JOGL 3D基本形状

在三维物体中, z轴也与x轴和y轴同时存在。这些轴代表物体的高度, 宽度和深度。因此, 它代表了对象的真实视图。
JOGL 3D示例 在此示例中, 我们将创建一个简单的3D对象。
J3DBasic.java

package com.srcmini.jogl; import javax.media.opengl.*; import javax.media.opengl.awt.GLCanvas; import javax.media.opengl.glu.GLU; import javax.swing.JFrame; public class J3DBasic implements GLEventListener {private GLU glu = new GLU(); @Overridepublic void display(GLAutoDrawable drawable) {final GL2 gl = drawable.getGL().getGL2(); gl.glTranslatef(0f, 0f, -3f); gl.glBegin(GL2.GL_LINES); gl.glVertex3f(-1f, 0f, 0); gl.glVertex3f(0f, 1f, 0); gl.glEnd(); //3Dgl.glBegin(GL2.GL_LINES); gl.glVertex3f(-1f, 0f, -2f); gl.glVertex3f(0f, 1f, -2f); gl.glEnd(); //topgl.glBegin(GL2.GL_LINES); gl.glVertex3f(-1f, 0f, 0); gl.glVertex3f(-1f, 0f, -2f); gl.glEnd(); //bottomgl.glBegin(GL2.GL_LINES); gl.glVertex3f(0f, 1f, 0); gl.glVertex3f(0f, 1f, -2f); gl.glEnd(); }@Overridepublic void dispose(GLAutoDrawable arg0) {//method body} @Overridepublic void init(GLAutoDrawable arg0) {// method body}@Overridepublic void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { 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(40.0f, h, 1.5, 18.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }public static void main(String[] args) {final GLProfile gp = GLProfile.get(GLProfile.GL2); GLCapabilities cap = new GLCapabilities(gp); final GLCanvas gc = new GLCanvas(cap); J3DBasic b = new J3DBasic(); gc.addGLEventListener(b); gc.setSize(600, 400); final JFrame frame = new JFrame("JOGL 3D"); frame.getContentPane().add(gc); frame.setSize(frame.getContentPane().getPreferredSize()); frame.setVisible(true); } }

【JOGL 3D基本形状】输出:
JOGL 3D基本形状

文章图片

    推荐阅读