|
@@ -1,48 +1,46 @@
|
|
|
#include "core/View.h"
|
|
|
|
|
|
-#define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
|
|
|
+#include "core/Generic.h"
|
|
|
|
|
|
-void coreUpdateDirections(CoreView* v, float lengthAngle, float widthAngle) {
|
|
|
- coreAngles(&v->front, lengthAngle, widthAngle);
|
|
|
+#define CV3(a, b, c) (&(Vector3){{a, b, c}})
|
|
|
|
|
|
- coreCross(&v->right, &v->front, CV3(0.0f, 1.0f, 0.0f));
|
|
|
- coreNormalizeV3(&v->right);
|
|
|
+void initView(View* v) {
|
|
|
+ *v = (View){0};
|
|
|
+}
|
|
|
|
|
|
- coreCross(&v->up, &v->right, &v->front);
|
|
|
- coreNormalizeV3(&v->up);
|
|
|
+void updateDirections(View* v, float lengthAngle, float widthAngle) {
|
|
|
+ angles(&v->front, lengthAngle, widthAngle);
|
|
|
|
|
|
- coreInvertV3(&v->left, &v->right);
|
|
|
- coreInvertV3(&v->back, &v->front);
|
|
|
- coreInvertV3(&v->down, &v->up);
|
|
|
-}
|
|
|
+ cross(&v->right, &v->front, &V(0.0f, 1.0f, 0.0f));
|
|
|
+ normalize(&v->right);
|
|
|
|
|
|
-void coreUpdateDirectionsQ(CoreView* v, const CoreQuaternion* q) {
|
|
|
- coreMulQV3(&v->up, q, CV3(0.0f, 1.0f, 0.0f));
|
|
|
+ cross(&v->up, &v->right, &v->front);
|
|
|
+ normalize(&v->up);
|
|
|
+
|
|
|
+ invert(&v->left, &v->right);
|
|
|
+ invert(&v->back, &v->front);
|
|
|
+ invert(&v->down, &v->up);
|
|
|
+}
|
|
|
|
|
|
- coreMulQV3(&v->back, q, CV3(-1.0f, 0.0f, 0.0f));
|
|
|
+void updateDirectionsQ(View* v, const Quaternion* q) {
|
|
|
+ mul(&v->up, q, &V(0.0f, 1.0f, 0.0f));
|
|
|
+ mul(&v->back, q, &V(-1.0f, 0.0f, 0.0f));
|
|
|
|
|
|
- coreCross(&v->right, &v->up, &v->back);
|
|
|
- coreNormalizeV3(&v->right);
|
|
|
+ cross(&v->right, &v->up, &v->back);
|
|
|
+ normalize(&v->right);
|
|
|
|
|
|
- coreInvertV3(&v->left, &v->right);
|
|
|
- coreInvertV3(&v->front, &v->back);
|
|
|
- coreInvertV3(&v->down, &v->up);
|
|
|
+ invert(&v->left, &v->right);
|
|
|
+ invert(&v->front, &v->back);
|
|
|
+ invert(&v->down, &v->up);
|
|
|
}
|
|
|
|
|
|
-CoreMatrix* coreUpdateMatrix(CoreView* v, const CoreVector3* pos) {
|
|
|
- v->view.data[0] =
|
|
|
- (CoreVector4){{v->right.data[0], v->right.data[1], v->right.data[1],
|
|
|
- -coreDotV3(&v->right, pos)}};
|
|
|
- v->view.data[1] = (CoreVector4){
|
|
|
- {v->up.data[0], v->up.data[1], v->up.data[1], -coreDotV3(&v->up, pos)}};
|
|
|
- v->view.data[2] =
|
|
|
- (CoreVector4){{v->back.data[0], v->back.data[1], v->back.data[1],
|
|
|
- -coreDotV3(&v->back, pos)}};
|
|
|
- v->view.data[3] = (CoreVector4){{0.0f, 0.0f, 0.0f, 1.0f}};
|
|
|
-
|
|
|
- // view.set(0, Vector4(right[0], right[1], right[2], right.dot(-pos)));
|
|
|
- // view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
|
|
|
- // view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));
|
|
|
- // view.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
|
+Matrix* updateMatrix(View* v, const Vector3* pos) {
|
|
|
+ Vector4* d = v->view.data;
|
|
|
+ d[0] = V(v->right.data[0], v->right.data[1], v->right.data[2],
|
|
|
+ -dot(&v->right, pos));
|
|
|
+ d[1] = V(v->up.data[0], v->up.data[1], v->up.data[2], -dot(&v->up, pos));
|
|
|
+ d[2] = V(v->back.data[0], v->back.data[1], v->back.data[2],
|
|
|
+ -dot(&v->back, pos));
|
|
|
+ d[3] = V(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
return &v->view;
|
|
|
}
|