So I got to the opengl point and then decided to get Anton's opengl tutorials.
I get most of it and using his code I already can draw some cube to the screen that XYZ rotates in place, the cam moves around in XZ and mouse does some look around in XY.
The weird part is when I add ANOTHER cube. This other cube will fly around like crazy if I apply any rotation, while the first cube rotates in XYZ but stays in place.
I switched from Anton's math funcs to GLMs but the problem persists.
Ok so main loop looks like this:
input.update(elapsed_seconds, &cam, &object, &object2); auto view_mat = transform(&cam); auto model_mat = transform(&object); auto model_mat2 = transform(&object2); /// first obj shader.use_programme_on_VAO(model.get_VAO()); shader.load_view_matrix(view_mat.m); shader.load_model_matrix(model_mat.m); glBindTexture(GL_TEXTURE_2D, tex1); glDrawElements(GL_TRIANGLES, model.indexes_count(), GL_UNSIGNED_BYTE, (GLvoid*)0); /// second obj shader.load_model_matrix(model_mat2.m); glBindTexture(GL_TEXTURE_2D, tex2); glDrawElements(GL_TRIANGLES, model.indexes_count(), GL_UNSIGNED_BYTE, (GLvoid*)0); // put the stuff we've been drawing onto the display glfwSwapBuffers( g_window );
the transform func is like this
static mat4 transform(Entity* e) { mat4 T, R; T = translate( identity_mat4(), vec3( -e->pos_X, -e->pos_Y, -e->pos_Z ) ); R = rotate_x_deg( T, -e->rot_X ); R = rotate_y_deg( R, -e->rot_Y ); R = rotate_z_deg( R, -e->rot_Z ); return R * T; }
Both camera and objects are an "entity", which is nothing but a position and a rotation float arrays.
The input update just get keyboard and mouse input, and I just pass some values for the rotation of the cubes
void Input::update(float elapsed_seconds, Entity* cam, Entity* obj, Entity* obj2) { get_inputs(); /// in millisec accum_time += elapsed_seconds*1000; float input_delay = 50; if (accum_time > input_delay) { float units_per_sec = 0.005; float speed = units_per_sec * 1000/input_delay; accum_time -= input_delay; if (key_LSHIFT) { speed *= 10; } if (key_W) { cam->pos_Z -= speed; } if (key_S) { cam->pos_Z += speed; } if (key_A) { cam->pos_X -= speed; } if (key_D) { cam->pos_X += speed; } float rotx = cam->rot_X + 0.22*(center_window_y - mouse_y); float roty = cam->rot_Y + 0.22*(center_window_x - mouse_x); cam->rot_X = rotx; cam->rot_Y = roty; /// a rotation each t seconds is deg = 360 / (t*1000/input_delay) obj->rot_X += 0.6; obj->rot_Y += 1.3; obj->rot_Z += 1.8; obj2->rot_X += 0.8; obj2->rot_Y += 1.8; obj2->rot_Z += 1.2; } }
it gives me the effect in the video
any ideas of what is going on here?
thx