Java 摄像机旋转
和我一样,我设法在opengl和jogl中创建了一个小太阳系:) 现在我想旋转相机,从不同角度显示它。Java 摄像机旋转,java,opengl,jogl,Java,Opengl,Jogl,和我一样,我设法在opengl和jogl中创建了一个小太阳系:) 现在我想旋转相机,从不同角度显示它。 我设法旋转立方体,但它们的运动平面保持不变 GL3 gl=drawable.getGL().getGL3() //定义 public static Mat4 lookAt(Vec4 eye, Vec4 at, Vec4 up) { final Vec4 eyeneg = eye.neg(); final Vec4 n = VectorMath.normalize(eye.su
我设法旋转立方体,但它们的运动平面保持不变 GL3 gl=drawable.getGL().getGL3() //定义
public static Mat4 lookAt(Vec4 eye, Vec4 at, Vec4 up) {
final Vec4 eyeneg = eye.neg();
final Vec4 n = VectorMath.normalize(eye.sub(at));
final Vec4 u = VectorMath.normalize(VectorMath.cross(up, n));
final Vec4 v = VectorMath.normalize(VectorMath.cross(n, u));
final Vec4 t = new Vec4(0, 0, 0, 1);
final Mat4 c = new Mat4(u, v, n, t);
return c.mul(MatrixMath.translate(eyeneg));
}
public static Mat4 lookAt(float x, float y, float z, Vec4 at, Vec4 up) {
final Vec4 eye = new Vec4(x, y, z, 1.0f);
return lookAt(eye, at, up);
}
检查jogl的PMV矩阵
对于摄像机:
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
pmvMatrix.glLoadIdentity();
pmvMatrix.gluPerspective(fov, aspect, zNear, zFar);
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmvMatrix.glLoadIdentity();
pmvMatrix.glRotatef(-pitch, 1, 0, 0);
pmvMatrix.glRotatef(-yaw, 0, 1, 0);
pmvMatrix.glRotatef(-roll, 0, 0, 1);
pmvMatrix.glTranslatef(-position.x, -position.y, -position.z);
pmvMatrix.update();
固定功能:
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadMatrixf(pmvMatrix.glGetPMatrixf());
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadMatrixf(pmvMatrix.glGetMvMatrixf());
着色器:
GLUniformData pmvMatrixUniform;
初始化代码
PMVMatrix pmvMatrix = ...;
state.attachObject("pmvMatrix", pmvMatrix);
pmvMatrixUniform = new GLUniformData("pmvMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
state.ownUniform(pmvMatrixUniform);
state.uniform(gl, pmvMatrixUniform);
显示代码
state.uniform(gl, pmvMatrixUniform);
state.uniform(gl, pmvMatrixUniform);