From d752f85e3992720c4cf1c515242d2b55ebf05e20 Mon Sep 17 00:00:00 2001 From: falsycat Date: Mon, 7 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Added MatrixFactory for matrix calculation. --- .../CircleElementScheduledController.d | 24 +++++++++---- .../sjplayer/ScheduledControllerInterface.d | 3 +- sjplayer/src/sjplayer/util/MatrixFactory.d | 26 ++++++++++++++ sjplayer/src/sjplayer/util/Parameter.d | 36 ++++++++++++++++++- 4 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 sjplayer/src/sjplayer/util/MatrixFactory.d diff --git a/sjplayer/src/sjplayer/CircleElementScheduledController.d b/sjplayer/src/sjplayer/CircleElementScheduledController.d index 10af18e..55e6ed8 100644 --- a/sjplayer/src/sjplayer/CircleElementScheduledController.d +++ b/sjplayer/src/sjplayer/CircleElementScheduledController.d @@ -11,6 +11,7 @@ import sjplayer.CircleElement, sjplayer.ScheduledControllerFactory, sjplayer.ScheduledControllerInterface, sjplayer.VarStoreInterface, + sjplayer.util.MatrixFactory, sjplayer.util.Parameter; /// @@ -35,8 +36,15 @@ class CircleElementScheduledController : element_.weight = 1; element_.smooth = 0.01; element_.color = vec4(1, 1, 1, 1); + + matrix_factory_ = matrix_factory_.init; + super.PrepareOperation(params); } + override void ProcessOperation(float time, ref in ParametersBlock params) { + super.ProcessOperation(time, params); + element_.matrix = matrix_factory_.Create().transposed; + } override void FinalizeOperation(ref in ParametersBlock params) { element_.alive = false; } @@ -44,17 +52,21 @@ class CircleElementScheduledController : override void SetParameter(Nullable!float time, ref in Parameter param) { auto vars = VarStore(this, time); switch (param.name) { - case "damage": return element_.damage. CalculateParameter(param, vars); - case "nearness_coe": return element_.nearness_coe.CalculateParameter(param, vars); - case "weight": return element_.weight. CalculateParameter(param, vars); - case "smooth": return element_.smooth. CalculateParameter(param, vars); - - default: return super.SetParameter(time, param); + case "damage": return param.CalculateParameter(element_.damage, vars); + case "nearness_coe": return param.CalculateParameter(element_.nearness_coe, vars); + case "weight": return param.CalculateParameter(element_.weight, vars); + case "smooth": return param.CalculateParameter(element_.smooth, vars); + default: } + if (param.CalculateMatrixParameter(matrix_factory_, vars)) return; + + return super.SetParameter(time, param); } private: CircleElement element_; + + MatrixFactory matrix_factory_; } /// diff --git a/sjplayer/src/sjplayer/ScheduledControllerInterface.d b/sjplayer/src/sjplayer/ScheduledControllerInterface.d index 244bd99..eb4c40e 100644 --- a/sjplayer/src/sjplayer/ScheduledControllerInterface.d +++ b/sjplayer/src/sjplayer/ScheduledControllerInterface.d @@ -111,8 +111,7 @@ abstract class AbstractScheduledControllerWithOperationImpl : (param.name.length >= 2 && param.name[0..2] == "__"). enforce("user defined variables must be prefixed '__'"); user_vars_[param.name] = 0; - user_vars_[param.name]. - CalculateParameter(param, VarStore(this, time)); + param.CalculateParameter(user_vars_[param.name], VarStore(this, time)); } private: diff --git a/sjplayer/src/sjplayer/util/MatrixFactory.d b/sjplayer/src/sjplayer/util/MatrixFactory.d new file mode 100644 index 0000000..11a99eb --- /dev/null +++ b/sjplayer/src/sjplayer/util/MatrixFactory.d @@ -0,0 +1,26 @@ +/// License: MIT +module sjplayer.util.MatrixFactory; + +import gl4d; + +/// +struct MatrixFactory { + public: + /// + @property mat3 Create() const { + auto m = mat3.identity; + m.scale(scale.x, scale.y, scale.z); + m.rotatex(rotation.x); + m.rotatey(rotation.y); + m.rotatez(rotation.z); + m.translate(translation.x, translation.y, translation.z); + return m; + } + + /// + vec3 scale = vec3(1, 1, 1); + /// + vec3 rotation = vec3(0, 0, 0); + /// + vec3 translation = vec3(0, 0, 0); +} diff --git a/sjplayer/src/sjplayer/util/Parameter.d b/sjplayer/src/sjplayer/util/Parameter.d index 6c35eeb..132066a 100644 --- a/sjplayer/src/sjplayer/util/Parameter.d +++ b/sjplayer/src/sjplayer/util/Parameter.d @@ -3,10 +3,44 @@ module sjplayer.util.Parameter; import sjscript; +import sjplayer.util.MatrixFactory; + /// void CalculateParameter(T)( - ref float value, in Parameter param, T vars) { + in Parameter param, ref float value, T vars) { auto result = param.rhs.CalculateExpression(vars); if (param.type == ParameterType.AddAssign) result += value; value = result; } + +/// +bool CalculateMatrixParameter(T)( + in Parameter param, ref MatrixFactory m, T vars) { + switch (param.name) { + case "translation_x": + param.CalculateParameter(m.translation.x, vars); + return true; + case "translation_y": + param.CalculateParameter(m.translation.y, vars); + return true; + + case "rotation_x": + param.CalculateParameter(m.rotation.x, vars); + return true; + case "rotation_y": + param.CalculateParameter(m.rotation.y, vars); + return true; + case "rotation_z": + param.CalculateParameter(m.rotation.z, vars); + return true; + + case "scale_x": + param.CalculateParameter(m.scale.x, vars); + return true; + case "scale_y": + param.CalculateParameter(m.scale.y, vars); + return true; + + default: return false; + } +}