Constraining quaternions for gradual rotation

Started by
6 comments, last by arithma 16 years, 8 months ago
Say I have two vectors (vecForward and vecToTarget) I know how to calculate the quaternion between them (dQ), and I simply multiply the difference quaternion by the current quaternion (Q) to realign my forward vector parallel to the target vector. That change is instantaneous; I may need to convert dQ to axis angles in order to make sure the rotation doesn't exceed the max angular velocities around each axis (yaw/pitch/roll rates may be different). I suspect that theory isn't feasible, though, and I'm not sure where to go with it. * Also (and maybe this bit would be better off in the AI section), does anyone know of a ground-up tutorial on steering behaviors and collision avoidance? I've looked at a lot of code, and Craig Reynolds' website has been helpful, but anything else would be appreciated. Thanks
Advertisement
Hm, no takers? Here's some code as it is now:

Dim As Vector VecToTarget = TargetObj->Coords - Obj.CoordsDim As Quaternion dQ = QUATERNION(obj.Forward, VecToTarget)obj.orientation *= dQ

The first line finds a vector between my location and the target's. The second line finds the quaternion between the two, and the third line modifies the current orientation by that quaternion.

I'm thinking of modifying the code so that I'm setting a goal orientation rather than a goal rotational velocity. This could be converted to an axis angle, which could theoretically be broken down so that I can compare each component to MaxRotSpeed.
Ok, but what is the question?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
I'm not quite following either, but if the goal is to restrict the local-axis rotations (yaw, pitch, and roll) to some maximum speed, then perhaps it would be better to handle the steering in terms of ypr in the first place, rather than via the (arbitrary) axis-angle rotations you're using currently.

Given a current orientation and a target, you can compute the yaw, pitch, and/or roll that will align the object with the target by projecting the vector-to-target onto the appropriate planes, and then using the atan2() function to compute the angle. You can fully align the object with the target using any two of the three rotations (for example, pitch and roll only). By breaking the steering down into these local-axis rotations, you can then easily apply rotational constraints as needed.

That is, if I understand correctly (which I may not :).
You could interpolate your actual orientation with the final orientation, incrementing the factor (in the range of [0,1]) as time goes.

initial = obj.orientation;
final = initial * dQ;
...
obj.orientation = slerp(initial, final , factor);

Not sure, but maybe you could also only multiply dQ by the same factor.

obj.orientation *= factor * dQ;

OUPS... forget this, I think missunderstood you by the "gradual rotation" in the title of your post...
The rotations represented by quaternions won't map smoothly into the yaw, pitch, and roll rates, because of limitations in using a yaw/pitch/roll representation. Yaw, pitch, and roll don't give smooth rotations since the order in which they are applied changes the effects that a change in each of them would have. If you're looking straight up, is that 90 degrees pitch or 180 degrees of roll and yaw?

To do this properly, with different rates of movement for yaw, pitch, and roll, a better model for thinking about this would be as 3 separate rotational joints. Think of it like a robot arm, where these joints are applied in a particular order. When trying to rotate to a certain direction, convert that direction vector to the robot's coordinate space to get the rotation relative to its current position. Now compute the needed rotations for each axis in whatever order you are applying them in to get three angle deltas.
Quote:Original post by Vorpy
The rotations represented by quaternions won't map smoothly into the yaw, pitch, and roll rates, because of limitations in using a yaw/pitch/roll representation. Yaw, pitch, and roll don't give smooth rotations since the order in which they are applied changes the effects that a change in each of them would have. If you're looking straight up, is that 90 degrees pitch or 180 degrees of roll and yaw?
Just to clarify for the OP, the 'yaw, pitch, and roll' I referred to in my earlier post are local-axis (relative) rotations, and therefore aren't subject to the kinds of problems described above (well, technically speaking, order does matter when applying local rotations as well, but these effects can usually be safely ignored).
ok, what you really need is to in first calculate the rotational velocity (or at least direction) that will "eventually" make u rotate from one vector to another. Once you have that, multiply by dt, take length and convert to quaternion (if needed) using a general {axis, angle} method:

axis = normalize(cross(current, target))
angle = desired_rotational_speed * dt

I hope I caught the essence of your problem.
[ my blog ]

This topic is closed to new replies.

Advertisement