🔒 Locked
camera
Advertisement
Original Post
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?
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.
D3DXVECTOR3 vPos(sin(angle), 0.0f, cos(angle)); where angle is the angle you want to use, which will be incrementing each frame.
Given an angle and a radius, you can use some simple trig to determine the X and Y position.
SOHCAHTOA
X = cos(theta) * radius
Y = sin(theta) * radius
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.
Camera + /| / | radius / | / | / | Y / | / _| / theta | | +---------------+ Object XSOHCAHTOA
X = cos(theta) * radius
Y = sin(theta) * radius
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.
Quote: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).
Original post by tinu
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?
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.
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.
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.
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 );
D3DXVec3Normalize(&CameraDirection,&(Target position -Camera Position));
FwdVector.x=0.0f;
FwdVector.y=Camera_Radius * sin( 90 * 0.0174 );
FwdVector.z=Camera_Radius * cos( 90 * 0.0174 );
D3DXVec3Cross(&Up,&FwdVector,&CameraDirection);
Is this correct?
CameraPosition.z = Camera_Radius * cos( Angle * 0.0174 );
CameraPosition.y = Camera_Radius * sin (Angle * 0.0174 );
D3DXVec3Normalize(&CameraDirection,&(Target position -Camera Position));
FwdVector.x=0.0f;
FwdVector.y=Camera_Radius * sin( 90 * 0.0174 );
FwdVector.z=Camera_Radius * cos( 90 * 0.0174 );
D3DXVec3Cross(&Up,&FwdVector,&CameraDirection);
Is this correct?
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.
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.
Define "does not work properly".
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement