CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.geom3d
Class Shape3D

java.lang.Object
  extended by ch.randelshofer.geom3d.Shape3D
All Implemented Interfaces:
Node3D

public class Shape3D
extends java.lang.Object
implements Node3D

Represents a 3 dimensional shape consisting of an arbitrary number of planar and convex vertices.

Version:
3.1 2010-01-04 Added method getFillColor.
3.0 2009-01-03 Reuse array of transformed coordinates between calls to addVisibleFacesTo(). Store face actions in Face3D rather than in this object. Changed method names for clarification. Removed method setAction.
2.1 2004-08-22 Added support for face reduction to optimize speed.
2.0 2004-08-03 Upgraded from Java 1.0 compliance to Java 1.1 compliance.
1.0 2000-02-28 Created.
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland

Constructor Summary
Shape3D(float[] coords, int[][] faces, java.awt.Color[][] colors)
          Creates a new Shape3D object.
Shape3D(float[] coords, int[][] faces, java.awt.Color[][] colors, int reducedFaceCount)
          Creates a new Shape3D object.
 
Method Summary
 void addVisibleFacesTo(java.util.List<Face3D> v, Transform3D t, Point3D observer)
          Adds all vertices to the vector that are visible when this Shape3D is transformed by the given Transform3D.
 float[] getCoords()
           
 int getFaceCount()
           
 Face3D[] getFaces()
           
 java.awt.Color getFillColor(int face)
           
 int[][] getVertices()
           
 boolean isRecuced()
           
 boolean isVisible()
           
 boolean isWireframe()
           
 void setAction(int face, java.awt.event.ActionListener action)
           
 void setBorderColor(int face, java.awt.Color color)
           
 void setFillColor(int face, java.awt.Color color)
           
 void setReduced(boolean b)
           
 void setTransform(Transform3D t)
           
 void setVisible(boolean b)
           
 void setWireframe(boolean b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Shape3D

public Shape3D(float[] coords,
               int[][] faces,
               java.awt.Color[][] colors)
Creates a new Shape3D object.

Parameters:
coords - Coordinate data for the shape. Each group of three entries describe a vector x, y, z in three dimensional space.
faces - Faces of the shape. Each entry in the first dimension of this array describes a face. Each entry in the second dimension of this array represents a vertex at the borderline of the face. Each vertex is the index of a vector in the coords array. The vertices of the face must be indicated in clockwise direction. All vertices must be on the same plane and the boundary of the face must be convex.
colors - The colors for each face. For each face, two colors can be specified: a fill color (index 0 of the inner array) and a wireframe color (index 1 of the inner array).

Shape3D

public Shape3D(float[] coords,
               int[][] faces,
               java.awt.Color[][] colors,
               int reducedFaceCount)
Creates a new Shape3D object.

Parameters:
coords - Coordinate data for the shape. Each group of three entries describe a vector x, y, z in three dimensional space.
faces - Faces of the shape. Each entry in the first dimension of this array describes a face. Each entry in the second dimension of this array represents a vertex at the borderline of the face. Each vertex is the index of a vector in the coords array. The vertices of the face must be indicated in clockwise direction. All vertices must be on the same plane and the boundary of the face must be convex.
colors - The colors for each face. For each face, two colors can be specified: a fill color (index 0 of the inner array) and a wireframe color (index 1 of the inner array).
reducedFaceCount - The shape will only draw reducedFaceCount colors, if the attribute isReduced is set to true.
Method Detail

getCoords

public float[] getCoords()

getVertices

public int[][] getVertices()

getFaces

public Face3D[] getFaces()

isVisible

public boolean isVisible()

setVisible

public void setVisible(boolean b)

isRecuced

public boolean isRecuced()

setReduced

public void setReduced(boolean b)

setTransform

public void setTransform(Transform3D t)

addVisibleFacesTo

public void addVisibleFacesTo(java.util.List<Face3D> v,
                              Transform3D t,
                              Point3D observer)
Adds all vertices to the vector that are visible when this Shape3D is transformed by the given Transform3D. The transform is applied to the vertices before they are added to the list.

Specified by:
addVisibleFacesTo in interface Node3D
Parameters:
v - The vector to which the vertices are added.
t - This transform is applied to the vertices before they are tested for visibility and added to the list.
observer - Coords of the observer.

setAction

public void setAction(int face,
                      java.awt.event.ActionListener action)

getFillColor

public java.awt.Color getFillColor(int face)

setFillColor

public void setFillColor(int face,
                         java.awt.Color color)

setBorderColor

public void setBorderColor(int face,
                           java.awt.Color color)

getFaceCount

public int getFaceCount()

isWireframe

public boolean isWireframe()

setWireframe

public void setWireframe(boolean b)

(c) Werner Randelshofer.
All rights reserved.