# camera

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

## Recommended Posts

Hi, To orbit around an object in y direction, how should I modify my up vector. [Edited by - tinu on March 26, 2007 1:28:53 AM]

##### Share on other sites
You don't. If you use a look-at matrix, set the look-at vector to your object, and move your camera in a circle around the object.

##### Share on other sites
How to
move camera in a circle around the object.

##### Share on other sites
You google for some basic matrix mathematics. Are you sure you want to rotate the camera around the object, and not rotate the object on the spot?

##### Share on other sites
s.I need to rotate the camera around the object.

##### Share on other sites
D3DXMatrixLookAtLH() will do the job then, and you can just have the camera position move in a circle as:
D3DXVECTOR3 vPos(sin(angle), 0.0f, cos(angle)); where angle is the angle you want to use, which will be incrementing each frame.

##### Share on other sites
Given an angle and a radius, you can use some simple trig to determine the X and Y position.

                             Camera                             +                            /|                          /  |                 radius /    |                      /      |                    /        | Y                  /          |                /           _|              / theta      | |             +---------------+         Object      X

SOHCAHTOA

You'll need to modify the axes to rotate on the Y axis (for simplicity this is an example of rotating on the Z axis).

EDIT: Yeah, what Evil Steve said.

##### Share on other sites
Yes.
This is true in orbiting in x-direction
But to orbit in y direction what should i do?

z = Radius * cos( Angle );
y = Radius * sin( Angle );

Is this correct?

If I do this,At particular angles my object disappears.

To avoid this, should I modify my up vector also?

##### Share on other sites
Quote:
 Original post by tinuYes.This is true in orbiting in x-direction But to orbit in y direction what should i do?z = Radius * cos( Angle );y = Radius * sin( Angle );Is this correct?If I do this,At particular angles my object disappears.To avoid this, should I modify my up vector also?
To orbit around the Y axis, you modify X and Z. You only change the up vector if the "up" direction has changed - which is if you rotate the camera around either X (Pitch) or Z (roll).

##### Share on other sites
To rotate the camera around X axis (pitch as mentioned)
how should i modify my up vector

##### Share on other sites
Your up vector should always be at right angles to your right and forwards vectors. So you can take the cross product of the two of them and use that as your up vector.

##### Share on other sites
What does forward vector mean?

Is it a vector formed by camera look at and camera position points.

What does a right vector mean?

##### Share on other sites
I'd highly recommend looking at some basic trigonometry and matrix maths stuff before going any further or you're just going to get very confused. The forwards vector is the vector that describes the direction of the camera, which is the normalised vector of viewTarget - cameraPos. The right vector is a vector that is at right angles to the forward vector. If you know the forwards vector and the up or right vector, you can calculate the last vector by using the vector cross product.

##### Share on other sites
I have only my forward vector.
I don't have right or up vectors.
How can I compute Right vector ( a perpendicular to forward vector which is known)
in direct X?

##### Share on other sites
Well, if you know your forward vector, the right vector will be 90 degrees to the right. So you can calculate that using the same trig as mentioned by Sc4Freak and I.

##### Share on other sites
To rotate around X pitch as mentioned,I do the following:

CameraPosition.z = Camera_Radius * cos( Angle * 0.0174 );
CameraPosition.y = Camera_Radius * sin (Angle * 0.0174 );

FwdVector.x=0.0f;
FwdVector.y=Camera_Radius * sin( 90 * 0.0174 );
FwdVector.z=Camera_Radius * cos( 90 * 0.0174 );

Is this correct?

##### Share on other sites
FwdVector should be equal to CameraDirection, and the right vector should be at 90 degrees to the forwards vector. I think this will work (not tested):

D3DXVECTOR3 vRight;
vRight.x = 0.0f;
vRight.z = Camera_Radius * cos ((Angle+90.0f) * 0.0174);
vRight.y = Camera_Radius * sin ((Angle+90.0f) * 0.0174);

You'd still be far easier rotating the object instead of the camera though, there's a reason functions like this don't already exist in D3DX.

##### Share on other sites
Thank you Sir,

it helped me a lot.

Now orbiting along X and Y are happening properly.

But combination does not work properly.

Why is it so?

##### Share on other sites
Define "does not work properly".

##### Share on other sites
If I am orbiting in X or Y direction separately , its working properly.. But If I rotate around Y direction after along X direction and vice versa, the orbiting doesn't work..

##### Share on other sites
on successive change in orbiting,orbit along X causes some orbiting along y also and vice versa.

##### Share on other sites
I did thing like that without any problems using just formula

matFinal = matCenterOfRotation * matScaling * matRotation * matTranslation;

where:

matCeneterOfRotation - D3DXMatrixTranslation result (center point of rotation )

matScaling - D3DXMatrixScaling result (object scaling matrix)

matRotation - D3DXMatrixRotationYawPitchRoll result (angle x,y,z to rotate)

matTranslation - D3DXMatrixTranslation result (distance from center of rotation)
use "0.0, 0.0, -zDist" as parameter to move camera back from rotation center.

##### Share on other sites
how can I achieve similar orbiting effect with quaternions.
I construct a Quaternion give it an axis and an angle.
Then how should I proceed to achieve the orbiting effect .

##### Share on other sites

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