Sign in to follow this  

DirectX camera help [resolved]

Recommended Posts

This is my first time on these boards, so hello all! I am a DirectX noob, so plz bare with me :P Anyway, I am basically making a 2D pathfinding project and I want to be able to zoom in and out along the z-axis, depending on the size of the map loaded. I have learned the basics of displaying sprites, but haven't touched anything with the camera as of yet... So from a few hours of searching this is all I've been able to come up with. I am putting this code in my initilization function of DirectX. I assume that this is setting up camera to look along the z-axis?
    D3DXVECTOR3 vEyePt( 0.0f, 0.0f,-5.0f );
    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

And, then in my rendering function (I guess just to see if I can make the camera change) I have this
    D3DXMATRIX matView;
    D3DXMATRIX matTrans;

    D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, -5.0f );
    matView = matTrans;
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

This doesn't change anything :( I know this is probably really simple, but any help for a noob would be greatly appreciated! [Edited by - Sk1d_Row on October 22, 2005 7:18:43 PM]

Share this post

Link to post
Share on other sites
You mention sprites, so I'm assuming you're using the ID3DXSPRITE interface. If so, this interface does not use the Transformation matrices that DX uses on 3D world objects. The sprite interface uses it's own matrices, allowing it to draw in 2D quite easily. If you insist, you could pass the OBJECTSPACE flag in Sprite->Begin(), but this is overcomplicating things.

The easiest way to scale your whole world (zoom in/out) would be to use a transformation matrix.

Use only a Scaling matrix, and pass it to Sprite->SetTransform() before drawing. This will scale everything you draw with the interface using the matrix you supply.

Also note, that in 2D, translating along the z axis makes no difference in size, so moving the sprite along the z axis with the sprite interface won't make it smaller...

Hope this helps.

Share this post

Link to post
Share on other sites
That cleared up a ton thank you very much! I got scaling to work! Now I just gotta figure out the formula for scaling to the screen height and width, but I am sure I can find that somewhere.

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