Я пытаюсь добавить возможность для камеры подниматься и опускаться по оси Y, что в настоящее время не поддерживается.Я попытался добавить к значению Y при нажатии W и или S, но это не работает правильно.Какая формула мне нужна?Я знаю, что это связано с шагом и добавлением к оси Y.
void WALKING_CAMERA::Update(double time)
{
//calculate the distance to move, based on time passed
static double lastTime=time;
double timePassed=time-lastTime;
lastTime=time;
float distance=speed*(float)timePassed/1000;
//Get the mouse position
POINT mPos;
GetCursorPos(&mPos);
angleYaw+=((float)mPos.x-320.0f)*speed/20;
anglePitch+=((float)mPos.y-240.0f)*speed/20;
//make sure angleY is not too great
if(anglePitch>85.0f)
anglePitch=85.0f;
if(anglePitch<-85.0f)
anglePitch=-85.0f;
//set the mouse back to the centre of the screen
SetCursorPos(320,240);
//move forward/back or strafe
if(window.isKeyPressed(VK_UP) || window.isKeyPressed('W'))
{
position.x += (float)sin(angleYaw*M_PI/180)*distance*25;
position.z -= (float)cos(angleYaw*M_PI/180)*distance*25;
}
if(window.isKeyPressed(VK_DOWN) || window.isKeyPressed('S'))
{
position.x -= (float)sin(angleYaw*M_PI/180)*distance*25;
position.z += (float)cos(angleYaw*M_PI/180)*distance*25;
}
if(window.isKeyPressed(VK_RIGHT) || window.isKeyPressed('D'))
{
position.x += (float)cos(angleYaw*M_PI/180)*distance*25;
position.z += (float)sin(angleYaw*M_PI/180)*distance*25;
}
if(window.isKeyPressed(VK_LEFT) || window.isKeyPressed('A'))
{
position.x -= (float)cos(angleYaw*M_PI/180)*distance*25;
position.z -= (float)sin(angleYaw*M_PI/180)*distance*25;
}
}
Спасибо!