I'm working on something in Unity3D (the game engine) where I have to modify a path/road in 3d space. The path consists of a collection of positions and quaternion-orientations (the orientation determines both the direction of the road, and the banking).
I'm having trouble rotating the the road the way I want it to.
I want to be able to rotate it using euler angles, rotating the path according to the startingpoint's orientation. (so the x-angle should rotate it around the first point's local x axis, etc.)
I thought the correct way to do this would be to do:
for (int i = 0; i < points.Count; i++)
{
rotation = (Quaternion.Inverse(points[0].orientation) * Quaternion.Euler(eulerRotation) * points[0].orientation);
points[i].orientation = rotation * points[i].orientation;
points[i].position -= points[0].position;
points[i].position = rotation * points[i].position;
points[i].position += points[0].position;
}
But that doesn't seem to rotate it the way I want it to, the axes are wrong.
Any help?
Here's an image to show what I mean: roadscreenshot
It shows both the road before and after rotation (the upmoast road being its original orientation), It was supposed to rotate 30 degrees around the startingpoint's local x-axis, but clearly that's not how it rotated. The axes shown are the startingpoint's local axes, the x-axis is the red one.
If
positionandorientationof thepointsare given in global coordinate space, then you don't need to mixorientationinto rotation as it has nothing to do with it.For better performance (at least I believe so), you might want to create
Transformobject from rotation and position of first point and apply it to positions of other points with one operation instead of three.