I am literally doing what the name of the thread says which is testing for different conditions. I am just wondering if this will hurt me down the road if I'm not careful about my use of if statements and stuff (on top of having to execute a ridiculous amount of math for each entity that has view, up and strafe vectors)
It is quite a bit of code
EDIT:
and I did not know of that site, thanks!
Code:
void Player::CheckMouse() {
char asdf[50];
static float MiddleX = SCREEN_WIDTH / 2;
static float MiddleY = SCREEN_HEIGHT / 2;
char test[128];
POINT MousePos;
GetCursorPos(&MousePos);
SetCursorPos(MiddleX, MiddleY);
if(MousePos.x == MiddleX && MousePos.y == MiddleY) //if there is no change align spaceship
{
//ZShipRotation is rotation ABOUT Z Axis
if(ZShipRotation > 0)
ZShipRotation -= ZRightSpeed;
if(ZShipRotation < 0)
ZShipRotation += ZRightSpeed;
//when in positive clamping zone
//XShipRotation is rotation ABOUT X Axis
if(XShipRotation > 0 && XShipRotation < XRightSpeed)
//XShipRotation -= (.1*XShipRotation);
XShipRotation = 0;
else
if(XShipRotation > 0 )
XShipRotation -= XRightSpeed;
if(XShipRotation < 0 && XShipRotation > -XRightSpeed)
// XShipRotation += (.1*XShipRotation);
XShipRotation = 0;
else
if(XShipRotation < 0 )
XShipRotation += XRightSpeed;
//sprintf(test, "zship rotation: %d", (int)ZShipRotation);
//SetWindowText(hWnd, test);
return;
}
Rotating = true;
float YDeviation = (MiddleY - MousePos.y);
float XDeviation = (MiddleX - MousePos.x);
if(XDeviation) //if Deviated left/right
HorizChange = true;
else
HorizChange = false;
/*
X / MaxZ = XDeviation / ScreenWidth
MaxZ * XDeviation = X * ScreenWidth
X = (MaxZ * XDeviation) / ScreenWidth
X / MaxX = YDeviation / SCREENHEIGHT
MaxX * YDeviation = X * SCREENHEIGHT
X = (MaxX * YDeviation) / SCREENHEIGHT
*/
if(ZShipRotation > -MaxZRotation && ZShipRotation < MaxZRotation) { //if we haven't reached the limit about Z
if( (ZShipRotation > 0 && XDeviation < 0) || (ZShipRotation < 0 && XDeviation > 0) )
ZShipRotation += 2*((MaxZRotation * XDeviation) / SCREEN_WIDTH) * ZRotateSpeed; //double time it because actual rotation and deviation
else //have different signs
ZShipRotation += (MaxZRotation * XDeviation) / SCREEN_WIDTH;
}
if(XShipRotation > -MaxXRotation && XShipRotation < MaxXRotation) { //if we haven't reached the limit about X
if( (XShipRotation > 0 && XDeviation < 0) || (XShipRotation < 0 && XDeviation > 0) )
XShipRotation += 2*((MaxXRotation * YDeviation) / SCREEN_HEIGHT) * XRotateSpeed;
else
XShipRotation += (MaxXRotation * YDeviation) / SCREEN_HEIGHT;
}
// sprintf(test, "zship rotation: %d", (int)ZShipRotation);
// SetWindowText(hWnd, test);
//XDegRad is how far to rotate ABOUT the x axis
//YDegRad is how far to rotate ABOUT the y axis
float XDegRad = ((2 * PI) * YDeviation) / SCREEN_WIDTH; //radians to rotate vector
float YDegRad = ((2 * PI) * XDeviation) / SCREEN_WIDTH;
float cosXTheta = (float)cos(XDegRad);
float sinXTheta = (float)sin(XDegRad);
float cosYTheta = (float)cos(YDegRad);
float sinYTheta = (float)sin(YDegRad);
//YRotation is how far to rotate ABOUT the y axis
//XRotation is how far to rotate ABOUT the x axis
YRotation += ((360 * XDeviation) / SCREEN_WIDTH);
XRotation += ((360 * YDeviation) / SCREEN_WIDTH);
Locked = false;
if(XRotation >= 57.3) {
XRotation = 57.3;
XDegRad = 0;
Locked = true;
}
if(XRotation <= -57.3) {
XRotation = -57.3;
XDegRad = 0;
Locked = true;
}
//calculate strafe vector
Strafe = CrossProduct(View - Position, Up);
Strafe.Normalize();
//rotate camera position
Vector tempCamPos = CamPos - Position;
RotateVector(XDegRad, Strafe, tempCamPos);
RotateVector(YDegRad, YAxis, tempCamPos);
CamPos = tempCamPos + Position;
// update Up vector
RotateVector(XDegRad, Strafe, Up);
RotateVector(YDegRad, YAxis, Up);
//update View vector
RotateView(XDegRad, Strafe);
RotateView(YDegRad, YAxis);
}