• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

# Euler angle rotations

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

17 replies to this topic

### #1nkarasch  Members

Posted 26 October 2013 - 06:23 PM

First, rotate alpha around the z axis, then rotate beta around the new y', finally rotate gamma around the new z''.

How would you accomplish this? I know how to do rotations around the X, Y, Z axis, but those are not applicable in this case other than the inital rotation right? It's the rotations around the "new" axis that are throwing me off.

Edited by nkarasch, 26 October 2013 - 06:24 PM.

### #2Paradigm Shifter  Members

Posted 26 October 2013 - 06:33 PM

Bit difficult to say when you don't provide a link for the quote or any context...

Normally you pick a rotation axis order (e.g. XYZ or ZYX) and write a function which converts Euler angles into a matrix, by directly multiplying the X Y and Z rotation matrices and doing the algebra.

Euler angles are pretty bad except for certain situations though (gun turrets that can rotate and look up and down, or characters rotating and looking up/down in an FPS). Otherwise use quaternions.

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

### #3nkarasch  Members

Posted 26 October 2013 - 06:43 PM

"You will eventually regret any use of Euler angles." -John Carmack

Part of my assignment:

Parameters of the rotation have been pre-calculated and stored in an attached data file (el1_sh.txt). In the file, the 1st column is timestamp and the rest three columns specify Euler angles of rotations: the 2nd column is alpha, 3th column is beta, 4th column is gamma. There are several definitions of Euler angles. The Euler angle definition used in the file is: First, rotate alpha around the z axis, then rotate beta around the new y', finally rotate gamma around the new z''.

In this assignment, you are asked to animate this series of rotation.

So I need to produce a transformation matrix for these rotations

These kinds of rotation matrices can't give me rotations around the "new" y' and z'' can they? aren't they only relative to the x, y and z of my coordinate system?

### #4Paradigm Shifter  Members

Posted 26 October 2013 - 06:48 PM

You pick the order in which to rotate and then always multiply in that order. You can simplify it by doing the multiplication by hand and then do it in a function. You only need 1 function since you always use the same rotation order.

Carmack is right though.

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

### #5nkarasch  Members

Posted 26 October 2013 - 07:36 PM

http://wolfr.am/1cjQWiv

Does that look right?

I would just go ahead and try it but I have no idea how my end result is supposed to look. All I can do is make sure I'm right on a theory level.

### #6Paradigm Shifter  Members

Posted 26 October 2013 - 07:43 PM

No, you used XYX so used the X rotation twice. Also you only need 3x3 matrices for rotations so don't bother with 4x4 for now (you need that for translations and perspective matrices though).

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

### #7nkarasch  Members

Posted 26 October 2013 - 07:56 PM

z axis, then rotate beta around the new y', finally rotate gamma around the new z''

I used ZYZ, doesn't that match up to what that says?

Thanks for your input

### #8Álvaro  Members

Posted 26 October 2013 - 08:04 PM

ZYZ is possibly correct. I believe Proper Euler angles are like that, with the same first and last axis. Convert from that format to a sane one (matrices or quaternions) as soon as possible in your program and forget about angles.

### #9rumblesushi  Members

Posted 27 October 2013 - 03:28 PM

I have no problem with Euler angles at all. I keep track of yaw, pitch and roll via simple euler variables and handle rotations in one of 2 ways.

Either incrementing an orientation matrix each time one of the rotations changes (matrix.arbitraryRotation(yaw-oldYaw) for example), or construct a new quaternion from scratch using my 3 euler angles each frame. For 6dof objects, that have constantly changing pitch, yaw, and roll - I've found the quaternion from scratch method to be the best and fastest.

For my car rotations, my euler angles for pitch and roll are simply the angles calculated from road raycasts of the front and back wheels, and left and right wheels respectively.

To be honest I'm not really sure how you could get away with not using euler angles at all. Maybe for something like a plane game for example, where the player just manually increments all axis rotations, and you don't need to calculate euler angles between points?

In all the games I've developed euler angles have seemed essential.

### #10Álvaro  Members

Posted 28 October 2013 - 12:48 PM

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?

### #11Paradigm Shifter  Members

Posted 28 October 2013 - 12:51 PM

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

### #12rumblesushi  Members

Posted 29 October 2013 - 03:50 PM

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.

### #13Álvaro  Members

Posted 30 October 2013 - 07:47 AM

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.

### #14rumblesushi  Members

Posted 30 October 2013 - 08:36 PM

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.

### #15Álvaro  Members

Posted 31 October 2013 - 06:21 AM

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".

### #16rumblesushi  Members

Posted 31 October 2013 - 05:47 PM

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?

### #17Álvaro  Members

Posted 31 October 2013 - 07:38 PM

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.

### #18rumblesushi  Members

Posted 31 October 2013 - 08:48 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.