# RTS camera question

This topic is 5192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites

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

pDevice->SetTransform(D3DTS_VIEW, &matrix);

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22