Euler angle rotations

Started by
16 comments, last by rumblesushi 10 years, 6 months ago

You've not seen my Mum driving! Cars roll over all the time in movies and games.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement

Normal car attitudes are very far from the region where Euler angles behave poorly (see gimbal lock). A car is essentially on a horizontal plane, which means that yaw captures most of what's going on. For instance, cars don't usually roll over. Interpolating between attitudes by interpolating Euler angles, for instance, behaves very poorly in general, but for a car you can just interpolate the yaw (making sure you go the short way) and then roll and pitch are small angles anyway, so interpolating them works just fine.

What operation is it that you have a hard time imagining without Euler angles?

Well just those car angles are one example. The angles between the front and back wheels, and left and right wheels are euler angles, needed to define pitch and roll.

In addition to storing the 3 rotations as euler angles, I also store the current steer level of the wheels as a euler angle, and many other things. I might want to make one model rotate to another models yaw angle, plus 90 degrees.

How would you do all that without storing euler angles at all?

Obviously I'm not suggesting handling the rotations themselves with euler rotations, but doesn't simply storing the orientation as 3 angles constitute euler, even if you then use matrices or quaternions to actually handle the orientation of those 3 angles?

As I said I use matrix rotations around local axes, or quaternions built from 3 euler angles from scratch each frame, and I've never encountered gimbal lock with these methods, only via raw euler rotations.

I am surprised you can get away with using Euler angles for almost anything in a car game, actually. If the car jumps off an irregular ramp, so it has some angular velocity, how do you update the attitude of the car from frame to frame? If you use a quaternion or a matrix to represent the attitude, you compose the current attitude with a small increment given by the angular velocity (the exponential of the angular velocity times delta_t, actually) to know the attitude after one more frame. With Euler angles, I have no idea what you do...

And yes, building your rotation from scratch from 3 Euler angles each frame is using Euler angles, and I can't see how you don't run into all sorts of problems.

If the car jumps into the air, I simply apply viscous friction to the angular velocity to level the car out, to make sure they can land easily.

I'm now making a futuristic racer and believe it or not I'm getting better results by building the orientation quaternion from scratch each frame, from 3 Euler angles. I've always had problems in my engine with simultaneous pitch and roll, using incremental matrix or quaternion rotations. The only way I can get perfect, simultaneous pitch and roll with no rotation drift etc, is by building a quaternion from scratch each frame, from 3 euler angles.

Using this method, my ships orient to the track perfectly (using a steer variable for yaw, and 2 raycasts each to define pitch and roll, front and back, left and right).

In this example, for my futuristic racer, how would I go about steering the ships and orienting the ships to the track, while hovering, using no euler angles at all?

I'm genuinely interested, because I just naturally started using euler angles when I built my 3D engine for simplicity (no matrices at all at first, pure euler calculations for not only objects, but even vertex transformation). And I guess that's stuck with me, because thought I of course now use matrices and quaternions for all aspects of my engine, I still rely pretty heavily on euler angles for steering behaviour, orientation etc.


In this example, for my futuristic racer, how would I go about steering the ships and orienting the ships to the track, while hovering, using no euler angles at all?

You know the normal vector to the track and you know which direction you want to face along the track. If your model is such that (1,0,0) is "forward" and (0,1,0) is "up", you can build a rotation matrix whose first column is the desired forward vector and whose second column is the normal to the track. The third column can be computed as the cross product of the first two. That's probably the easiest way to do it.

However, I think I would prefer to create a solid Physics simulation of the situation and apply forces instead of setting the attitude "by hand".


In this example, for my futuristic racer, how would I go about steering the ships and orienting the ships to the track, while hovering, using no euler angles at all?

You know the normal vector to the track and you know which direction you want to face along the track. If your model is such that (1,0,0) is "forward" and (0,1,0) is "up", you can build a rotation matrix whose first column is the desired forward vector and whose second column is the normal to the track. The third column can be computed as the cross product of the first two. That's probably the easiest way to do it.

However, I think I would prefer to create a solid Physics simulation of the situation and apply forces instead of setting the attitude "by hand".

That is the method I used for my first game, which used soft body physics. I composed the matrix from scratch, with its side vector just being a cross product of the forward and up vectors.

Don't you mean 1,0,0 being the side though? It should be 1,0,0 for X, 0,1,0 for Y, and 0,0,1 for Z.

Regarding a solid physics sim, I actually have a decent little solid body physics engine, but I don't use it for several reasons. Partly because I work in Flash, performance is a priority, and I have 20 to 30 ships on the track. Second, I want something more stylised. Solid body physics are more realistic than I want, and less stable.

Also the method you suggest wouldn't be good enough. It relies on just one normal right? Whatever poly is directly underneath your vehicle. I tried it, and I don't like the snapping behaviour, even with interpolation.

Say the ship is perpendicular to a right angle, the 2 raycasts on either side means you get a nice, stable orientation based on the 2 adjacent track normals. Orienting to one normal would have the pitch switching between 2 normals that are 90 degrees apart.

How would you achieve pure matrix rotations with no euler angles based on raycasts like this?

Don't you mean 1,0,0 being the side though? It should be 1,0,0 for X, 0,1,0 for Y, and 0,0,1 for Z.


Whether X is to the side or forward is purely a matter of convention. I don't know how you position your models.


Also the method you suggest wouldn't be good enough. It relies on just one normal right? Whatever poly is directly underneath your vehicle. I tried it, and I don't like the snapping behaviour, even with interpolation.


Well, my method allows you to build a rotation matrix oriented however you want. If you happen to pick some incorrect thing to line up with, it won't be good enough, but that has nothing to do with what I described.

Say the ship is perpendicular to a right angle, the 2 raycasts on either side means you get a nice, stable orientation based on the 2 adjacent track normals. Orienting to one normal would have the pitch switching between 2 normals that are 90 degrees apart.

How would you achieve pure matrix rotations with no euler angles based on raycasts like this?


Your ray casts give you points of intersection with the track. If you have three of these points, they determine a triangle, whose normal you can use to line up with in the manner I just described.


Your ray casts give you points of intersection with the track. If you have three of these points, they determine a triangle, whose normal you can use to line up with in the manner I just described.

Good point. Not sure how I hadn't thought of this, as I did something very similar for my very first racer. Probably because I wasn't that happy with the results ;)

If you have high poly collision geometry this would work fine as is, and be very fast. Otherwise to smooth it out you'd need to create a quaternion from that newly created plane normal, then interpolate your model's quaternion towards it. Which would probably be a bit slower than just creating one quaternion from 3 euler angles.

This topic is closed to new replies.

Advertisement