Class GLModel

java.lang.Object
  |
  +--GLModel

public class GLModel
extends java.lang.Object

Store and render a textured mesh. Can load 3DS and OBJ formats.

NOTE: OBJ doesn't load texture coords. Need to debug.

Uses the IDX3D library to load and hold 3DS meshes. See http://www.idx3d.ch for the complete pure-java 3D library by Peter Walser.

napier at potatoland dot org


Field Summary
static int SIZE_BYTE
           
static int SIZE_DOUBLE
           
static int SIZE_FLOAT
           
static int SIZE_INT
           
static float tileFactorHoriz
           
static float tileFactorVert
           
 
Constructor Summary
GLModel()
           
GLModel(java.lang.String filename)
           
 
Method Summary
 void calculateNormals()
           
 void commitChanges()
           
static java.io.InputStream getInputStream(java.lang.String filename)
          Open a file InputStream and trap errors.
 void loadMesh(java.lang.String filename)
           
 void makeDisplayList()
          Compile the mesh into display list
 void render()
          Draw this mesh with current texture
static void renderCube()
          Render a unit cube, using current color, texture and material.
static void renderMesh(idx3d_Object o)
          Basic mesh render function, using current color, material and texture.
static void renderMesh(idx3d_Object o, int textureHandle)
          Render a mesh with the given texture.
static void renderMeshOBJ(idx3d_Object o, int textureHandle)
          Render OBJ mesh (may have multiple texture coords per vert!!??!!)
static void renderSphere()
          Render a unit sphere at the origin, using current color, texture and material.
 void rotate(float dx, float dy, float dz)
           
 void scale(float dx, float dy, float dz)
          Functions to alter mesh size, position, orientation.
 void setTexture(int textureHandle)
          Set texture for mesh.
 void setTextureTile(float horizontalTile, float verticalTile)
          How many times to repeat texture horizontally and vertically.
 void sortTriangles()
           
static idx3d_Triangle[] sortTriangles(idx3d_Triangle[] tri, int L, int R)
          Sort an array of triangles by Z depth.
 void translate(float dx, float dy, float dz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_DOUBLE

public static final int SIZE_DOUBLE
See Also:
Constant Field Values

SIZE_FLOAT

public static final int SIZE_FLOAT
See Also:
Constant Field Values

SIZE_INT

public static final int SIZE_INT
See Also:
Constant Field Values

SIZE_BYTE

public static final int SIZE_BYTE
See Also:
Constant Field Values

tileFactorVert

public static float tileFactorVert

tileFactorHoriz

public static float tileFactorHoriz
Constructor Detail

GLModel

public GLModel()

GLModel

public GLModel(java.lang.String filename)
Method Detail

loadMesh

public void loadMesh(java.lang.String filename)

scale

public void scale(float dx,
                  float dy,
                  float dz)
Functions to alter mesh size, position, orientation. Not to be confused with glRotate() glScale() glTranslate(). These functions operate on the mesh data, not the coordinate system. They can be used to modify a mesh permanently (see commitChanges()) so that the changes will be "baked in" to the mesh.


translate

public void translate(float dx,
                      float dy,
                      float dz)

rotate

public void rotate(float dx,
                   float dy,
                   float dz)

commitChanges

public void commitChanges()

setTextureTile

public void setTextureTile(float horizontalTile,
                           float verticalTile)
How many times to repeat texture horizontally and vertically.


setTexture

public void setTexture(int textureHandle)
Set texture for mesh.


render

public void render()
Draw this mesh with current texture


makeDisplayList

public void makeDisplayList()
Compile the mesh into display list


calculateNormals

public void calculateNormals()

sortTriangles

public void sortTriangles()

renderMesh

public static void renderMesh(idx3d_Object o,
                              int textureHandle)
Render a mesh with the given texture.
Must include these lines in init() for textures to appear:
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);

Parameters:
o -
textureHandle -

renderMesh

public static void renderMesh(idx3d_Object o)
Basic mesh render function, using current color, material and texture.

Parameters:
o -

renderMeshOBJ

public static void renderMeshOBJ(idx3d_Object o,
                                 int textureHandle)
Render OBJ mesh (may have multiple texture coords per vert!!??!!)

Parameters:
o -

sortTriangles

public static idx3d_Triangle[] sortTriangles(idx3d_Triangle[] tri,
                                             int L,
                                             int R)
Sort an array of triangles by Z depth. Before sorting, some routine has to set triangle.dist (average Z depth of triangle) for all triangles. Triangle Z depth will change as viewpoint/mesh move.

To use: sortTriangles(triangleArray, 0, triangleArray.length-1);


renderCube

public static void renderCube()
Render a unit cube, using current color, texture and material.


renderSphere

public static void renderSphere()
Render a unit sphere at the origin, using current color, texture and material.


getInputStream

public static java.io.InputStream getInputStream(java.lang.String filename)
Open a file InputStream and trap errors.

Returns: