OpenGL - 向前移动相机
下面是我的代码,它可以让我向前移动相机,它工作得很好,但我总是想知道我是否以有效的方式编写代码。
void keyboard (unsigned char key, int x, int y) {
if (key=='w')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad))* 3 ;//move forward and initialise speed
zpos -= float(cos(yrotrad))* 3 ;
ypos -= float(sin(xrotrad))* 3 ;
}
好吧,这个问题刚刚出现在我的脑海中:有谁知道任何好的 OpenGL 碰撞教程吗?在线..如果是的话,如果您分享,我将不胜感激..
感谢您阅读我的问题
Below is my code that lets me to move the camera forward it works fine but i always want to know if I'm writing code in a efficient way..
void keyboard (unsigned char key, int x, int y) {
if (key=='w')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad))* 3 ;//move forward and initialise speed
zpos -= float(cos(yrotrad))* 3 ;
ypos -= float(sin(xrotrad))* 3 ;
}
OK this question just came to my head: Does anyone know any good OpenGL collision tutorials online.. if yes would be more than grateful if u share..
Thanks for reading my question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的解决方案非常好。我过去曾使用类似的解决方案来解决该问题。我会将 / 180 和乘以 PI 组合成一个常数。
Define PI_OVER_180 (3.141459f / 180f)
如果常量表达式由预处理器或编译器执行,这应该保证您不必每次都执行该计算。
I think your solution is pretty good. I've used similar solutions to that problem in the past. I would combine the / 180 and the multiply by PI into a constant.
define PI_OVER_180 (3.141459f / 180f)
This should guarantee you don't have to perform that calculation every time if the constant expression is performed by the preprocessor or compiler.