Translating/Rotating an object relative to it's orientaion
by Daniel Hopkins · in Technical Issues · 09/12/2008 (3:03 pm) · 2 replies
Ok, I use the .containerRayCast() method to cast a ray at a desired point. If it collides, it will return both the position and the surface normal of the collision point. Basically, I want to move an object to that point and orient it so that the z-axis is parallel to the normal. Here's what I'm doing:
%newTransform = %colPoint SPC %surfNorm SPC "360";
[obj].setTransform(%newTransform);
As far as I know, it's working the way it should. Now, here's what I want to do: sometimes an object is oriented in such a way relative to its center, that the mesh is not touching the collision surface, such as a tree above the terrain.
What would you do to the above code to translate the object a certain amount in the relative z direction (the same as entering the editor and moving it with its z-axis)?
Then, what would you do to rotate the object a certain amount around its relative z-axis?
Any help will be very much appreciated!
I appologize if I'm merely asking the same thing someone else already has.
%newTransform = %colPoint SPC %surfNorm SPC "360";
[obj].setTransform(%newTransform);
As far as I know, it's working the way it should. Now, here's what I want to do: sometimes an object is oriented in such a way relative to its center, that the mesh is not touching the collision surface, such as a tree above the terrain.
What would you do to the above code to translate the object a certain amount in the relative z direction (the same as entering the editor and moving it with its z-axis)?
Then, what would you do to rotate the object a certain amount around its relative z-axis?
Any help will be very much appreciated!
I appologize if I'm merely asking the same thing someone else already has.
#2
09/12/2008 (9:08 pm)
Okay, thanks. Yeah, that's what I thought (referring to the tranlation down z-axis) but the results sometimes seemed a bit odd. Alright, thanks for the angle cheatsheet.
Associate James Ford
Sickhead Games
%colPoint = VectorSub( %colPoint, VectorScale( %surfNorm, 0.5 ) );
To rotate it in object space could actually be a pain. I don't know of a way to do this in script, and the way to do it in C++ off the top of my head is really sortof complex.
In pseudo code...
The current forward vector in object space is always (0,1,0).
Rotate that by the amount you desire around the z axis.
Convert that vector into world space
Reconstruct the transform matrix via cross products.
I wrote down the algorithm for rotating a vector around the z axis in this coding cheatsheet.