如何解决帮助3D摄像机类
| 我正在尝试增加相机在Y轴上上下移动的功能,这是它当前不支持的功能。我试过在按下W和S时将Y值相加,但无法正常工作。我需要哪种配方?我知道这与间距和添加到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;
}
}
谢谢!
解决方法
为了向前移动,应该执行以下操作:
position.y += (float)sin(anglePitch * M_PI / 180) * distance * 25;
您可能需要反转符号,因为我不确定您的应用程序是使用正Y还是负Y值进行向上移动。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。