Sign in to follow this  
jckut10

Constraining quaternions for gradual rotation

Recommended Posts

jckut10    122
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

Share this post


Link to post
Share on other sites
jckut10    122
Hm, no takers? Here's some code as it is now:

Dim As Vector VecToTarget = TargetObj->Coords - Obj.Coords
Dim 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.

Share this post


Link to post
Share on other sites
jyk    2094
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 :).

Share this post


Link to post
Share on other sites
skalco6    181
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...

Share this post


Link to post
Share on other sites
Vorpy    869
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.

Share this post


Link to post
Share on other sites
jyk    2094
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).

Share this post


Link to post
Share on other sites
arithma    226
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this