首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >想要旋转我的立方体。我怎么能这样做呢?

想要旋转我的立方体。我怎么能这样做呢?
EN

Stack Overflow用户
提问于 2014-02-27 19:12:40
回答 1查看 59关注 0票数 0

我想旋转我的立方体,并添加4个按钮,以加快速度,向下移动,向上移动和向下移动。你能帮我一下吗?颜色是黄色的。cube.cube下的4个按钮应围绕y轴旋转。

代码语言:javascript
复制
public class MyGLRenderer implements Renderer {
Context context; 


Cube cube;

public MyGLRenderer(Context context) {

    this.context = context;


    cube = new Cube();
}

// Call back when the surface is first created or re-created
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // clear-value for color and depth, enabling depth-test, etc.
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set color's clear-value to black
}

// Call back after onSurfaceCreated() or whenever the window's size changes
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0)
        height = 1;
    float aspect = (float) width / height;

    // Set the viewport (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Select projection matrix: projection matrix or model-view matrix
    gl.glMatrixMode(GL10.GL_PROJECTION);
    // Reset projection matrix
    gl.glLoadIdentity();

    GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.f);

    // Select model-view matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    // Reset
    gl.glLoadIdentity();

}

// Call back to draw the current frame.
@Override
public void onDrawFrame(GL10 gl) {
    // Clear color and depth buffers using clear-value set earlier
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // Reset model-view matrix
    gl.glLoadIdentity();
    // Translate into the screen
    gl.glTranslatef(0.0f, 0.0f, -5.0f); 


    // Draw cube
    cube.draw(gl);
}

}

EN

回答 1

Stack Overflow用户

发布于 2014-02-27 19:36:03

这就是你要找的:https://www.opengl.org/sdk/docs/man2/xhtml/glRotate.xml,你必须把它放在glTranslatef前面

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22066758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档