Rings
Version 0.3

threeD.raytracer.primitives
Class Mesh

java.lang.Object
  extended bythreeD.raytracer.engine.AbstractSurface
      extended bythreeD.raytracer.engine.SurfaceGroup
          extended bythreeD.raytracer.primitives.Mesh
All Implemented Interfaces:
Surface

public class Mesh
extends SurfaceGroup

A Mesh object stores a set of points (Vector objects) and allows triangles to be specified using those points.


Nested Class Summary
protected static class Mesh.Vertex
           
 
Constructor Summary
Mesh()
          Constructs a new Mesh object.
Mesh(Vector[] points, int[][] triangles)
          Constructs a new Mesh object.
 
Method Summary
 void addSurface(Surface s)
          Adds the specified Surface object to the list of triangles stored by this Mesh object.
 int addTriangle(int p1, int p2, int p3)
          Adds the triangle described by the specified points to the mesh represented by this Mesh object.
 int addVector(Vector p)
          Adds the point defined by the specified Vector object to the mesh represented by this Mesh object.
 Vector getNormalAt(Vector point)
          Returns null.
 Surface getSurface(int index)
          Returns the Surface object stored by this SurfaceGroup object at the specified index.
 Surface[] getSurfaces()
          Returns the Surface objects stored by this SurfaceGroup object as a Surface array.
 Triangle[] getTriangles()
           
 Mesh.Vertex[] getVectors()
           
 boolean intersect(Ray ray)
          Returns true if the ray represented by the specified Ray object intersects any of the surfaces represented by this SurfaceGroup object.
 Intersection intersectAt(Ray ray)
          Returns an Intersection object that represents the ray-surface intersections for the AbstractSurface object which is intersected closest to the origin of the ray (>= 0).
 void removeSurface(int index)
          Removes the Triangle object stored by this Mesh object at the specified index.
 void setSmooth(boolean smooth)
          Sets the smooth flag for each Triangle object stored by this Mesh object.
 void setSurfaces(Surface[] surfaces)
          Does nothing.
 
Methods inherited from class threeD.raytracer.engine.SurfaceGroup
shade
 
Methods inherited from class threeD.raytracer.engine.AbstractSurface
addShader, addTexture, addTransform, calculateTransform, getColor, getColorAt, getLocation, getParent, getRotationCoefficients, getScaleCoefficients, getShadeBack, getShadeFront, getShaderSet, getSize, getTexture, getTextures, getTextureSet, getTransform, getTransform, getTransforms, removeTexture, removeTransform, setColor, setLocation, setParent, setRotationCoefficients, setScaleCoefficients, setShadeBack, setShadeFront, setShaders, setSize, setTexture, setTextures, setTransform, setTransforms
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mesh

public Mesh()
Constructs a new Mesh object.


Mesh

public Mesh(Vector[] points,
            int[][] triangles)
Constructs a new Mesh object.

Parameters:
points - Array of points to use.
triangles - {{x0, y0, z0}, {x1, y1, z1},...} Where the int values are indices in the points array.
Method Detail

addVector

public int addVector(Vector p)
Adds the point defined by the specified Vector object to the mesh represented by this Mesh object.

Parameters:
p - Vector object to add.
Returns:
The unique index of the point to be used when adding triangles.

addTriangle

public int addTriangle(int p1,
                       int p2,
                       int p3)
Adds the triangle described by the specified points to the mesh represented by this Mesh object.

Parameters:
p1 - Index of first point.
p2 - Index of second point.
p3 - Index of third point.
Returns:
The unique index of the triangle added or -1 if it is not added (if any point indicies are the same).
Throws:
java.lang.IllegalArgumentException - if any of the indicies specified are not valid.

getVectors

public Mesh.Vertex[] getVectors()
Returns:
An array of Mesh.Vertex objects stored by this Mesh object.

getTriangles

public Triangle[] getTriangles()
Returns:
An array of Triangle objects stored by this Mesh object.

getNormalAt

public Vector getNormalAt(Vector point)
Description copied from class: SurfaceGroup
Returns null.

Specified by:
getNormalAt in interface Surface
Overrides:
getNormalAt in class SurfaceGroup
Returns:
null.

setSmooth

public void setSmooth(boolean smooth)
Sets the smooth flag for each Triangle object stored by this Mesh object.

Parameters:
smooth - Boolean flag to use.

intersect

public boolean intersect(Ray ray)
Description copied from class: SurfaceGroup
Returns true if the ray represented by the specified Ray object intersects any of the surfaces represented by this SurfaceGroup object.

Specified by:
intersect in interface Surface
Overrides:
intersect in class SurfaceGroup
See Also:
Surface.intersect(threeD.raytracer.engine.Ray)

intersectAt

public Intersection intersectAt(Ray ray)
Description copied from class: SurfaceGroup
Returns an Intersection object that represents the ray-surface intersections for the AbstractSurface object which is intersected closest to the origin of the ray (>= 0). If there is no intersection >= 0 along the ray, null is returned.

Specified by:
intersectAt in interface Surface
Overrides:
intersectAt in class SurfaceGroup
See Also:
Surface.intersectAt(threeD.raytracer.engine.Ray)

setSurfaces

public void setSurfaces(Surface[] surfaces)
Does nothing.

Overrides:
setSurfaces in class SurfaceGroup

addSurface

public void addSurface(Surface s)
Adds the specified Surface object to the list of triangles stored by this Mesh object. This method should not be used to add triangles that will share verticies, because that can be done more efficiently with the addVector and addTriangle methods.

Overrides:
addSurface in class SurfaceGroup
Throws:
java.lang.IllegalArgumentException - If the specified Surface object is not a Triangle object.

removeSurface

public void removeSurface(int index)
Removes the Triangle object stored by this Mesh object at the specified index.

Overrides:
removeSurface in class SurfaceGroup

getSurfaces

public Surface[] getSurfaces()
Description copied from class: SurfaceGroup
Returns the Surface objects stored by this SurfaceGroup object as a Surface array.

Overrides:
getSurfaces in class SurfaceGroup
Returns:
An array of Surface objects containing the Triangle objects stored by this Mesh object.

getSurface

public Surface getSurface(int index)
Description copied from class: SurfaceGroup
Returns the Surface object stored by this SurfaceGroup object at the specified index.

Overrides:
getSurface in class SurfaceGroup
Returns:
The Triangle object stored by this Mesh object with the specified index.

Rings
Version 0.3

Copyright 2003-05 Mike Murray