Sign in to follow this  
ahmetay

Problem with virtual camera - solving maze with virtual camera

Recommended Posts

Hi friends, in my project, I have to get out of the maze, I have to solve the maze using directx with virtual camera. For this, I have a generic camera class, that moves forward - backward, left- right etc. To move camera forward, I just change the camera's 'z' position. But it does not give the movement effect. For example, pressing the 'up' key, I want to move the camera forward. My camera class's render function is below: void Camera::render(LPDIRECT3DDEVICE9 & device) { D3DXMATRIX matView; // the view transform matrix D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (camX, camY, camZ), // the camera position &D3DXVECTOR3 (lookAtX, lookAtY, lookAtZ), // the look-at position &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction device->SetTransform(D3DTS_VIEW, &matView); // set the view transform to matView D3DXMATRIX matProjection; // the projection transform matrix D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(60), // the horizontal field of view 640 / 480, // the aspect ratio 1.0f, // the near view-plane 100.0f); // the far view-plane device->SetTransform(D3DTS_PROJECTION, &matProjection); // set the projection return; } Everything is performed by the function D3DXMatrixLookAtLH(). camX, camY, camZ, and lookAtX, lookAtY, lookAtZ are static private members of camera class. When pressing the up key, I call the code block: if (KEY_DOWN(VK_UP)) { cam->setCamZ(z+=0.5); } I just change the camera's z position. Is this enough to move the camera forward. When I do this, the camera dooes not give the moving forward effect. Using 6 variables, camX, camY, camZ, and lookAtX, lookAtY, lookAtZ , how can I move the camera and how to solve the maze. Thanks a lot. I realy, realy need your replies friends. thanks.

Share this post


Link to post
Share on other sites
thanks. I tried the LookAtZ position. but to move the camera ahead, is it enough JUST change LookAt Z position? When I did this, I did not take moving ahead effect. If you explain, I will be very gratefull.

Share this post


Link to post
Share on other sites
Changing the camera position and the lookat point should be sufficient.

For your purposes right now, pos.z += 0.5f and lookAt.z += 0.5f should work, assuming you don't change the world matrix and the lookAt vector is correct to begin with.

Share this post


Link to post
Share on other sites
In the project, I draw the maze and move the camera at the same time.

To begin with, I set the D3DXMatrixLookAtLH's parameters in constructor to,
float Camera::camX=-1;
float Camera::camY=-2;
float Camera::camZ=3;
float Camera::lookAtX=-1;
float Camera::lookAtY=-1;
float Camera::lookAtZ=-1;

and maze's initial coordinates are x=-2,y=-2,z=0 to the function D3DXCreateBox with D3DXMatrixTranslation() function.

Are these initial parameters correct?
When I run it, it does not draw the maze.

thanks.

Share this post


Link to post
Share on other sites
thanks for your help Buckeye. I am new to directx, not expert in directx for this reason i asked so.
i searched the google and i found what i need.
For those who need basic camera and basic directx codes, refer to http://www.two-kings.de/download.html.

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