Free-Look Camera Mode in Counter-Strike
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.
When your Camera is upside down, you should clip your angle that''s for looking up and down with something like this
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
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
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 ?
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 ?
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.
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.
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.
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.
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.
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement