Hello everyone, I’m trying to create a hand with a basic geometric shapes that will do some transformations hierarchically. So rotation is working well but the translation is te problem. When I change the camera position the translation stay the same. Example, if I have a camera with the position (0,0,-10) looking at the origin and a cube at the origin and a cylider with a translation of (.5,0,0) from the cube. OpenGL manages the view with the positions from -1 to 1 right? If I do this translation my cylinder center will be at the point X = 0.5 of the screen and it’s wrong, It’s was to be at the point X = 0.5 in world coordinate because if I change the cam postion to (0,0,-30) the cyliner still stay on the position X = 0.5 of view and the translation seens bigger than it should be.
What I do:
MVP = cam.matrix() * cube.getTransformationsMatrix() ;
glUniformMatrix4fv(MVPMatrix, 1, GL_TRUE, &MVP[0][0]);
cube.render(GL_LINES);
cylinder.translate(glm::vec3(0.0,.5,0.0));
MVP = cam.matrix() * cylinder.getTransformationsMatrix() ;
glUniformMatrix4fv(MVPMatrix, 1, GL_TRUE, &MVP[0][0]);
cylinder.render(GL_TRIANGLES);
where matrix() return Projection * View and a object function getTransformationMatrix() returns this:
glm::mat4 sgl::Object::getTransformationsMatrix(){
if(this->father == NULL){
//cout<<"has no father"<<endl;
return this->rotateMatrix * this->translateMatrix;
}
else{
//cout<<"has a father"<<endl;
return this->rotateMatrix * this->translateMatrix * this->father->getTransformationsMatrix();
}
}