I've got a program, in which I display an object. First I load position p.x, p.y, p.z, and scale s.x, s.y, s.z from the file. Then I apply them to 4x4 ModelMatrix and perform many translation and scale operations to it.
When I load object for the first time, I use p and s values:
modelMatrix = glm::mat4(1.0));
/*Translations*/
modelMatrix = glm::translate(modelMatrix, glm::vec3(p.x, p.y, p.z));
modelMatrix = glm::scale(modelMatrix, glm::vec3(s.x, s.y, s,z));
While during the program I perform scale and translation operations, and then save p and s values back to the file.
void Display::Translate( double x, double y, double z)
{
modelMatrix = glm::translate(modelMatrix, glm::vec3(x,y,z));
p.x += x; //that way p is composition of all translations
p.y += y;
p.z += z;
}
void Display::Scale( double x, double y, double z)
{
modelMatrix = glm::scale(modelMatrix, glm::vec3(x,y,z));
s.x *= x; //that way s is composition of all scalings
s.y *= y;
s.z *= z;
}
Now the problem is that after loading again (running the program again), objects are not in the place I save them, but some rather random place. (especially translation). Am I composing transformations in the wrong way (adding to x,y,z in translation and multiplying in scalings)?