Jump to content
  • Advertisement
Sign in to follow this  
muhkuh

OpenGL head skoming, please help with skinning

This topic is 4827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I'm trying to fix this for days and I don't find my mistake. I'm implementing a model animation system with skinning. My models come from .x files and my renderer is OpenGL so there are probably some conversion problems along the way. I really hope somebody finds the time to read this as it's quite long. To be on the save side I thought it would be best to convert everything from Direct3Ds coordinate system to OpenGLs. I'll explain what I do in detail in hope somebody can find a logical mistake in that. In the file: -left handed coordinate system of D3D -matrices in row major form and are applied to a vertex like this v'=v*M OpenGL: -right handed coordinate system -matrices in column major form are applied to a vertex like: v'=M*v I leave out animation and take only one keyframe so I got these matrices: O: skin offset matrix of the mesh to a bone R: rotation matrix of a bone's keyframe T: translation matrix of a bone's keyframe S: scaling matrix of a bone's keyfram I use OpenGL's way of doing transformations from here on. I calculate the local transformation matrix T for each bone as: L=T*S*R After that the combined transformation matrix of a bone C is: C=P_combined*L, where P_combined is the combined matrix of the parent. To get the final matrix F to get the vertices to world space I use: F=C*O After that F is multiplied by the MVP matrix. So to transform a vertex this calculation has to be performed: v'= MVP*P_combined*T*S*R*O Now to the conversion stuff: I multiplied the z components of all positions, normals and translation vectors by -1. I took all matrices from the file and transposed them to convert from matrices that multiply on the right to matrices that multiply on the left. To change from left to right handed I applied a scaling matrix left and right: M'= S*transpose(M)*S, with S being: 1 0 0 0 0 1 0 0 0 0-1 0 0 0 0 1 I took the quaternions and converted them to a matrix, applied the scaling like above and converted back to a quaternion. q'=toquaternion( S*tomatrix(q)*S ) The problem is, that the displayed model look totally scewed. Is this the correct way of doing that? I tried not to invert the z component and leave out the multiplications with S but the result was the same. Damn ... Thanks a lot fro reading this. Markus

Share this post


Link to post
Share on other sites
Advertisement
Some corrections that might be affecting you.

(Row-major form)
L = T*S*R should be L = T*R*S.

If you apply rotation first, then do a non-uniform scale, your transformation will be all skewed and wrong.

Also, don't both pre- and post- multiply by the scaling matrix. Just do it once, in the order indicated above. I'm not sure which way you mean by 'multiply on the right/left' but I'm pretty sure that both D3D and OpenGL use column major, which does transforms like v' = v*M, so you shouldn't need to transpose if you reverse the order of the other transformations (v' = v * O*S*R*T*...)

And don't convert back to a quaternion after scaling! That's crazy! Then you get a non-unit quaternion and you'd better have a damn good reason for doing that kind of thing.

...
wait, by 'scewed' do you mean to misspell 'skewed' or 'screwed'?

Share this post


Link to post
Share on other sites
Quote:
Original post by ajas95
I'm pretty sure that both D3D and OpenGL use column major


Actually, the D3D fixed function pipeline, and all the D3DX generated matrices, are row-major, as muhkuh said.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!