# 3D Cameras

## Recommended Posts

sakky    100
Okay, I have a nice little class called CD3DCamera. I will use it for different types of cameras, a more or less base class so I don’t hae to keep writing the same code over and over again. I haven’t tested it yet because I don’t want to go to all the trouble and have something not work right, I want to make sure the math is correct first. I’m not that good and 3D math, a bummer because I use Direct3D all the time. 1. ) I need to make sure I’m calculating the UP vector correctly. I use the D3DXVec4Cross helper function to get the UP vector. I use the cross product of the look-at-target vector and the original up (0,1,0) vector. 2. ) To rotate, I use D3DXRotationAxis to rotate the camera on any axis I choose. I apply the rotation and use D3DXVec4TransformCoord with the look-at-target vector as the source and destination vector. Then I apply the cross product again to achieve the UP vector. Is this all correct?

##### Share on other sites
sakky    100
Hmm... no replys, I guess that means I'm correct then.

##### Share on other sites
dotproduct    180
Quote:
 Original post by sakky1. ) I need to make sure I’m calculating the UP vector correctly. I use the D3DXVec4Cross helper function to get the UP vector. I use the cross product of the look-at-target vector and the original up (0,1,0) vector.

Well... if you take the cross product of the look-at-target vector (I'm assuming this is a vector from the position of the camera to the look-at target?) and the original up vector. How can you get the new up-vector??
The cross product of two vectors gives you a vector that is perpendicular to both of those vectors.

##### Share on other sites
lubby    290
Which is saying. If you are at the origon and looking(0,0,1) with up(0,1,0) the cross product will return the right vector(1,0,0)

##### Share on other sites
bzroom    647

If your getting your look at vector by transforming a base vector by a matrix, then you can do the same for your up vector

vlook = {1,0,0}; //with no rotation look in the +x direction
vup = {0,1,0}; //with no rotation up is +y

vlook.tranform3(viewChangeMatrix);
vup.tranform3(viewChangeMatrix);

##### Share on other sites
sakky    100
I have three vectors, position, look and up. I use the three in the D3DXMatrixLookAt function. I need the new up vector for the look. How do I get that then?

##### Share on other sites
lubby    290
Generally people use either the world up vector or the camera up vector

You can get the camera up vector by cross product of the forward and right vectors.

##### Share on other sites
bzroom    647
Quote:
 Original post by sakkyI have three vectors, position, look and up. I use the three in the D3DXMatrixLookAt function. I need the new up vector for the look. How do I get that then?

You say you have three vectors but then you ask how to calculate the 3rd? So what you mean is you have 2 points (which is really 1 vector) and you have to ask yourself how did you arrive at this vector. You need to take the same steps and apply them to your up vector to get accurate results. Or just set it to up (0,1,0) always and never look straight up or down.

If you calculate a matrix to get you to your final view vectors this is easy. Just transform your base view vectors by the same matrix and they are all the correct vectors. No cross product or anything.

As far as I know its mathematicaly imposible to calculate the up vector given only the lookFrom and lookAt positions. There is not enough data present.

##### Share on other sites
Zook    134
Quote:
 Original post by sakky2. ) To rotate, I use D3DXRotationAxis to rotate the camera on any axis I choose.

You mean D3DXMatrixRotationAxis? Then the resulting matrix contains all the vectors you need. If I remember correctly first row is right vector, second is up vector and third is look-at vector.

##### Share on other sites
sakky    100
Quote:
Original post by Zook
Quote:
 Original post by sakky2. ) To rotate, I use D3DXRotationAxis to rotate the camera on any axis I choose.

You mean D3DXMatrixRotationAxis? Then the resulting matrix contains all the vectors you need. If I remember correctly first row is right vector, second is up vector and third is look-at vector.

Really? Like I said, I'm not to good with the math. I've been studying though.

Okay, I start off with Position(0,0,0), Look(0,0,1) and Up(0,1,0). So the camera is located at the origin looking straigh down the +Z axis, with the up vector, up, as usual. So to translate or rotate, I apply the same to all three vectors. When I translate, I add a vecctor or three floats to the position of the camera. I'm also suppose to do this to the look and up vectors too?

Okay then, so what ever I do to the one, I must to do to all others.

##### Share on other sites
jyk    2094
Quote:
 I apply the same to all three vectors. When I translate, I add a vecctor or three floats to the position of the camera. I'm also suppose to do this to the look and up vectors too?
No, you never translate the direction vectors.

