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

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

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

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×