mirror of https://github.com/bjornbytes/lovr.git
Use MAT4_IDENTITY macro;
This commit is contained in:
parent
7829f3f75f
commit
28c56f959d
|
@ -454,9 +454,7 @@ void lovrGraphicsDraw(DrawCommand* draw) {
|
|||
if (pose) {
|
||||
lovrShaderSetMatrices(shader, "lovrPose", pose, 0, MAX_BONES * 16);
|
||||
} else {
|
||||
float identity[16];
|
||||
mat4_identity(identity);
|
||||
lovrShaderSetMatrices(shader, "lovrPose", identity, 0, 16);
|
||||
lovrShaderSetMatrices(shader, "lovrPose", (float[16]) MAT4_IDENTITY, 0, 16);
|
||||
}
|
||||
|
||||
lovrShaderSetInts(shader, "lovrViewportCount", &viewportCount, 0, 1);
|
||||
|
|
|
@ -158,8 +158,7 @@ void lovrModelDraw(Model* model, mat4 transform, int instances) {
|
|||
for (int i = 0; i < model->modelData->nodeCount; i++) {
|
||||
ModelNode* node = &model->modelData->nodes[i];
|
||||
|
||||
float localTransform[16];
|
||||
mat4_identity(localTransform);
|
||||
float localTransform[16] = MAT4_IDENTITY;
|
||||
if (!lovrAnimatorEvaluate(model->animator, node->name, localTransform)) {
|
||||
mat4_set(localTransform, node->transform);
|
||||
}
|
||||
|
|
|
@ -213,9 +213,8 @@ static void fakeRenderTo(void (*callback)(void*), void* userdata) {
|
|||
int width, height;
|
||||
fakeGetDisplayDimensions(&width, &height);
|
||||
bool stereo = state.mirrorEye == EYE_BOTH;
|
||||
Camera camera = { .canvas = NULL, .stereo = stereo };
|
||||
Camera camera = { .canvas = NULL, .viewMatrix = { MAT4_IDENTITY }, .stereo = stereo };
|
||||
mat4_perspective(camera.projection[0], state.clipNear, state.clipFar, 67 * M_PI / 180., (float) width / (1 + stereo) / height);
|
||||
mat4_identity(camera.viewMatrix[0]);
|
||||
mat4_translate(camera.viewMatrix[0], 0, state.offset, 0);
|
||||
mat4_multiply(camera.viewMatrix[0], state.transform);
|
||||
mat4_invertPose(camera.viewMatrix[0]);
|
||||
|
|
|
@ -541,7 +541,7 @@ static void openvrRenderTo(void (*callback)(void*), void* userdata) {
|
|||
lovrRelease(texture);
|
||||
}
|
||||
|
||||
Camera camera = { .canvas = state.canvas };
|
||||
Camera camera = { .canvas = state.canvas, .viewMatrix = { MAT4_IDENTITY, MAT4_IDENTITY } };
|
||||
|
||||
float head[16], eye[16];
|
||||
getTransform(HEADSET_INDEX, head);
|
||||
|
@ -549,7 +549,6 @@ static void openvrRenderTo(void (*callback)(void*), void* userdata) {
|
|||
for (int i = 0; i < 2; i++) {
|
||||
EVREye vrEye = (i == 0) ? EVREye_Eye_Left : EVREye_Eye_Right;
|
||||
mat4_fromMat44(camera.projection[i], state.system->GetProjectionMatrix(vrEye, state.clipNear, state.clipFar).m);
|
||||
mat4_identity(camera.viewMatrix[i]);
|
||||
mat4_translate(camera.viewMatrix[i], 0, state.offset, 0);
|
||||
mat4_multiply(camera.viewMatrix[i], head);
|
||||
mat4_multiply(camera.viewMatrix[i], mat4_fromMat34(eye, state.system->GetEyeToHeadTransform(vrEye).m));
|
||||
|
|
|
@ -237,22 +237,13 @@ mat4 mat4_rotate(mat4 m, float angle, float x, float y, float z) {
|
|||
}
|
||||
|
||||
mat4 mat4_rotateQuat(mat4 m, quat q) {
|
||||
float x = q[0];
|
||||
float y = q[1];
|
||||
float z = q[2];
|
||||
float w = q[3];
|
||||
float rotation[16];
|
||||
mat4_identity(rotation);
|
||||
rotation[0] = 1 - 2 * y * y - 2 * z * z;
|
||||
rotation[1] = 2 * x * y + 2 * w * z;
|
||||
rotation[2] = 2 * x * z - 2 * w * y;
|
||||
rotation[4] = 2 * x * y - 2 * w * z;
|
||||
rotation[5] = 1 - 2 * x * x - 2 * z * z;
|
||||
rotation[6] = 2 * y * z + 2 * w * x;
|
||||
rotation[8] = 2 * x * z + 2 * w * y;
|
||||
rotation[9] = 2 * y * z - 2 * w * x;
|
||||
rotation[10] = 1 - 2 * x * x - 2 * y * y;
|
||||
return mat4_multiply(m, rotation);
|
||||
float x = q[0], y = q[1], z = q[2], w = q[3];
|
||||
return mat4_multiply(m, (float[16]) {
|
||||
1 - 2 * y * y - 2 * z * z, 2 * x * y + 2 * w * z, 2 * x * z - 2 * w * y, 0,
|
||||
2 * x * y - 2 * w * z, 1 - 2 * x * x - 2 * z * z, 2 * y * z + 2 * w * x, 0,
|
||||
2 * x * z + 2 * w * y, 2 * y * z - 2 * w * x, 1 - 2 * x * x - 2 * y * y, 0,
|
||||
0, 0, 0, 1
|
||||
});
|
||||
}
|
||||
|
||||
mat4 mat4_scale(mat4 m, float x, float y, float z) {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define MAT4_IDENTITY { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
|
||||
|
||||
#define mat4_init mat4_set
|
||||
mat4 mat4_set(mat4 m, mat4 n);
|
||||
mat4 mat4_fromMat34(mat4 m, float (*n)[4]);
|
||||
|
|
Loading…
Reference in New Issue