[update] Replaced MatrixFactory with ModelMatrixFactory came from gl4d.

This commit is contained in:
falsycat 2019-10-12 00:00:00 +00:00
parent 58e88e9eb4
commit 79654d6da4
5 changed files with 26 additions and 52 deletions

View File

@ -11,7 +11,6 @@ import sjscript;
import sjplayer.AbstractScheduledController,
sjplayer.ScheduledControllerInterface,
sjplayer.VarStoreInterface,
sjplayer.util.MatrixFactory,
sjplayer.util.Parameter;
///
@ -73,7 +72,7 @@ class ScheduledController(
default:
}
static if (MatrixModificationAvailable) {
const value = matrix_factory_.GetValueByName(name);
const value = matrix_factory_.GetModelMatrixParameterValueByName(name);
if (!value.isNull) return value;
}
return super.GetVariable(name);
@ -88,7 +87,7 @@ class ScheduledController(
default:
}
static if (MatrixModificationAvailable) {
if (param.CalculateMatrixParameter(matrix_factory_, vars)) return;
if (param.CalculateModelMatrixParameter(matrix_factory_, vars)) return;
}
super.SetParameter(param, vars);
}
@ -96,6 +95,6 @@ class ScheduledController(
Target target_;
static if (MatrixModificationAvailable) {
MatrixFactory matrix_factory_;
ModelMatrixFactory!3 matrix_factory_;
}
}

View File

@ -1,42 +0,0 @@
/// License: MIT
module sjplayer.util.MatrixFactory;
import std.typecons;
import gl4d;
///
struct MatrixFactory {
public:
///
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, 1);
return m;
}
///
Nullable!float GetValueByName(string name) const {
switch (name) {
case "scale_x": return Nullable!float(scale.x);
case "scale_y": return Nullable!float(scale.y);
case "rotation_x": return Nullable!float(rotation.x);
case "rotation_y": return Nullable!float(rotation.y);
case "rotation_z": return Nullable!float(rotation.z);
case "translation_x": return Nullable!float(translation.x);
case "translation_y": return Nullable!float(translation.y);
default: return Nullable!float.init;
}
}
///
vec3 scale = vec3(1, 1, 1);
///
vec3 rotation = vec3(0, 0, 0);
///
vec2 translation = vec2(0, 0);
}

View File

@ -1,9 +1,11 @@
/// License: MIT
module sjplayer.util.Parameter;
import sjscript;
import std.typecons;
import sjplayer.util.MatrixFactory;
import gl4d;
import sjscript;
///
void CalculateParameter(T)(
@ -14,8 +16,8 @@ void CalculateParameter(T)(
}
///
bool CalculateMatrixParameter(T)(
in Parameter param, ref MatrixFactory m, T vars) {
bool CalculateModelMatrixParameter(T)(
in Parameter param, ref ModelMatrixFactory!3 m, T vars) {
switch (param.name) {
case "translation_x":
param.CalculateParameter(m.translation.x, vars);
@ -44,3 +46,18 @@ bool CalculateMatrixParameter(T)(
default: return false;
}
}
///
Nullable!float GetModelMatrixParameterValueByName(
ref in ModelMatrixFactory!3 m, string name) {
switch (name) {
case "scale_x": return Nullable!float(m.scale.x);
case "scale_y": return Nullable!float(m.scale.y);
case "rotation_x": return Nullable!float(m.rotation.x);
case "rotation_y": return Nullable!float(m.rotation.y);
case "rotation_z": return Nullable!float(m.rotation.z);
case "translation_x": return Nullable!float(m.translation.x);
case "translation_y": return Nullable!float(m.translation.y);
default: return Nullable!float.init;
}
}

View File

@ -45,7 +45,7 @@ class LobbyWorld {
///
mat4 view = mat4.look_at(vec3(0, 0, -1), vec3(0, 0, 0), vec3(0, 1, 0));
///
vec3 light_color = vec3(1, 1, 1, 1);
vec3 light_color = vec3(1, 1, 1);
///
vec3 light_direction = vec3(0, 1, 0);
///

2
thirdparty/gl4d vendored

@ -1 +1 @@
Subproject commit 51ad9270d58fd7cd64b494450dd447b39b21bb45
Subproject commit 33883a68a9179cdfca72da9d0f60a88e1f385715