Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Question about my camera (view matrix)

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

## Recommended Posts

I have a camera class that I got from a book ("Introduction to 3d game programming with directx 9.0"). It works great, but I''m having trouble making changes to it. One of the changes I want to make, is create a limit to how far the camera can look up or down. Here is what the code looks like: Here is the code to look up and down:
// This function adjusts the pitch of the camera

void CCamera::Pitch(float angle)
{
D3DXMATRIX T;
D3DXMatrixRotationAxis(&T, &m_xVector, angle);

// rotate y and z around x vector

D3DXVec3TransformCoord(&m_yVector,&m_yVector, &T);
D3DXVec3TransformCoord(&m_zVector,&m_zVector, &T);
TransformCamera();
}

// This function is used to transform the view matrix.  Anytime the camera

// position, or view is changed - this function must be called.

void CCamera::TransformCamera()
{
D3DXMATRIX V;
GetViewMatrix(&V);
m_pd3dDevice->SetTransform(D3DTS_VIEW, &V);
}

// This function returns the view matrix

void CCamera::GetViewMatrix(D3DXMATRIX* V)
{
// Keep camera''s axes orthogonal to eachother

D3DXVec3Normalize(&m_zVector, &m_zVector);

D3DXVec3Cross(&m_yVector, &m_zVector, &m_xVector);
D3DXVec3Normalize(&m_yVector, &m_yVector);

D3DXVec3Cross(&m_xVector, &m_yVector, &m_zVector);
D3DXVec3Normalize(&m_xVector, &m_xVector);

// Build the view matrix:

float x = -D3DXVec3Dot(&m_xVector, &m_posVector);
float y = -D3DXVec3Dot(&m_yVector, &m_posVector);
float z = -D3DXVec3Dot(&m_zVector, &m_posVector);

(*V)(0,0) = m_xVector.x; (*V)(0, 1) = m_yVector.x; (*V)(0, 2) = m_zVector.x; (*V)(0, 3) = 0.0f;
(*V)(1,0) = m_xVector.y; (*V)(1, 1) = m_yVector.y; (*V)(1, 2) = m_zVector.y; (*V)(1, 3) = 0.0f;
(*V)(2,0) = m_xVector.z; (*V)(2, 1) = m_yVector.z; (*V)(2, 2) = m_zVector.z; (*V)(2, 3) = 0.0f;
(*V)(3,0) = x;        (*V)(3, 1) = y;     (*V)(3, 2) = z;       (*V)(3, 3) = 1.0f;
}

So what would I need to change to make it so the user''s range of view (as far as looking up/down) was just 180 degrees instead of being able to look in a 360 degree circle.

##### Share on other sites
Just looking at this, is pitch the only vector you use for now ?

Because you can limit it inside that function!
void CCamera:itch(float angle){    I might do something like this here  Notice the 3.0f is just an arbitrary number.  If you are working in degrees,  this may be 80.0f;    float A=angle;    if(Angle>=3.0f)Angle=3.0f;    else if(Angle<=-3.0f)Angle=-3.0f;    D3DXMATRIX T;	    D3DXMatrixRotationAxis(&T, &m_xVector, A);	// rotate y and z around x vector	    D3DXVec3TransformCoord(&m_yVector,&m_yVector, &T);        D3DXVec3TransformCoord(&m_zVector,&m_zVector, &T);         TransformCamera();}

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632989
• Total Posts
3009742
• ### Who's Online (See full list)

There are no registered users currently online

×