How to set object's orientation around its center?

Post » Thu May 30, 2013 4:00 pm

I have run into a problem that has me stumped. I have searched the forums and Google but haven't been able to come up with an answer to do what I need. So I am hoping the knowledgeable forum members here will have some ideas.

I have a need to be able to calculate new x, y, z values to plug into the SetAngle() function to change an objects orientation around its center.

I need to be able to place an object into the world then tilt it on its local X and Y axes then spin it around the global Z axis. I do not want to orbit the object around another object. I just want to reorient the object in place. I will already know the desired local X and Y rotation I want for the object but I will need to be able to change the Z rotation at any time. And I need the Z rotation to be about the world Z axis not the local Z axis (and the object can be at the cell origin (0,0,0) when I do this).

Unfortunately, I know very little trigonometry and even less about matrix rotations, etc.

I found the following article on the Bethesda Creation Kit Wiki and it looked very promising. However, when I implement it, it only seems to work when the Z rotation is a multiple of 90 degrees (0, 90, 180, 270). Any other Z angle causes the object to end up at strange angles.

Here is the link to that article:

http://www.creationkit.com/Setting_Local_Rotation

Is there a reason these formulas only work for Z angles of 0, 90, 180, and 270 degrees? Can they be modified to allow me to choose any arbitrary Z angle? Or is there a different set of formulas that would work?

Note that I do not need fast formulas since I am not using this for animation. I will only need to change the orientation in response to particular player actions that will not happen often. And the object does not need to transition to the new orientation gradually. I just want to make a single call to SetAngle with the X,Y,Z of the desired orientation and have the object snap to that orientation.

User avatar
clelia vega
 
Posts: 3433
Joined: Wed Mar 21, 2007 6:04 pm

Return to V - Skyrim