More specifically, the direction vectors indicate direction only, not position, and describe the orientation of the object. The orientation doesn't change when you translate, so for that and other reasons translating the direction vectors makes no sense.

##### Share on other sites
Zook    134
When you have the rotation matrix from D3DXMatrixRotationAxis or whichever way you use to calculate it, all you need to do is:
Get the updated Up and Look vectors from row 2 and 3 in the matrix.
Then call D3DXMatrixLookAtLH(&viewMat, &Position, &(Position + Look), &Up);

##### Share on other sites
sakky    100
Okay this is what I have right now. Some of this is still in progress of changing from what input you people are giving me.

/* Camera interface */
class CD3DCamera
{
public :

CD3DCamera( void ) ;
virtual ~CD3DCamera( void ) ;

// Helper functions
//
public :

HRESULT __stdcall ConfigureDevice( LPDIRECT3DDEVICE9* ) ;

HRESULT __stdcall Translate( D3DXVECTOR3* ) ;
HRESULT __stdcall Translate( FLOAT, FLOAT, FLOAT ) ;

HRESULT __stdcall Rotate( D3DXVECTOR3*, FLOAT ) ;
HRESULT __stdcall Rotate( FLOAT, FLOAT, FLOAT, FLOAT ) ;

HRESULT __stdcall BuildFrustum( D3DXPLANE[ 6 ] ) ;

private :

HRESULT __stdcall Rebuild( void ) ;

// View matrix
//
public :

HRESULT __stdcall SetPosition( D3DXVECTOR3* ) ;
HRESULT __stdcall SetPosition( FLOAT, FLOAT, FLOAT ) ;
HRESULT __stdcall GetPosition( D3DXVECTOR3* ) ;

HRESULT __stdcall SetLookAt( D3DXVECTOR3* ) ;
HRESULT __stdcall SetLookAt( FLOAT, FLOAT, FLOAT ) ;
HRESULT __stdcall GetLookAt( D3DXVECTOR3* ) ;
HRESULT __stdcall GetUpVector( D3DXVECTOR3* ) ;

HRESULT __stdcall SetView( D3DXMATRIX* ) ;
HRESULT __stdcall GetView( D3DXMATRIX* ) ;

private :

D3DXVECTOR3 m_vPosition ;
D3DXVECTOR3 m_vLookAt ;
D3DXVECTOR3 m_vUp ;

D3DXMATRIX m_xView ;

// Projection matrix
//
public :

HRESULT __stdcall SetFeildOfView( FLOAT ) ;
HRESULT __stdcall GetFeildOfView( FLOAT* ) ;

HRESULT __stdcall SetAspectRatio( DWORD, DWORD ) ;
HRESULT __stdcall SetAspectRatio( FLOAT ) ;
HRESULT __stdcall GetAspectRatio( FLOAT* ) ;

HRESULT __stdcall SetClippingPlanes( FLOAT, FLOAT ) ;
HRESULT __stdcall GetNearPlane( FLOAT* ) ;
HRESULT __stdcall GetFarPlane( FLOAT* ) ;

HRESULT __stdcall SetProjection( D3DXMATRIX* ) ;
HRESULT __stdcall GetProjection( D3DXMATRIX* ) ;

private :

FLOAT m_fFOV ;
FLOAT m_fAspect ;
FLOAT m_fNear ;
FLOAT m_fFar ;

D3DXMATRIX m_xProj ;
} ;

