Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

C++, DirectX9, camera?

This topic is 3297 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

Vector m_UpVector(0, 0, 1); m_EyePos.x = m_TargetPos.x + 100 * zrot * sin(xrot); m_EyePos.y = m_TargetPos.y + 100 * zrot * cos(xrot); m_EyePos.z = m_TargetPos.z + 100 * zrot; D3DXMatrixLookAtLH(&m_View, &m_EyePos, &m_TargetPos, &m_UpVector); zrot changes when mouse wheel is rotated. xrot changes when mouse moved sideways (left/right). yrot changes when mouse moved forward and backwards (up/down). With this code camera rotates left and right, however I've been trying to make it rotate up and down like in MMORPGs for ages, and I can't make it work, maybe anyone could help?

Share this post


Link to post
Share on other sites
Advertisement
I am not sure but try that. (assuming zrot between 0-1)

Vector m_UpVector(0, 0, 1);
m_EyePos.x = m_TargetPos.x + 100 * zrot * sin(xrot);
m_EyePos.y = m_TargetPos.y + 100 * zrot * cos(xrot);
m_EyePos.z = m_TargetPos.z + 100 * (1-zrot);
D3DXMatrixLookAtLH(&m_View, &m_EyePos, &m_TargetPos, &m_UpVector);

this one might give a better result. this time you gie zrot as an angle

Vector m_UpVector(0, 0, 1);
m_EyePos.x = m_TargetPos.x + 100 * cos(zrot) * sin(xrot);
m_EyePos.y = m_TargetPos.y + 100 * cos(zrot) * cos(xrot);
m_EyePos.z = m_TargetPos.z + 100 * sin(zrot);
D3DXMatrixLookAtLH(&m_View, &m_EyePos, &m_TargetPos, &m_UpVector);

Share this post


Link to post
Share on other sites
basically what you do is storing the angle of camera as latitude and longitude. it is easier to use lng&lat while dealing mmorpg type camera

and after that you can convert it to a regular vector using

x = cos(lat)*sin(lng)
y = sin(lat)*sin(lng)
z = cos(lng)

and you multiply this vector by 100 and add to target position to find eye position

Share this post


Link to post
Share on other sites
shultays, I think you understood something wrong, either I explained wrong. zrot value is 0.5f to 5f, and it changes camera distance from my character, but I'll try to replace zrot with yrot in your 2nd sample and try.

Thank you, after replacing it works very well.

Thanks for your 2nd post too :)

Share this post


Link to post
Share on other sites
hmm sorry my mistake ^^ I thought you want to rotate the camera over a character similiar to mmorpgs, not zooming in or out

Share this post


Link to post
Share on other sites
I showed the code I had already, it included zooming in/out and rotating horizontally, probably you misthough my zooming in/out (*zrot) with my vertical rotation, and added sin/cos to it. But don't worry about it

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!