关于3d相机类的帮助
Help with 3d camera class
我正在尝试添加相机在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;
你可能需要反转符号,因为我不确定你的应用程序是使用正值还是负值向上移动。
相关文章:
- 需要帮助设置在C++中使用的Potrace
- 了解 GLM- openGL 中的相机转换
- 在指针的帮助下,文本文件中单词的频率
- 计算每个节点的树高,帮助我解释这个代码解决方案
- OpenGL相机和相机空间转型的困惑
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 需要帮助将结构数组传递给函数
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 有人可以帮助我处理正则表达式吗?
- C++调用具有 *this 属性的单个帮助程序函数
- C++:需要帮助了解运算符重载错误
- 通过 API 控制 DJI 相机
- 需要以下代码的帮助,下面的代码有什么问题
- 将相机数据从服务器实时流式传输到客户端
- CS1 项目帮助C++
- 用于检查值是否为其任何参数的帮助程序函数
- 需要帮助在OpenGL中移动相机
- 关于3d相机类的帮助