# Orbit camera movement

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am creating an editor which needs camera movements similar to those of a model viewer/editor. The camera is controlled with the mouse. So now I want to rotate the camera around a point. The position is easy, but I am having trouble with the orientation. I first tried to use a simple lookat, but the camera flips around when you go over the point. Instead the camera should keep moving the same way and therefore be upside down. I tried to fix this using all kinds of weird stuff but I have failed so far. So how do I make this work? How do I get a camera that orientates properly while moving around a point. The camera is not allowed to roll (x.y==0). I would very much prefer to use matrices and not quaternions, because I simple don't understand quaternions :)

[Edited by - Hedanito on August 28, 2010 2:01:10 PM]

##### Share on other sites
Since no one replied I tried using quaternions. But that messed up things even more. According to the book I got it from and also some sources on the internet the x,y and z components are sin(angle/2)*x etc. But when the angle is 0, the vector is zero as well and therefore just disappears. I tried using other values like 90 and 180 degrees (yes converted to radians) but that gave me a messed up orientation as well (the 180 one as well, strangely enough). So could someone please give me a way, any kind of way, to do this? I really need it to be able to continue with my project.

##### Share on other sites
Whatever problem you're having, using quaternions isn't going to solve it. (Using quaternions is certainly an option, but it isn't the solution to your problem.)

As for the problem you mentioned, I'm not completely clear on how the camera controls are intended to work. Can you describe them in more detail, and/or specify a modeling program that uses this type of control scheme?

##### Share on other sites
Quote:
 Original post by jykWhatever problem you're having, using quaternions isn't going to solve it. (Using quaternions is certainly an option, but it isn't the solution to your problem.)As for the problem you mentioned, I'm not completely clear on how the camera controls are intended to work. Can you describe them in more detail, and/or specify a modeling program that uses this type of control scheme?

Maya uses this type of camera. I bet pretty much any other modeling program does as well. The camera needs to look at a point, but also needs to be able to go upside down, unlike for example lookat, where the camera will flip around when you move over a point.

##### Share on other sites
So this is what I have currently:

matrix3x3 m;m.FromEulerAngles(-((float)MousePosRel[0])*0.01f,((float)MousePosRel[1])*0.01f,0.0f);viewcamera[0].SetPosition(viewcamera[0].GetPosition()*m);m.SetZ(viewcamera[0].GetOrientation().GetZ().RotatedAroundAxis(viewcamera[0].GetOrientation().GetX(),((float)MousePosRel[1])*0.01f));m.SetY(viewcamera[0].GetOrientation().GetY().RotatedAroundAxis(viewcamera[0].GetOrientation().GetX(),((float)MousePosRel[1])*0.01f));m.SetX(m.GetY().Cross(m.GetZ()));//m.SetX(m.GetX().RotatedAroundAxis(vector3(0.0f,1.0f,0.0f),-((float)MousePosRel[0])*0.01f));//m.SetY(m.GetY().RotatedAroundAxis(vector3(0.0f,1.0f,0.0f),-((float)MousePosRel[0])*0.01f));//m.SetZ(m.GetZ().RotatedAroundAxis(vector3(0.0f,1.0f,0.0f),-((float)MousePosRel[0])*0.01f));					viewcamera[0].SetOrientation(m);

I now got the position and the x orientation working perfectly. The camera can now go upside down. I still have a problem though, when I try to rotate all the axis around the global y axis, thing go wrong again. Rolling and weird orientation as a result. I didn't think rolling would be possible when rotating an x axis with y=0 around the global y axis.

Oh and here is my axis rotation code in case something is wrong with it:
vector3 RotatedAroundAxis(const vector3 &v,float angle){	return vector3(		(v.x*(v.x*x+v.y*y+v.z*z)+(x*(v.y*v.y+v.z*v.z)-v.x*(v.y*y+v.z*z))*cos(angle)+sqrt(v.x*v.x+v.y*v.y+v.z*v.z)*(-v.z*y+v.y*z)*sin(angle))/(v.x*v.x+v.y*v.y+v.z*v.z),		(v.y*(v.x*x+v.y*y+v.z*z)+(y*(v.x*v.x+v.z*v.z)-v.y*(v.x*x+v.z*z))*cos(angle)+sqrt(v.x*v.x+v.y*v.y+v.z*v.z)*(v.z*x-v.x*z)*sin(angle))/(v.x*v.x+v.y*v.y+v.z*v.z),		(v.z*(v.x*x+v.y*y+v.z*z)+(z*(v.x*v.x+v.y*v.y)-v.z*(v.x*x+v.y*y))*cos(angle)+sqrt(v.x*v.x+v.y*v.y+v.z*v.z)*(-v.y*x+v.x*y)*sin(angle))/(v.x*v.x+v.y*v.y+v.z*v.z)	);}

I got the formula from here: http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/

##### Share on other sites
I didn't look at your code, but, do you know if Blender uses the kind of camera control you're referring to? If so, what 'mode' does it correspond to? (That is, in Blender, how do you move the camera in the way you're describing?)

Also, this is just a guess, but maybe it's an 'arcball' camera that you're looking for. If so, I think there are examples of how to implement such a camera floating around online.

##### Share on other sites
Arcball is similar to what I need, but not the same. With arcball you actually grab a point on a sphere and then rotate it according to the input. It seems like what I need is called an orbit camera.

And about the code I posted, I checked and the y of the x-axis actually is zero. Still, I get orientations like this: http://img835.imageshack.us/img835/9467/trackeditorcamera.png
How the hell is that even possible to do with an y of 0 on the x-axis.
URGH this is totally pissing me off.

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 11
• 23
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631406
• Total Posts
2999907
×