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.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'cube/cube.cpp') diff --git a/cube/cube.cpp b/cube/cube.cpp index ce594626..ed572e39 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -91,13 +91,6 @@ static char const *const tex_files[] = {"lunarg.ppm"}; static int validation_error = 0; -struct vkcube_vs_uniform { - // Must start with MVP - float mvp[4][4]; - float position[12 * 3][4]; - float color[12 * 3][4]; -}; - struct vktexcube_vs_uniform { // Must start with MVP float mvp[4][4]; @@ -2472,7 +2465,8 @@ void Demo::update_data_buffer() { // Rotate around the Y axis mat4x4 Model; mat4x4_dup(Model, model_matrix); - mat4x4_rotate(model_matrix, Model, 0.0f, 1.0f, 0.0f, (float)degreesToRadians(spin_angle)); + mat4x4_rotate_Y(model_matrix, Model, (float)degreesToRadians(spin_angle)); + mat4x4_orthonormalize(model_matrix, model_matrix); mat4x4 MVP; mat4x4_mul(MVP, VP, model_matrix); -- cgit v1.2.3