[update] Added MatrixFactory for matrix calculation.

This commit is contained in:
falsycat 2019-10-07 00:00:00 +00:00
parent 1783d78183
commit d752f85e39
4 changed files with 80 additions and 9 deletions

View File

@ -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_;
}
///

View File

@ -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:

View File

@ -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);
}

View File

@ -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;
}
}