/* Camera implementation */
// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::CD3DCamera( )
// Desc : CD3DCamera constructor
// ---------------------------------------------------------------------------- //
CD3DCamera::CD3DCamera( void )
{
// Clear all data!
//
m_vPosition = D3DXVECTOR3( 0.0F, 0.0F, 0.0F ) ;
m_vLookAt = D3DXVECTOR3( 0.0F, 0.0F, 1.0F ) ;
m_vUp = D3DXVECTOR3( 0.0F, 1.0F, 0.0F ) ;

D3DXMatrixIdentity( &m_xView ) ;

m_fFOV = 0.0F ;
m_fAspect = 0.0F ;
m_fNear = 0.0F ;
m_fFar = 0.0F ;

D3DXMatrixIdentity( &m_xProj ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::~CD3DCamera( )
// Desc : CD3DCamera destructor
// ---------------------------------------------------------------------------- //
CD3DCamera::~CD3DCamera( void )
{
// Do Nothing!
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::ConfigureDevice( )
// Desc : Configures render device's matricies using camera's
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::ConfigureDevice( LPDIRECT3DDEVICE9* ppD3DDevice )
{
if ( NULL != ppD3DDevice )
{
Rebuild( ) ;

( *ppD3DDevice )->SetTransform( D3DTS_VIEW, &( D3DMATRIX )m_xView ) ;
( *ppD3DDevice )->SetTransform( D3DTS_PROJECTION, &( D3DMATRIX )m_xProj ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::Translate( )
// Desc : Translates camera from position
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::Translate( D3DXVECTOR3* pTranslation )
{
D3DXMATRIX xTran ;

if ( NULL != pTranslation )
{
D3DXMatrixTranslation( &xTran, pTranslation->x, pTranslation->y, pTranslation->z ) ;

D3DXVec3TransformCoord( &m_vPosition, &m_vPosition, &xTran ) ;
D3DXVec3TransformCoord( &m_vLookAt, &m_vLookAt, &xTran ) ;
D3DXVec3TransformCoord( &m_vUp, &m_vUp, &xTran ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::Translate( )
// Desc : Translates camera from position
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::Translate( FLOAT fX, FLOAT fY, FLOAT fZ )
{
D3DXMATRIX xTran ;

D3DXMatrixTranslation( &xTran, fX, fY, fZ ) ;

D3DXVec3TransformCoord( &m_vPosition, &m_vPosition, &xTran ) ;
D3DXVec3TransformCoord( &m_vLookAt, &m_vLookAt, &xTran ) ;
D3DXVec3TransformCoord( &m_vUp, &m_vUp, &xTran ) ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::Rotate( )
// Desc : Rotates camera's 'look at' vector
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::Rotate( D3DXVECTOR3* pRotation, FLOAT fAngle )
{
D3DXMATRIX xRot ;

if ( NULL != pRotation )
{
D3DXMatrixRotationAxis( &xRot, pRotation, fAngle ) ;
D3DXVec3TransformCoord( &m_vPosition, &m_vPosition, &xRot ) ;
D3DXVec3TransformCoord( &m_vLookAt, &m_vLookAt, &xRot ) ;
D3DXVec3TransformCoord( &m_vUp, &m_vUp, &xRot ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::Rotate( )
// Desc : Rotates camera's 'look at' vector
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::Rotate( FLOAT fX, FLOAT fY, FLOAT fZ, FLOAT fAngle )
{
D3DXMATRIX xRot ;

D3DXMatrixRotationAxis( &xRot, &D3DXVECTOR3( fX, fY, fZ ), fAngle ) ;
D3DXVec3TransformCoord( &m_vPosition, &m_vPosition, &xRot ) ;
D3DXVec3TransformCoord( &m_vLookAt, &m_vLookAt, &xRot ) ;
D3DXVec3TransformCoord( &m_vUp, &m_vUp, &xRot ) ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::BuildFrustum( )
// Desc : Builds set of frustum planes from camera
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::BuildFrustum( D3DXPLANE vFrustum[ 6 ] )
{
D3DXMATRIX xMulti ;

Rebuild( ) ;

D3DXMatrixMultiply( &xMulti, &m_xView, &m_xProj ) ;

vFrustum[ 0 ].a = ( xMulti._14 + xMulti._13 ) ;
vFrustum[ 0 ].b = ( xMulti._24 + xMulti._23 ) ;
vFrustum[ 0 ].c = ( xMulti._34 + xMulti._33 ) ;
vFrustum[ 0 ].d = ( xMulti._44 + xMulti._43 ) ;
D3DXPlaneNormalize( &vFrustum[ 0 ], &vFrustum[ 0 ] ) ;

vFrustum[ 1 ].a = ( xMulti._14 - xMulti._13 ) ;
vFrustum[ 1 ].b = ( xMulti._24 - xMulti._23 ) ;
vFrustum[ 1 ].c = ( xMulti._34 - xMulti._33 ) ;
vFrustum[ 1 ].d = ( xMulti._44 - xMulti._43 ) ;
D3DXPlaneNormalize( &vFrustum[ 1 ], &vFrustum[ 1 ] ) ;

vFrustum[ 2 ].a = ( xMulti._14 + xMulti._11 ) ;
vFrustum[ 2 ].b = ( xMulti._24 + xMulti._21 ) ;
vFrustum[ 2 ].c = ( xMulti._34 + xMulti._31 ) ;
vFrustum[ 2 ].d = ( xMulti._44 + xMulti._41 ) ;
D3DXPlaneNormalize( &vFrustum[ 2 ], &vFrustum[ 2 ] ) ;

vFrustum[ 3 ].a = ( xMulti._14 - xMulti._11 ) ;
vFrustum[ 3 ].b = ( xMulti._24 - xMulti._21 ) ;
vFrustum[ 3 ].c = ( xMulti._34 - xMulti._31 ) ;
vFrustum[ 3 ].d = ( xMulti._44 - xMulti._41 ) ;
D3DXPlaneNormalize( &vFrustum[ 3 ], &vFrustum[ 3 ] ) ;

vFrustum[ 4 ].a = ( xMulti._14 + xMulti._12 ) ;
vFrustum[ 4 ].b = ( xMulti._24 + xMulti._22 ) ;
vFrustum[ 4 ].c = ( xMulti._34 + xMulti._32 ) ;
vFrustum[ 4 ].d = ( xMulti._44 + xMulti._42 ) ;
D3DXPlaneNormalize( &vFrustum[ 4 ], &vFrustum[ 4 ] ) ;

vFrustum[ 5 ].a = ( xMulti._14 - xMulti._12 ) ;
vFrustum[ 5 ].b = ( xMulti._24 - xMulti._22 ) ;
vFrustum[ 5 ].c = ( xMulti._34 - xMulti._32 ) ;
vFrustum[ 5 ].d = ( xMulti._44 - xMulti._42 ) ;
D3DXPlaneNormalize( &vFrustum[ 5 ], &vFrustum[ 5 ] ) ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::Rebuild( )
// Desc : Rebuilds camera's view & projection matricies
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::Rebuild( void )
{
D3DXMatrixLookAtLH( &m_xView, &m_vPosition, &m_vLookAt, &m_vUp ) ;

D3DXMatrixPerspectiveFovLH( &m_xProj, m_fFOV, m_fAspect, m_fNear, m_fFar ) ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetPosition( )
// Desc : Sets camera's position
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetPosition( D3DXVECTOR3* pPosition )
{
if ( NULL != pPosition )
{
m_vPosition = *pPosition ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetPosition( )
// Desc : Sets camera's position
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetPosition( FLOAT fX, FLOAT fY, FLOAT fZ )
{
m_vPosition.x = fX ;
m_vPosition.y = fY ;
m_vPosition.z = fZ ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetPosition( )
// Desc : Retrieves camera's position
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetPosition( D3DXVECTOR3* pPosition )
{
if ( NULL != pPosition )
{
*pPosition = m_vPosition ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetLookAt( )
// Desc : Sets camera's 'look at' vector
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetLookAt( D3DXVECTOR3* pLookAt )
{
if ( NULL != pLookAt )
{
m_vLookAt = *pLookAt ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetLookAt( )
// Desc : Sets camera's 'look at' vector
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetLookAt( FLOAT fX, FLOAT fY, FLOAT fZ )
{
m_vLookAt.x = fX ;
m_vLookAt.y = fY ;
m_vLookAt.z = fZ ;

D3DXVec3Cross( &m_vUp, &m_vLookAt, &D3DXVECTOR3( 0.0F, 1.0F, 0.0F ) ) ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetPosition( )
// Desc : Retrieves camera's 'look at' vector
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetLookAt( D3DXVECTOR3* pLookAt )
{
if ( NULL != pLookAt )
{
*pLookAt = m_vLookAt ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetUpVector( )
// Desc : Retrieves camera's 'up' vector
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetUpVector( D3DXVECTOR3* pUp )
{
if ( NULL != pUp )
{
*pUp = m_vUp ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetView( )
// Desc : Sets camera's view matrtix
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetView( D3DXMATRIX* pView )
{
if ( NULL != pView )
{
memcpy( &m_xView, pView, sizeof( D3DXMATRIX ) ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetView( )
// Desc : Retrieves camera's view matrtix
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetView( D3DXMATRIX* pView )
{
if ( NULL != pView )
{
Rebuild( ) ;

memcpy( pView, &m_xView, sizeof( D3DXMATRIX ) ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetFeildOfView( )
// Desc : Sets camera's feild of view
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetFeildOfView( FLOAT fFOV )
{
m_fFOV = fFOV ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetFeildOfView( )
// Desc : Retrieves camera's feild of view
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetFeildOfView( FLOAT* pFOV )
{
if ( NULL != pFOV )
{
*pFOV = m_fFOV ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::::SetAspectRatio( )
// Desc : Sets camera's view aspect ratio
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetAspectRatio( DWORD dwWidth, DWORD dwHeight )
{
m_fAspect = ( ( FLOAT )dwWidth ) / dwHeight ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::::SetAspectRatio( )
// Desc : Sets camera's view aspect ratio
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetAspectRatio( FLOAT fAspect )
{
m_fAspect = fAspect ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::::GetAspectRatio( )
// Desc : Retrieves camera's view aspect ratio
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetAspectRatio( FLOAT* pAspect )
{
if ( NULL != pAspect )
{
*pAspect = m_fAspect ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetClippingPlanes( )
// Desc : Sets camera's clipping plane
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetClippingPlanes( FLOAT fNear, FLOAT fFar )
{
m_fNear = fNear ;
m_fFar = fFar ;

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetFarPlane( )
// Desc : Retrieves camera's near clipping plane
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetNearPlane( FLOAT* pNear )
{
if ( NULL != pNear )
{
*pNear = m_fNear ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetFarPlane( )
// Desc : Retrieves camera's far clipping plane
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetFarPlane( FLOAT* pFar )
{
if ( NULL != pFar )
{
*pFar = m_fFar ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::SetProjection( )
// Desc : Sets camera's projection matrtix
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::SetProjection( D3DXMATRIX* pProj )
{
if ( NULL != pProj )
{
memcpy( &m_xProj, pProj, sizeof( D3DXMATRIX ) ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

// ---------------------------------------------------------------------------- //
// Name : CD3DCamera::GetProjection( )
// Desc : Retrieves camera's projection matrtix
// ---------------------------------------------------------------------------- //
HRESULT __stdcall CD3DCamera::GetProjection( D3DXMATRIX* pProj )
{
if ( NULL != pProj )
{
Rebuild( ) ;

memcpy( pProj, &m_xProj, sizeof( D3DXMATRIX ) ) ;

return ( S_OK ) ;
}

return ( E_INVALIDARG ) ;
}

So what you are saying then Zook, is if I use the D3DXMatrixRotation function, I just use the matrix's vectros. In my interface, the helper functions are you rotate and move the camera and to build it's matrices and also to contruct a view frustum. I also have accessor functions that can do similar, but the helper functions sort of wrapp things up to do a little more.

First off, I have the rotate group. These set of functions do that same, just overloaded for different types of parameters. I want these functions to rotate from the current orientation. Translation is handled that same.

So then, I was wondering if I use the vectors to adjust rotation and translation only, but to use them as part of the matrix rotation axis function. Like, when I rotate, the up vector or position will be the axis I rotate on. Then I get the vectors from the matrix, right?

##### Share on other sites
sakky    100
I know it may sound as if I'm not listening to you advice guys, but I am. It's just that this is alot to take in for me because I'm not to good at math, never had a real tutorial besides programming books, other books and SDK documentations.

But I have gotten father. I now see that the only two vectors or transformation I really need to concern my self with are look-at-target, up and the rotation transformations. This is because translation only effects on vector and the up vector nor the look-at vector is uneffected by it. I would count three vectors if I include the right vector. But frfom what I've learned so far, if I have the look and up vectors, then I can have the right vector from the cross product.

##### Share on other sites
Zook    134
Are you saying you want to rotate around any of the three axes in your current orientation (up, right, look)? Then it's as simple as D3DXMatrixRotationYawPitchRoll.
To make the rotation relative to your current orientation you need to concatenate the rotation matrix with a matrix that you use to store your current orientation.
Something like this:

D3DXMATRIX orientation; //Current orientation(class member)

Iinitialize it as the identity matrix which makes right=(1,0,0), up=(0,1,0), look=(0,0,1)
D3DXMatrixIdentity(&orientation);

Then every frame calculate the rotation matrix and use it to update the current orientation:

D3DXMATRIX rotation;
D3DXMatrixRotationYawPitchRoll(&rotation, yaw, pitch, roll);
orientation = rotation * orientation;

Then use row 2 and 3 from the orientation matrix as described in my last post.

Remember that the order by which you multiply matrices is important.
orientation = rotation * orientation; is correct
orientation = orientation * rotation; will give strange results

Hope this helps!

[Edited by - Zook on November 26, 2005 7:38:32 AM]

##### Share on other sites
sakky    100
I don't use matricies for my camaera tho, I only use the two that I have in my class for easy use with creating them or retrieving them from the camera. I use the given vecctors position, up, right and look-at for my camera.

##### Share on other sites
Trienco    2555
Quote:
 Original post by sakkyI use the given vecctors position, up, right and look-at for my camera.

Well, replace "look-at" with "forward" and it IS nothing but a transformation matrix if you use the order right/up/forward/position.