CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.geom3d
Class Face3D

java.lang.Object
  extended by ch.randelshofer.geom3d.Face3D
All Implemented Interfaces:
java.lang.Comparable

public class Face3D
extends java.lang.Object
implements java.lang.Comparable

Represents a planar and convex polygon in 3 dimensional space.

Version:
3.0 2009-01-03 Added support for swipe listeners.
2.1 2004-08-21 Changed operation handleEvent(Event) to handleEvent(MouseEvent).
2.0 2004-08-03 Upgraded from Java 1.0 compliance to Java 1.1 compliance.
1.0 2002-06-26 Signature of method getBrightness changed.
0.1.1 2001-08-17 Pass java.awt.Event as event source to action listener. 0.1 2000-02-28 Created.
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland

Constructor Summary
Face3D(float[] coords, int[] vertices, java.awt.Color[] colors)
          Creates a new Face3D object.
 
Method Summary
 void addSwipeListener(SwipeListener l)
          returns the plane equation: a*x1 + b*y1 + c*z1 = -1 a*x2 + b*y2 + c*z2 = -1 a*x3 + b*y3 + c*z3 = -1 / public double[] getPlaneEquation() { return planeEquation; } /** Determines on which side of the given plane equation this face is.
 int compareTo(java.lang.Object o)
           
protected  void fireSwipeEvent(java.awt.event.MouseEvent evt, float angle)
           
 java.awt.event.ActionListener getAction()
           
 java.awt.Color getBorderColor()
           
 double getBrightness(Point3D light, double lightSourceIntensity, double ambientLightIntensity)
          Returns ambient light intensity + the intensity of this face's diffuse reflection to the light source.
 float[] getCoords()
           
 java.awt.Color getFillColor()
           
 int getSwipeListenerCount()
           
 SwipeListener[] getSwipeListeners()
           
 int[] getVertices()
           
 boolean handleEvent(java.awt.event.MouseEvent evt)
           
 boolean isVisible(Point3D observer)
           
 void removeSwipeListener(SwipeListener l)
           
 void setAction(java.awt.event.ActionListener action)
           
 void setCoords(float[] coords)
           
 void setFillColor(java.awt.Color newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Face3D

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

Parameters:
coords - Coordinate data for the face. Each group of three entries describe a vector x, y, z in three dimensional space.
vertices - Each entry 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.
Method Detail

getBorderColor

public java.awt.Color getBorderColor()

getFillColor

public java.awt.Color getFillColor()

setFillColor

public void setFillColor(java.awt.Color newValue)

setAction

public void setAction(java.awt.event.ActionListener action)

handleEvent

public boolean handleEvent(java.awt.event.MouseEvent evt)

getAction

public java.awt.event.ActionListener getAction()

isVisible

public boolean isVisible(Point3D observer)

getVertices

public int[] getVertices()

getCoords

public float[] getCoords()

setCoords

public void setCoords(float[] coords)

getBrightness

public double getBrightness(Point3D light,
                            double lightSourceIntensity,
                            double ambientLightIntensity)
Returns ambient light intensity + the intensity of this face's diffuse reflection to the light source. If the light source is behind the face, the ambient light intensity is returned. FIXME: The brightness must be determined before a perspective distortion is applied to the face.


compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

addSwipeListener

public void addSwipeListener(SwipeListener l)
returns the plane equation: a*x1 + b*y1 + c*z1 = -1 a*x2 + b*y2 + c*z2 = -1 a*x3 + b*y3 + c*z3 = -1 / public double[] getPlaneEquation() { return planeEquation; } /** Determines on which side of the given plane equation this face is. 0 = face is coplanar to the plane. 1 = face is on the far (hidden) side of the plane. -1 = face is on the near (visible) side of the plane. 2 = face intersects the plane. / public int determineSide(double[] peq) { double a = peq[0]; double b = peq[1]; double c = peq[2]; double d = peq[3]; int side = 0; for (int i=0; i < vertices.length; i++) { double test = a * coords[vertices[i]*3] + b * coords[vertices[i]*3+1] + c * coords[vertices[i]*3+2] + d; if (test > 0.1e-8) { side = (side == 0 || side == 1) ? 1 : 2; } else if (test < -0.1e-8) { side = (side <= 0) ? -1 : 2; } } return side; }


removeSwipeListener

public void removeSwipeListener(SwipeListener l)

getSwipeListeners

public SwipeListener[] getSwipeListeners()

getSwipeListenerCount

public int getSwipeListenerCount()

fireSwipeEvent

protected void fireSwipeEvent(java.awt.event.MouseEvent evt,
                              float angle)

(c) Werner Randelshofer.
All rights reserved.