RTS camera movement

This is a discussion on RTS camera movement within the C++ Programming forums, part of the General Programming Boards category; Alright, so in my last post I was busy fixing one aspect of my RTS camera, the looking-feature. In this ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    27

    RTS camera movement

    Alright, so in my last post I was busy fixing one aspect of my RTS camera, the looking-feature. In this one I'm busy trying to get the basic RTS camera movement, either the standard move to the side of the screen, or the standard (introduced in C&C tib sun) hold the right mouse button, and move mouse in the direction and it'll keep going in that direction based on how far you moved the mouse, and until you let go.
    Here's what I got right now.
    Code:
    	//Created by Erich Ulmer, Camera looks at mouse when pressing alt, else moves camera with mouse movements
    
    		if (GetAsyncKeyState(VK_MENU)&0x8000)
    		{
    		//move camera target around camera position
    		}	
    		else if (GetAsyncKeyState(VK_RBUTTON)&0x8000)
    		{
                    //Currently moves camera directly proportional and constant to when and how far you move the mouse
    for reference, Rh = rotation horizontal I.E. what degree the camera is facing towards
    			posCameraX -= ((gDInput->mouseDY()*sinf(Rh))-(gDInput->mouseDX()*sinf(Rh+(D3DX_PI/2))))/50.0f;
    			tarCameraX -= ((gDInput->mouseDY()*sinf(Rh))-(gDInput->mouseDX()*sinf(Rh+(D3DX_PI/2))))/50.0f;
    			posCameraZ -= ((gDInput->mouseDY()*cosf(Rh))-(gDInput->mouseDX()*cosf(Rh+(D3DX_PI/2))))/50.0f;
    			tarCameraZ -= ((gDInput->mouseDY()*cosf(Rh))-(gDInput->mouseDX()*cosf(Rh+(D3DX_PI/2))))/50.0f;
    		}
    The code highlighted in red (if the comment didnt' explain well enough) currently moves the camera when you move the mouse, a physical movement forward or backward, side to side, (or any combination of which).
    What i'm looking for would either be a good tutorial for C++/Direct3D 9.0c (haven't been able to find one, don't bash, I've been looking! ) OR for someone to help me modify my code to have a constant input based on the above, but continuing to move the camera in that direction while the button is held, rather than only moving it when you move the mouse. I assume this means I should find some relationship to where the mouse started, and where it is "currently" at, but the algorithm eludes me. If this has to be called every frame, how can I do this?

    Standard RTS Camera - I would simply find the current cursor position, and then if it is in a certain value range, maybe get the ratio of those values to eachother and base that as another angle to compare to Rh functions. This is frankly just a little more confusing than I expected it to be. I thought I had taken care of the harder camera type first, but this has had me held up a little bit and on the look out.

    Right Button Style Camera - I thought of maybe setting a value when the second if statement is called the first time each time, and then it would save the coordinates, and then after that compare coordinates and base speed and direction of camera movement on that. (And to reset that value would be to have it reset in the initial if statement for the other camera mode, or to have it set on button release or something). Even so, I still need a way through direct3d/windows to find the current cursor position (should just be some function out there?) and compare to the next one.

    Personally I'd rather have help with option B, and an opinion on it, but help or guidance on either, including critizism of the algorithm is very welcome.

    p.s. I know my code isn't optimized for performance yet, I plan on reducing the redundency of the code, by simply making the value calculate once per frame, and send it to the places it needs to be, instead of calculating it 2-4 times each. However I might not even have similar code after all this, so we'll just see where this takes me


    Thanks again for input/help!
    Erich
    Last edited by blurrymadness; 04-22-2007 at 10:40 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  2. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  3. Problems moving the camera
    By Mavix in forum Game Programming
    Replies: 8
    Last Post: 01-30-2008, 11:52 AM
  4. OGL camera movement and vector trouble
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 05-12-2004, 05:33 PM
  5. Camera rotation/movement in 3D world
    By tegwin in forum Game Programming
    Replies: 11
    Last Post: 01-24-2003, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21