Sign in to follow this  
yuppies

3D RTS camera , how?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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!

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