Jump to content
  • Advertisement
Sign in to follow this  
_mike

Simple Camera

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

I'm very new to Managed DirectX programming, I have drawn a Triangle with one of those many tutorials out there, and I wanted to know how I could, pan the camera left and right up and down. As if you were looking up from above. Top down camera.

Share this post


Link to post
Share on other sites
Advertisement
Well, do you have a function D3DXMatrixLookAtLH anywhere in your code? This is how I position / aim the camera. ( I'm not sure if there are other ways, but maybe so. )

Basically, the function goes like this:


D3DXMATRIXLookAtLH(
D3DXMATRIX * pOut,
CONST D3DXVECTOR3 * pEye,
CONST D3DXVECTOR3 * pAt,
CONST D3DXVECTOR3 * pUp
);



(From MSDN)

pOut is a pointer to a matrix where you want to put the info from this function.
pEye is position of the camera, where it is located.
pAt is the the target of the camera, what point in the world it is looking at.
pUp is a vector that describes which direction is up in your world.

So, by changing pEye and pAt, you can move the camera around.

From top down, your code might look somewhat like this:


D3DXVECTOR3 pos = D3DXVECTOR3( 0.0f, 10.0f. 0.0f ); //We'll place the camera 10 units above the origin.
D3DXVECTOR3 target = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); //We'll have it look at the origin, I assume this is where your triangle is.
D3DXVECTOR3 up = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );

D3DXMATRIX view;

//Now we are ready to use this function
D3DXMATRIXLookAtLH(
&view,
&pos,
&target,
&up );

//Now that we have the information for the camera (view) in a matrix, we set it as the aproppriate transform:

DEVICE->SetTransform( D3DTS_VIEW, &view ); //You should replace DEVICE with YOUR device variable.




You could also try something more advanced one you get the hang of this, like being able to steer around with the mouse and all, but this is a good place to start.

Hope this helps!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!