I am developing a robot hand simulation program in which I can load and draw a robot hand model(the model built in 3DS MAX) and perform some actions according to the inputs, for an example, joint angles.
the hand model contains many different parts, each part have it's own model matrix and VBO storing vertex coordinates, normals and uvs.
I want to perform rotation using glm::rotate() on a joint around a certain axis(not coordinate axis), so I was going to translate it to the world origin, and perform rotation, and finally move back.
The problem here is that when I perform rotation after translation, the world origin it rotates around seems changed as well, it looks like the world origin have been translated in the same way.
also, I don't really know whether glm::rotate rotates around world origin? it's confusing that why it changes, I have tested rotating directly not to translate before rotation, and it actually rotates around world origin,but when I perform translation before rotation, it changes.
More details:
I also think the problem are most likely in the coordinate system. I used a Robothand class to represent the robot hand object, and those "parts" are objects of Model class, there are parent-child relationships among models, so every transformation performed in one specific model will have the same effect on their children model.
Vertex shader
void main(){
mat4 MVP = P * V * M;
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
Position_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;
vec3 vertexPosition_cameraspace = (V * M * vec4(vertexPosition_modelspace,1)).xyz;
EyeDirection_cameraspace = vec3(0,0,0) - vertexPosition_cameraspace;
vec3 LightPosition_cameraspace = (V * vec4(LightPosition_worldspace,1)).xyz;
LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;
Normal_cameraspace = ( V * M * vec4(vertexNormal_modelspace,0)).xyz;
UV = vertexUV;
Color = vertexColor;
}
I have to explain that the robot hand model is built in 3ds max, and exported as .obj file.In 3DS MAX, all the models share the same world origin, which means the their origin of model coordinate systems are in the same position. There are not any problems if I rotate any model without translation, it will rotate around world coordinate axis, but the real problem is, if I translate first, the world origin will be translated in the same way, it looks like rotating in a new coordinate system.