fix: Transform->matrix conversion is now (more) correct
This commit is contained in:
parent
c74c006ae2
commit
0661622b9c
4 changed files with 18 additions and 25 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "transformable.h"
|
||||
#include "utils/debug.h"
|
||||
|
||||
Transform TransformIdentity() {
|
||||
return (Transform){
|
||||
|
|
@ -8,14 +9,10 @@ Transform TransformIdentity() {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
Matrix TransformGetMatrix(Transform self) {
|
||||
Matrix mat = MatrixScale(self.scale.x, self.scale.y, self.scale.z);
|
||||
mat = MatrixMultiply(mat, QuaternionToMatrix(self.rotation));
|
||||
mat.m12 = self.translation.x;
|
||||
mat.m13 = self.translation.y;
|
||||
mat.m14 = self.translation.z;
|
||||
return mat;
|
||||
return MatrixMultiply(mat, MatrixTranslate(self.translation.x, self.translation.y, self.translation.z));
|
||||
}
|
||||
|
||||
Vector3 TransformPosition(Transform self, Vector3 local_pos) {
|
||||
|
|
@ -61,7 +58,7 @@ Vector3 InverseTransformScale(Transform self, Vector3 global_scale) {
|
|||
}
|
||||
|
||||
Quaternion InverseTransformRotation(Transform self, Quaternion global_rotation) {
|
||||
return QuaternionMultiply(QuaternionInvert(self.rotation), global_rotation);
|
||||
return QuaternionDivide(self.rotation, global_rotation);
|
||||
}
|
||||
|
||||
Transform InverseTransformTransform(Transform self, Transform other) {
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ extern Vector3 InverseTransformScale(Transform self, Vector3 global_scale);
|
|||
extern Quaternion InverseTransformRotation(Transform self, Quaternion quat);
|
||||
extern Transform InverseTransformTransform(Transform self, Transform other);
|
||||
|
||||
#define MATRIX_UP(self_) ((Vector3){self_.m0, self_.m1, self_.m2})
|
||||
#define MATRIX_RIGHT(self_) ((Vector3){self_.m4, self_.m5, self_.m6})
|
||||
#define MATRIX_RIGHT(self_) ((Vector3){self_.m0, self_.m1, self_.m2})
|
||||
#define MATRIX_UP(self_) ((Vector3){self_.m4, self_.m5, self_.m6})
|
||||
#define MATRIX_FORWARD(self_) ((Vector3){self_.m8, self_.m9, self_.m10})
|
||||
|
||||
#define VECTOR3_RIGHT ((Vector3){1.f, 0.f, 0.f})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue