@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(30.0, (double) width / (double) height, 1.0, 300.0); // 視点位置と視線方向 // glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);//コメントアウト gl.glMatrixMode(GL_MODELVIEW); }
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { final GL2 gl = drawable.getGL().getGL2(); if (height <= 0) height = 1; final float h = (float) width / (float) height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(FOV, h, 1.0, 4000.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl2 = drawable.getGL().getGL2(); GLU glu = GLU.createGLU(); gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl2.glEnable(GL2.GL_DEPTH_TEST); gl2.glDisable(GL2.GL_CULL_FACE); gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); glu.gluPerspective(60, drawable.getSurfaceWidth() / drawable.getSurfaceHeight(), 0.1f, 100); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); camera_.apply(gl2, glu); light_.apply(gl2, glu); terrain_.draw(gl2, glu); Runnable triangle = () -> { gl2.glBegin(GL2.GL_TRIANGLES); { gl2.glColor3f(1, 1, 1); gl2.glNormal3f(0, 0, 1); gl2.glVertex3f(0, 1, 0); gl2.glColor3f(1, 0, 0); gl2.glNormal3f(0, 0, 1); gl2.glVertex3f(-0.87f, -0.5f, 0); gl2.glColor3f(0, 0, 1); gl2.glNormal3f(0, 0, 1); gl2.glVertex3f(0.87f, -0.5f, 0); gl2.glColor3f(1, 1, 1); gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f); gl2.glVertex3f(0, 1, 0); gl2.glColor3f(0, 0, 1); gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f); gl2.glVertex3f(0.87f, -0.5f, 0); gl2.glColor3f(0, 1, 0); gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f); gl2.glVertex3f(0, 0, -0.75f); gl2.glColor3f(1, 0, 0); gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f); gl2.glVertex3f(-0.87f, -0.5f, 0); gl2.glColor3f(1, 1, 1); gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f); gl2.glVertex3f(0, 1, 0); gl2.glColor3f(0, 1, 0); gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f); gl2.glVertex3f(0, 0, -0.75f); gl2.glColor3f(0, 0, 1); gl2.glNormal3f(0, -1.305f, -0.87f); gl2.glVertex3f(0.87f, -0.5f, 0); gl2.glColor3f(1, 0, 0); gl2.glNormal3f(0, -1.305f, -0.87f); gl2.glVertex3f(-0.87f, -0.5f, 0); gl2.glColor3f(0, 1, 0); gl2.glNormal3f(0, -1.305f, -0.87f); gl2.glVertex3f(0, 0, -0.75f); } gl2.glEnd(); }; gl2.glPushMatrix(); { gl2.glPushMatrix(); gl2.glTranslatef(0, 0, 0); gl2.glRotatef(angle__, 0, 1, 0); triangle.run(); gl2.glPopMatrix(); gl2.glPushMatrix(); gl2.glTranslatef(0, 3.2f, 0); gl2.glRotatef(angle__ + 30, 0, 1, 0); triangle.run(); gl2.glPopMatrix(); gl2.glPushMatrix(); gl2.glTranslatef(3.2f, 0, 0); gl2.glRotatef(angle__ + 60, 0, 1, 0); triangle.run(); gl2.glPopMatrix(); } gl2.glPopMatrix(); angle__ += 1; gl2.glPushMatrix(); gl2.glTranslatef(0.05f, -1.5f, 5); gl2.glScalef(0.05f, 0.05f, 0.05f); for (Face face : glock3__.faces) { gl2.glBegin(GL2.GL_POLYGON); for (FaceVertex vertex : face.vertices) { gl2.glColor3f(1, 1, 1); gl2.glNormal3f(vertex.n.x, vertex.n.y, vertex.n.z); gl2.glVertex3f(vertex.v.x, vertex.v.y, vertex.v.z); } gl2.glEnd(); } gl2.glPopMatrix(); }