From 3ae088978f2107d79ac9a8eaec9ae0600f54f19f Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Tue, 25 May 2021 00:07:24 -0700 Subject: vkcube: Fix disturbed rotation after many iterations vkcube computes the model matrix for the cube by repeatedly multiplying a rotation matrix with it. After a sufficient number of iterations the matrix becomes disturbed (likely due to numerical errors) and stops being orthogonal and the cube vertices start scaling increasingly on the XY plane. * Orthonormalize the model matrix after each multiplication to prevent the scaling. * Use mat4x4_rotate_Y() instead of mat4x4_rotate() as it is less verbose. * Remove unused duplicate vkcube_vs_uniform struct. --- cube/cube.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cube/cube.c') diff --git a/cube/cube.c b/cube/cube.c index 83022306..7f6effbd 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -882,7 +882,8 @@ void demo_update_data_buffer(struct demo *demo) { // Rotate around the Y axis mat4x4_dup(Model, demo->model_matrix); - mat4x4_rotate(demo->model_matrix, Model, 0.0f, 1.0f, 0.0f, (float)degreesToRadians(demo->spin_angle)); + mat4x4_rotate_Y(demo->model_matrix, Model, (float)degreesToRadians(demo->spin_angle)); + mat4x4_orthonormalize(demo->model_matrix, demo->model_matrix); mat4x4_mul(MVP, VP, demo->model_matrix); memcpy(demo->swapchain_image_resources[demo->current_buffer].uniform_memory_ptr, (const void *)&MVP[0][0], matrixSize); -- cgit v1.2.3