Jump to content
  • Advertisement
Sign in to follow this  
Skyzyx

Object not rotating as it should

This topic is 737 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

Hello!

 

I am trying to rotate a character around it's mid point but apparently it is not working properly.

This is the code that is making the transformations. http://pastebin.com/L6J7dbp5

Here are some pictures so you can see how the character is rotating. http://imgur.com/a/rS064

 

I think I am getting the transformations right but I could be wrong. If anybody might have any clue on why this might be happening or incase you might find a mistake that I might be making please feel free to share the information.

 

Regards!

Edited by Skyzyx

Share this post


Link to post
Share on other sites
Advertisement

I don't know where the origin is in that model, but if you want to rotate around its center you need to translate it such that the origin is at that point, then perform your rotation, then translate it again to where you want it to be. If you're already aware of this then try changing your argument order in the multiplications. The Matrix.multiplyMM() documentation states that the args are in non-intuitive order.

Share this post


Link to post
Share on other sites
From the code provided it is impossible to tell how you are multiplying your matrices as you call a function to do the multiplication and i have no idea how that function is doing the multiplications

In general, using glsl standards, your tform would look something like

mat4 finalTform = projMat * camMat * objTranslateMat * objRotateMat * objScaleMat

And if you wanted to rotate around some point other than the origin - you add that to the lineup as a parent transform


mat4 finalTform = projMat * camMat * parentTform * objTranslateMat * objRotateMat * objScaleMat

And your parent tform can be its own combination of scale, rotation, and translation matrices. Leaving you with


mat4 finalTform = projMat * camMat * parentTranslateMat * parentRotationMat * parentScalingMat * objTranslateMat * objRotateMat * objScaleMat

To move the object relative to the rotation pivot point you would edit the position used to build the objTranslate mat, to edit the rotation around this point you would edit the parentRotationMat, to edit the world position of the rotation pivot point you would edit the parentTranslateMat, and to edit the local rotation of the object you would edit objRotationMat.

In your case you seem to only be interested in moving the rotation pivot point which means you could drop everythinh else leaving


mat4 finalTform = projMat * camMat * parentRotationMat * objTranslateMat

Note that changing objTranslateMat will move your pivot point around

Share this post


Link to post
Share on other sites

Yes I was testing a few things and I noticed that the model's center needs to be at the origin when performing rotations. So basically what you said khatharr. Thanks :)

Edited by Skyzyx

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!