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