关于3d相机类的帮助

Help with 3d camera class

本文关键字:帮助 相机 3d 关于      更新时间:2023-10-16

我正在尝试添加相机在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;

你可能需要反转符号,因为我不确定你的应用程序是使用正值还是负值向上移动。