Object not rotating as it should

Started by
2 comments, last by Skyzyx 7 years, 9 months ago

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!

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.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
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

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 :)

This topic is closed to new replies.

Advertisement