3D RTS camera , how?

Started by
3 comments, last by evanofsky 18 years, 8 months ago
how to implement a 3D rts camera?.. what i mean is when i move my cursor to the edge of the screen the camera position also moves.. how to do it? right now what i have done is to move the camera to the right if the mouse cursor is x<=0 or x>= window width using the right vector of the camera(that is the cross prod of the forward and the up vector).. but i dont knw how to move the camera position when the mouse move vertically, is this correct or theres another way of doing this? what are the correct way of doing this..? pls enlighten me thanks
Advertisement
Use standard "trigonometry" - math. :)

sin for Y (or Z) and cos for X...

use gluLookAy to position the camera... move target and camera position simultaniously...


p.s I would give you some sourcecode, but my computer is not in my possession for the moment... cheers!
"Game Maker For Life, probably never professional thou." =)
oh, and you need a yaw (direction) angle for the camera, preferably a pitch too..
"Game Maker For Life, probably never professional thou." =)
I'm not sure if this is the "correct" way or even a good way but I guess you can get the direction by taking cross product of the right camera vector and the world up vector (probably y-axis unit vector).

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

I hope you're using DirectX... otherwise I can't help you, so here goes.

You have the right idea with testing whether the mouse is at the edge of the screen, but once you've figured out which direction to move it in, it gets a little harder.

Let's say you want to move to the right. You make a vector in global space that points to the right, like this:
D3DXVECTOR3 toTheRight(1.0f, 0.0f, 0.0f);

Okay, so now all you have to do is add that vector to the camera's position, right? That's only if the camera isn't rotated at all. (this is assuming your game supports camera rotation) Let's say it's rotated 45 degrees to the left. This is real easy, it doesn't involve any math.

Just multiply the "toTheRight" vector by the camera's rotation matrix, like this:
D3DXVec3TransformCoord(&toTheRight, &toTheRight, &cameraRotationMatrix);

This makes the "toTheRight" vector point to the right relative to the camera.

Have fun!

This topic is closed to new replies.

Advertisement