andy-thomason / octet

A single module, header only C++ framework for learning OpenGL
12 stars 68 forks source link

Translating after rotating gives wrong orientation to objects. #7

Open parmandorc opened 7 years ago

parmandorc commented 7 years ago

The following code draws the axis twice - the second time after rotating 30 degrees on the Y axis, and then translating along the (local) X axis.

mat4t mat;
mat.loadIdentity();
app_scene->add_shape(mat, new mesh_box(vec3(5.0f, 0.1f, 0.1f)), red, false);
app_scene->add_shape(mat, new mesh_box(vec3(0.1f, 5.0f, 0.1f)), green, false);
app_scene->add_shape(mat, new mesh_box(vec3(0.1f, 0.1f, 5.0f)), blue, false);

mat.rotateY(30);
mat.translate(1, 0, 0);
app_scene->add_shape(mat, new mesh_box(vec3(2.0f, 0.1f, 0.1f)), red, false);
app_scene->add_shape(mat, new mesh_box(vec3(0.1f, 2.0f, 0.1f)), green, false);
app_scene->add_shape(mat, new mesh_box(vec3(0.1f, 0.1f, 2.0f)), blue, false);

It looks like this: wrong

When it should look like this: right

The position of the object is correct, but its orientation is as if the rotation had been in the opposite direction.