Jump to content
  • Advertisement
Sign in to follow this  
simotix

Bad Camera?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason when I create a scene and I move around, -1(x) is on the right and +1(x) is on the left. -1(y) is up and +1(y) is down. Does anyone know what could be doing this?

Share this post


Link to post
Share on other sites
Advertisement
m_pCam->BuildPerspective(D3DX_PI/3, (float)(nWidth/nHeight), 0.1f, 500.0f); is how I build my projection matrix, this is the function

void CCamera::BuildPerspective(float fFieldOfView, float fAspect, float fZNear, float fZFar)
{
D3DXMatrixPerspectiveFovLH(&m_mProjectionMatrix, fFieldOfView, fAspect, fZNear, fZFar);
}

m_pCam->SetViewPosition(0.0f, -10.0f, 5.0f); is how i build my view matrix

void CCamera::SetViewPosition(float fX, float fY, float fZ)
{
m_mViewMatrix._41 = fX;
m_mViewMatrix._42 = fY;
m_mViewMatrix._43 = fZ;
}

I call SetViewPosition before BuildPerspective. Does anyone know why?

Share this post


Link to post
Share on other sites
Quote:
Original post by simotix
m_pCam->BuildPerspective(D3DX_PI/3, (float)(nWidth/nHeight), 0.1f, 500.0f); is how I build my projection matrix, this is the function

void CCamera::BuildPerspective(float fFieldOfView, float fAspect, float fZNear, float fZFar)
{
D3DXMatrixPerspectiveFovLH(&m_mProjectionMatrix, fFieldOfView, fAspect, fZNear, fZFar);
}

m_pCam->SetViewPosition(0.0f, -10.0f, 5.0f); is how i build my view matrix

void CCamera::SetViewPosition(float fX, float fY, float fZ)
{
m_mViewMatrix._41 = fX;
m_mViewMatrix._42 = fY;
m_mViewMatrix._43 = fZ;
}

I call SetViewPosition before BuildPerspective. Does anyone know why?
What is m_mViewMatrix intiailised to? An identity matrix? There's another 13 values in the matrix that need set apart from the position.

Also, what is the value of fFieldOfView? And are you passing it in as radians? Putting a value in degrees comes out as a crazy value in radians (90 radians is 5156 degrees), and can give results like you're seeing.

Share this post


Link to post
Share on other sites
In my classes constructor I do

D3DXMatrixIdentity(&m_mProjectionMatrix);
D3DXMatrixIdentity(&m_mViewMatrix);

So they are both set to identity matrices. My fFieldOfView is set to 3.14/3

Share this post


Link to post
Share on other sites
It may or may not be related to your problem, but you should set the aspect ratio to:
float(nWidth)/nHeight

rather than:
float(nWidth/nHeight)


If nWidth is less than nHeight, float(nWidth/nHeight)=0, assuming nWidth and nHeight are integer. (nWidth/nHeight) is an integer divide!

Share this post


Link to post
Share on other sites
I don't think it's related to your problem, but you're not setting the position of your camera correctly in CCamera::SetViewPosition. The view matrix is equivalent to the inverse of the corresponding transform matrix, so if you set the translation in that manner you'd have to take the inverse of that matrix before applying it.

Share this post


Link to post
Share on other sites
Turns out I wanted to do

D3DXMatrixPerspectiveFovRH(&m_mProjectionMatrix, fFieldOfView, fAspect, fZNear, fZFar);

Thanks for the help!

Share this post


Link to post
Share on other sites
Actually, I have more question about the camera. How can I tell what direction I am looking in?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!