Sign in to follow this  
Ripiz

C++, DirectX9, camera?

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this