【问题标题】:OpenGL rotate 3D Cube on own AxisOpenGL在自己的轴上旋转3D立方体
【发布时间】:2016-02-20 08:35:10
【问题描述】:

我有一个 3D 立方体,我想旋转它,但不使用 X、Y、Z 轴。

我想在它自己的轴上旋转立方体。

例如:我从右向左移动我的立方体:我的立方体应该在顶点的左下轴上旋转大约 90 度,而不是在 Z 轴上大约 90 度。

我试过这个:

//prespektive...
gluPerspective(45,1.0,2.0,30.0);
//look at...
gluLookAt(0.0,2.0,  -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
//try to rotate cube on bottom-right-axis
glTranslatef(-(-0.7), 0.40, -(-0.25));
glRotatef(90, 1,0,0);
glRotatef(90, 0,1,0);
glRotatef(90, 0,0,1);
glTranslatef(-0.7, 0.40, -0.25);

但它不起作用。 有什么想法吗?

【问题讨论】:

    标签: c++ opengl 3d rotation cube


    【解决方案1】:

    你为什么破坏投影矩阵。在旋转立方体之前转到MODELVIEW矩阵模式

    // Setup the projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
    gluPerspective(45,1.0,1.0,30.0); // front clip plane to 1.0
    
    // Now go to modelview
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    //look at...
    gluLookAt(0.0,2.0,  -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    //try to rotate cube on bottom-right-axis
    glTranslatef(-(-0.7), 0.40, -(-0.25));
    glRotatef(90, 1,0,0);
    glRotatef(90, 0,1,0);
    glRotatef(90, 0,0,1);
    glTranslatef(-0.7, 0.40, -0.25);
    

    【讨论】:

    • @Roma Kap:我的回答有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2014-04-28
    • 1970-01-01
    • 2014-12-05
    • 2014-05-20
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多