# Hierarchical Modeling - OpenGL 3.0+

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);
cube.render(GL_LINES);

cylinder.translate(glm::vec3(0.0,.5,0.0));

MVP = cam.matrix() *  cylinder.getTransformationsMatrix() ;
glUniformMatrix4fv(MVPMatrix, 1, GL_TRUE, &MVP);
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();

}
}

``````

I solved this problem modifying my code that calculate the transformation matrix

``````
glm::mat4 sgl::Object::getTransformationsMatrix(sgl::Camera cam){
if(this->father == NULL){
//cout<<"has no father"<<endl;
return   cam.matrix() * glm::mat4(1.0f) * this->rotateMatrix * this->translateMatrix;
}
else{
//cout<<"has a father"<<endl;
return this->rotateMatrix * this->translateMatrix * this->father->getTransformationsMatrix(cam);

}
}

``````

I don’t know why because to me it’s the same way that I’m doing. Now my problem is when I rotate the camera or the object, the mesh of the hierarchical branches of has been squeezed.
Here a image of the result with rotate the object 70º in Y axis: http://imageshack.us/f/713/5kbz.png/

Here rotating 90º: http://imageshack.us/photo/my-images/191/uoo0.png/