OpenGL - 向前移动相机

发布于 2024-12-25 23:47:27 字数 515 浏览 5 评论 0原文

下面是我的代码,它可以让我向前移动相机,它工作得很好,但我总是想知道我是否以有效的方式编写代码。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深空失忆 2025-01-01 23:47:27

我认为你的解决方案非常好。我过去曾使用类似的解决方案来解决该问题。我会将 / 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文