Rotations...is this even possible?

Started by
7 comments, last by karwosts 14 years, 1 month ago
First of all I should say I'm not working with c++ or openGl or any 'real' language, I just don't have the patience to work with them. I'm using a language aptly named game maker. It's not the most powerful but in theory you should be able to do almost anything with it... But my particular problem doesn't really concern what programming language I'm using, it is entirely mathematical. I'm trying to setup a trackball camera system in 3 dimensions. Setting up a camera in GM is incredibly easy but the problem is getting it to rotate right, or rather getting it to rotate right and being able to control it in the way that I want to. First of all I should describe my ideal camera system to you. It's ridiculously easy to understand and is controlled entirely by three buttons. Each button corresponds to x,y, and z axis rotation relative to the camera. So x axis rotation spins the screen around in a circle, y axis allows you to look 'up' or 'down' and z axis rotation allows you to look 'left' or 'right'. Like I said its very easy to imagine and It really should not be as hard as it has been. Secondly I should say that my first attempt at this was to use Euler matrices. I really liked how these worked and they actually made at least some sense. Specifically I liked that the rotation could be defined in terms of x,y, and z axis rotation. I could say set the x rotation to 90 and instantly get a change in position to the corresponding rotation. The problem with this system of course is gimbal lock, losing 1 degree of freedom at certain intervals of rotation. So I tried two systems next: rotation about an arbitrary axis and quaternions. I would later find out that these are exactly the same (see: http://www.gamedev.net/reference/articles/article1199.asp) and both had the exact same problem. Certainly the rotation 'worked' but what happened to terms of x,y, and z rotation? I can no longer tell the camera to rotate some arbitrary amount on a given axis but rather have to lead it to this amount. I tried sort of system where x,y, and z rotation was kept track of but this inevitably led to error and just didn't 'feel' right. So is it possible, using any sort of math or trick to get trackball camera motion and still be able to keep track of x,y, and z axis rotation and still be able to set these rotations to a fixed value and see the proper rotation? In another sense can I define the type of rotation I see in a quaternion or arbitrary axis system with euler angles?
Advertisement
You shouldn't have problems with Gimbal Lock to be honest. Just use Euler angles.

PS: I use quaternions and it works just fine for my camera, no idea what you're talking about.
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
I can try to help you more with the concepts, but I think your description from what you want in a camera is still slightly ambiguous.

Quote:First of all I should describe my ideal camera system to you. It's ridiculously easy to understand and is controlled entirely by three buttons. Each button corresponds to x,y, and z axis rotation relative to the camera. So x axis rotation spins the screen around in a circle, y axis allows you to look 'up' or 'down' and z axis rotation allows you to look 'left' or 'right'. Like I said its very easy to imagine and It really should not be as hard as it has been.


There are two types of rotations you can do, and I'm not sure which one you are aiming for. These are Local and Global rotations.

In local rotation, the current orientation of the object defines the axis of rotation. Imagine looking straight up. If you "turn right" with a local rotation, your view will start to move toward the right until you are looking right, then down, then left, and finally back around toward up again. You might imagine this how a spaceship moves.

If you "turn right" in a global rotation, you are always rotating around the global up vector. This means what is in your view will never change, you will always be looking "up" toward the sky, but you will be spinning around in circles and your screen will be rotating.

Typically a FPS would have the right/left rotation be global rotation, and the up/down rotation as a local rotation. This is because the camera is always rotated first around the global up vector, then rotated up/down around the local right vector. In situations like this where you rotate successively around one axis then another than you can get into gimbal lock.

Which one of these situations sounds more like what you are trying to achieve? Telling me "look left or right" doesn't fully describe it because I don't know if you mean left and right in a local space or a global space.

Also I should probably mention that I believe the X axis is generally referred to as "right", the Y axis as "up", and the Z axis as "out". So then rotating "left/right" is rotating around the Y axis, up/down is rotating around the X axis, and screen rolling is rotation around the Z axis. Not a big deal but it may help when communicating problems like this.




[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Look I have tried quternions and arbitrary axis rotation (what you would call local rotation) and they 'work'. But I dislike how they are controlled. I would like to control these rotations with euler angles (that is by setting x,y, and z rotation to specific values) but without encountering any sort of gimbal lock. By left,right,up,down, I mean left, right, up, and down in local space but controlled by global rotation. So I am sort of looking for a combination of global and local rotation.

[Edited by - 1101 on March 10, 2010 1:17:58 PM]
All these details of Euler angles, quaternions, axis-angle... They aren't the main concepts. There's a much more general way to think about your problem, which I think will help you (it helps me). First let me use an analogy:

Picture the surface of the Earth. It is a sphere, a 2-manifold (because locally it always "looks" like 2-dimensional Euclidean space), embedded in 3-space. It's not too difficult to picture moving around on this surface, and you can surely picture what tangent vectors to the sphere are, so it will be a nice visual metaphor for what comes next.

The set of rotations, together with a notion of how "far apart" different rotations are, also form a smooth manifold; it's called SO(3). It is a 3-manifold which we typically embed in the 9-dimensional space of 3x3 matrices.

What are the tangent vectors to this manifold, with this embedding?

I ask because one way to think about your problem is this: You want, for each point on your manifold -- each possible rotation -- to assign to each key a tangent vector. Then, when you push that key, you should move on the manifold a little in that direction. This set of tangent vectors is a frame on your manifold.

Now to answer my question: The tangent vectors are the 3x3 skew-symmetric matrices. Such a matrix only has three unique elements, so there is a simple bijection between them and R^3 (sometimes called the "hat operator"). It turns out that this vector in R^3 is actually the instantaneous axis of rotation; its length gives the speed of rotation, and its direction together with the right hand rule gives the direction.

So basically, the question now boils down to, "how do you want to assign frames to points on your manifold?" This is your design choice. And every single system you can think of -- whether using Euler angles, or quaternions, or what-have-you -- will boil down to this.
@) Emergent

Up until you started talking about Bijections (something I know nothing about) you seemed to describe the type of rotation system I am using exactly. I am using three tangent vectors, which would be <1,0,0>, <0,1,0> and <0,0,1> before any rotation occurs. <1,0,0> would be the direction the camera is looking in and also correspond to the 'x-axis', <0,1,0> corresponds to the side of the camera and the y axis, and <0,0,1> corresponds to the top of the camera and the z-axis. This would correspond to what you call a frame.

What I'm a little confused about is your reference to Bijections. I've literally never heard this term so I am very unfamiliar with them. I am using a matrix to handle rotations and I can see what you mean when you say there are only really three unique elements.

Now you say that given that a 3x3 matrix only has three unique elements that R^3 (meaning the axis of the third dimension correct?) is in fact the axis of instantaneous rotation. What exactly do you mean by this? Because I am certainly rotating by other axes than this one. I understand that this axis controls the direction and magnitude of rotation but that's about it. I should also mention that all my 'tangent vectors' as you put it are unit vectors.

I believe you understand my problem when you ask how I want to assign frames. Basically I want to assign them like I would euler angle rotation (by adding,subtracting, or setting x,y, and z axis rotation values). But to do this without encountering any sort of gimble lock or otherwise losing a degree of freedom. Like I said in my other posts I have already achieved three degrees of complete freedom using arbitrary axis rotation and quaternions but am not able to control it by setting euler angle values.
Quote:Original post by 1101
Up until you started talking about Bijections (something I know nothing about) you seemed to describe the type of rotation system I am using exactly.


Oh!

A bijection is just a one-to-one mapping from one set to another, with the added requirement that the mapping be "onto" (which just means no part of the range is left out).

It's a concept I'm sure you already use without thinking about; so I guess this is basically just vocabulary.

In this case the bijection I was talking about was the "hat operator," which takes a vector and returns a skew-symmetric matrix, in the following way,



so it's a mapping from to the subset of that is skew-symmetric. It's called the "hat operator" because people usually write it like,



where a is a 3-vector and A is a 3x3 matrix. You can see that, given a 3x3 skew-symmetric matrix, you can construct the 3-vector and vice versa; that's what makes the mapping a bijection.
I'm still not sure how to setup the rotation the way I want it. Are you talking about this technique here?

http://en.wikipedia.org/wiki/Euler%27s_rotation_theorem

[Edited by - 1101 on March 10, 2010 3:16:13 PM]
Quote:Basically I want to assign them like I would euler angle rotation (by adding,subtracting, or setting x,y, and z axis rotation values). But to do this without encountering any sort of gimble lock or otherwise losing a degree of freedom.


You can't do this. When you specify that you want to use intrinsic euler angles, by the very design of your camera you will have gimbal lock. There's not some different way to compute it so that it won't happen.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement