Jump to content

  • Log In with Google      Sign In   
  • Create Account


Implementing a first person camera: directx10, c++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 R. LeBlanc   Members   -  Reputation: 140

Like
0Likes
Like

Posted 10 November 2012 - 06:37 PM

I have read many different articles on creating a first person camera. Most of them have been xna stuff. I am using c++ and have been going through Frank D. Luna's Directx 10 book. He does not cover first person camera's in that book. Anyway, I want to be able to control the camera with the mouse.

I've read that directInput is deprecated so I'm not using that. Is rawInput what I should be using or is what I have fine for mouse input?

Anyway, here is the section of code dealing with view transformations etc in relation to the camera. Everything else in the program works fine. It's taken directly from Luna's crate example and I'm just changing the view functionality. I believe once I get the rotation part figured out moving the camera around should be relatively easy.

GetCursorPos(&curMousePoint);
int xCenter = (int)mClientWidth/2 + mWinPosX;
int yCenter = (int)mClientHeight/2 + mWinPosY;
D3DXVECTOR3 lUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f); //local up vector
D3DXVECTOR3 lDir = D3DXVECTOR3(0.0f, 0.0f, 1.0f); //local direction vector

if(curMousePoint.x != xCenter)
{
  deltaX += (curMousePoint.x - xCenter)/500.0f;

  //Yaw (around y axis)
  D3DXMATRIX yRotMatrix;
  D3DXMatrixRotationY(&yRotMatrix, deltaX);
  D3DXVec3TransformCoord(&wDir, &lDir, &yRotMatrix); //wDir is world direction vector
}
if( curMousePoint.y != yCenter)
{
  deltaY += (curMousePoint.y - yCenter)/500.0f;
  //Pitch (around x axis)
  //D3DXMATRIX xRotMatrix;
  //D3DXMatrixRotationX(&xRotMatrix, deltaY);
  //D3DXVec3TransformCoord(&wUp, &lUp, &xRotMatrix);	//wUp is world up vector
}
target = mEyePos + wDir; //Should point in direction of target
D3DXMatrixLookAtLH(&mView, &mEyePos, &target, &lUp);

SetCursorPos((int)mClientWidth/2 + mWinPosX, (int)mClientHeight/2 + mWinPosY);

I haven't worried about over rotating yet.

What I would like to know is: is this along the right track? What should be changed?

I have the pitch portion commented out for simplicity

Sponsor:

#2 Such1   Members   -  Reputation: 435

Like
0Likes
Like

Posted 11 November 2012 - 01:57 AM

Yeah, you are on the right track.
My camera code is structured like this:
cameraLookAt;//Set to the position you want your camera to point at(probably your characters head or something like that)
cameraPosition = D3DXVECTOR3(0, 0, -distance);//change distance to the distance between the camera target and the camera
//now rotate cameraPosition using deltaY and deltaX
than:
cameraPosition += cameraLookAt;

Edited by Such1, 11 November 2012 - 01:58 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS