# 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.

## 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 on other sites
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 functionD3DXMATRIXLookAtLH(  &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!

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013753
×