Jump to content
  • Advertisement
Sign in to follow this  
be17_17y

RTS camera question

This topic is 4887 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 want camera like in real time strategy games..... 1.how to positioning the camera like that ? and 2.how to make camera rotate based on world Y coordinate or position where we focusing like character pos. or ..., it's like in game "Age of Mythology", if the camere is facing a tree, if i use mouse scroll, the camera will move around that tree (in circle movement with the tree as center) and keep facing that tree..... help me please.......

Share this post


Link to post
Share on other sites
Advertisement

First you define a position of the camera and its orientation (that is what it's looking at and the up vector)
Just position it above the worldmap and point it towards the map.
When you want to rotate: determine the point your looking at and the camera's position and then rotate around that line.
When you want to change the pitch rotate around the right or left vector of the camera.

Cheers

Share this post


Link to post
Share on other sites
The functions you may use to do this are:

D3DXMATRIX matrix;
D3DXMatrixIdentity(&matrix);
D3DXMatrixRotationX(&matrix, xAngle);
D3DXMatrixRotationY(&matrix, yAngle);
D3DXMatrixRotationZ(&matrix, zAngle);
D3DXMatrixTranslation(...);
D3DXMatrixScaling(...);

The simpler method:
D3DXVECTOR3 eyeVec(0.0f, 1.0f, -1.0f);
D3DXVECTOR3 lookAtVec(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 upVec(0.0f, 1.0f, 0.0f);

D3DXMatrixLookAtLH(&matrix, &eyeVec, &lookAtVec, &upVec);

This sets your eye vector at 1 up and 1 back, your look at the origin, and up is the y axis. You can move the lookAt and eye vectors to change where you are and what your'e looking at.

Then set your transform.
pDevice->SetTransform(D3DTS_VIEW, &matrix);

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!