Jump to content
  • Advertisement

Archived

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

Max Payne

Free-Look Camera Mode in Counter-Strike

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

With the following commands, I can move the camera forward, backward, left, right, rotate left and right. It is perfect. // Get the previous position of the camera g_pd3dDevice->GetTransform(D3DTS_VIEW, &matViewOld); D3DXMatrixTranslation(&matTranslation, g_fPosX, g_fPosY, g_fPosZ); D3DXMatrixRotationY(&matRotationY, D3DXToRadian(g_fAngleY)); D3DXMatrixMultiply(&matView, &matTranslation, &matRotationY); D3DXMatrixMultiply(&matView, &matViewOld, &matView); g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); Now, I want to add pitch up and down (move camera up and down), so I have modified above commands like these: // Get the previous position of the camera g_pd3dDevice->GetTransform(D3DTS_VIEW, &matViewOld); D3DXMatrixTranslation(&matTranslation, g_fPosX, g_fPosY, g_fPosZ); D3DXMatrixRotationX(&matRotationX, D3DXToRadian(g_fAngleX)); D3DXMatrixRotationY(&matRotationY, D3DXToRadian(g_fAngleY)); D3DXMatrixMultiply(&matRotation, &matRotationX, &matRotationY); D3DXMatrixMultiply(&matView, &matTranslation, &matRotation); D3DXMatrixMultiply(&matView, &matViewOld, &matView); g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); The problem is sometimes the camera is upside down. Please help! I want to be able to fly around my scene like Free-Look mode in Counter-Strike game.

Share this post


Link to post
Share on other sites
Advertisement
When your Camera is upside down, you should clip your angle that''s for looking up and down with something like this

if (angle > 90) {angle = 90;}
if (angle <-90) {angle =-90;}

You must adapt that to your situation. I assumed that 0 Degree mean looking straight forward and that you are using Degrees and not Radians, but to figure out that shouldn''t be the problem

Share this post


Link to post
Share on other sites
Thanks for the suggestion, I tried it but it had the same effect when I turned the camera left or right.

I think the Y axis must always up, I mean it should not be rotated around the X axis.

I do not know how to do that.

anyother Idea''s ?

Share this post


Link to post
Share on other sites
  
void Renderer::Set3DTransformations(float *viewangles, float *position) {
D3DXMATRIX matProj, matView, matWorld, rx, ry, rz, t, temp, temp2;

D3DXMatrixRotationX( &rx, viewangles[1] );
D3DXMatrixRotationY( &ry, viewangles[0] );
D3DXMatrixRotationZ( &rz, viewangles[2] );
D3DXMatrixTranslation( &t, -position[0], -position[1], -position[2] );
D3DXMatrixMultiply( &temp, &t, &ry);
D3DXMatrixMultiply( &temp2, &temp, &rx);
D3DXMatrixMultiply( &matView, &temp2, &rz);
m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
}


Take a look at that code, maybe it can help you. The only thing I wonder about is that you save your old transformation and multiply it back. I use this code also for floating a camera in a FirstPersonShooter. But note that it uses Radians and not Degrees.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thank you very much.

Actually I am a webmaster of http://www.CWinApp.com.
It is about game programming tutorials (Visual C++, DirectX 8.0a) in Thai language.

My last tutorial is about how to move the camera like First-Person Shooting (I will post it to my website by this Sunday), you can download source code at:

http://www.cwinapp.com/tutorials/sourcecode/051.zip

And you have to download the following texture files also:

Skybox: http://www.cwinapp.com/tutorials/textures/desert.zip
Train 1: http://www.cwinapp.com/tutorials/textures/train1.zip
Train 2: http://www.cwinapp.com/tutorials/textures/train2.zip
Train Wheel: http://www.cwinapp.com/tutorials/textures/trainwheel.zip
Track: http://www.cwinapp.com/tutorials/textures/track.zip

I am going to make a new tutorial about Free-Look camera that can fly around 3d scene but I do not know how to control y-axis.

Share this post


Link to post
Share on other sites
Thank you very much.

Actually I am a webmaster of http://www.CWinApp.com.
It is about game programming tutorials (Visual C++, DirectX 8.0a) in Thai language.

My last tutorial is about how to move the camera like First-Person Shooting (I will post it to my website by this Sunday), you can download source code at:

http://www.cwinapp.com/tutorials/sourcecode/051.zip

And you have to download the following texture files also:

Skybox: http://www.cwinapp.com/tutorials/textures/desert.zip
Train 1: http://www.cwinapp.com/tutorials/textures/train1.zip
Train 2: http://www.cwinapp.com/tutorials/textures/train2.zip
Train Wheel: http://www.cwinapp.com/tutorials/textures/trainwheel.zip
Track: http://www.cwinapp.com/tutorials/textures/track.zip

I am going to make a new tutorial about Free-Look camera that can fly around 3d scene but I do not know how to control y-axis.

Share this post


Link to post
Share on other sites
Your site looks great to me, me being someone new to D3D. However, I''m afraid that there are very few of us, myself not included, that know the Thai language You wouldn''t happen to have your site in English too, would you?

Share this post


Link to post
Share on other sites

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