OpenGL中的FPS相机

时间:2018-09-05 06:53:54

标签: android opengl-es

我对opengl很陌生,我正在尝试将其用于我的android应用程序。我创建了一个相机类,并且能够打开Y轴(偏航),但是仍然找不到打开Z和X轴的方法。有帮助吗?

import android.opengl.GLU;

import javax.microedition.khronos.opengles.GL10;

public class Camera
{
    private Vertex3f _position = new Vertex3f(-20.0f,2.0f,0.0f);
    private Vertex3f _rotation = new Vertex3f(0.0f,0.0f,0.0f);

    public Camera()
    {

    }

    public void updateCamera(GL10 gl)
    {
        // UP Y
        GLU.gluLookAt(gl,
                this._position.x,
                this._position.y,
                this._position.z,
                this._position.x+(float) Math.cos(Math.toRadians(_rotation.y)),
                this._position.y,
                this._position.z+(float) Math.sin(Math.toRadians(_rotation.y)),
                0.0f,
                1.0f,
                0.0f);

    }

    public void set_position(Vertex3f _position) {
        this._position = _position;
    }

    public Vertex3f get_position() {
        return _position;
    }

    public void set_rotation(Vertex3f _rotation) {
        this._rotation = _rotation;
    }

    public Vertex3f get_rotation() {
        return _rotation;
    }

}

并进行相机更新:

@Override
public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT
            | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    camera.updateCamera(gl);
    mCubeOpenGL.draw(gl);

}

用于发送横摆偏航:

public void orientationUpdate(double pitch,double roll,double yaw){
    camera.set_rotation(new Vector3((float) roll, (float) yaw,(float) pitch));
}

0 个答案:

没有答案