org.vizzini.ui.graphics.shape
Class AbstractShape

java.lang.Object
  extended by org.vizzini.ui.graphics.shape.AbstractShape
All Implemented Interfaces:
Comparable, IStateful, IShape
Direct Known Subclasses:
AnchorShape, BoardShape, Box, Ellipse, ExtrudedShape, PolygonShape

public abstract class AbstractShape
extends Object
implements IShape

Provides base functionality for 3D shapes. The coordinate system is screen based (+Z into the screen).

         ^ +Z
        /
       /
      +-----> +X
      |
      |
      V +Y
 
Other shapes can be placed "on" or relative to this one with add. Specify their center with setCenter relative to this.

Since:
v0.2
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
protected  boolean _isWireframe
          Flag indicating whether to draw this as a wireframe or solid.
protected  Vector[] _points
          The absolute point relative to the center.
protected  Vector _screenCenter
          The center in screen coordinates.
protected  Vector[] _screenPoints
          The shape's points in screen coordinates.
protected  ShapeGroup _shapeGroup
          Collection of child shapes to this shape.
protected  double _zNormal
          The z normal value.
 
Constructor Summary
AbstractShape(double width, double height, double depth)
          Construct this object with the given parameters.
 
Method Summary
 void add(IShape shape)
          Add the given shape as a child of this.
 void clear()
          Clear all child shapes.
 int compareTo(Object object)
          Compare this shape to the given object.
protected  void computeCenteredScreenPoints()
          Translate the screen points by the screen center.
 double computeNormalZComponent(int i1, int i2, int i3)
          Compute the normal z component of the plane define by the points with the given indices in screen coordinates.
protected  Vector computeScreenCenter(Quaternion q, Vector v, double magnify, int offsetX, int offsetY)
          Compute the center in screen coordinates.
 void computeScreenPoints(Quaternion q, Vector v, double magnify, int offsetX, int offsetY, double d)
          Compute the points of this shape in screen coordinates.
 boolean contains(Point point)
          Return true if the given point is within this shape.
protected  IState createState()
          Create the state.
protected  StatefulSupport createStatefulSupport()
          Create a stateful support object.
 void drawOn(Graphics g, double magnify)
          Draw this shape on the given graphics with the given magnification.
protected  void drawOn(Graphics g, double magnify, boolean isWireframe)
          Draw this shape on the given graphics with the given magnification.
protected  void drawOnSolid(Graphics g, double magnify)
          Draw a solid representation of this shape on the given graphics with the given magnification.
protected  void drawOnWireframe(Graphics g, double magnify)
          Draw a wireframe representation of this shape on the given graphics with the given magnification.
 IState getAbsoluteState()
          Return the absolute state.
 Rectangle getBounds()
          Return the bounding box of the screen coordinates.
 ShapeGroup getChildren()
          Return the child shapes.
 Color getColor()
          Return the color of this shape.
protected  Color getColorForIntensity(double intensity)
          Return this shape's color scaled by the given intensity.
 double getDepth()
           
 Vector getDimensions()
          Return the dimensions in world coordinates.
 double getHeight()
           
 double getMinDimension()
          Return the minimum dimension.
 String getName()
           
 Vector getScreenCenter()
          Return this shape's center in screen coordinates.
 ShapeGroup getShapeGroup()
          Return the shape group.
 IState getState()
          Return the state.
 IStateful getStatefulParent()
          Return the parent.
 String getTextureFilepath()
          Return the texture filepath.
 double getWidth()
           
protected  boolean isInFrontOf(IShape s)
          Return true if the given shape is in front of this.
 boolean isLightSource()
           
 boolean isTextureFilepathSet()
          Return true if a texture filepath is set.
 boolean isVisible()
          Return true if this is visible.
 boolean isWireframe()
          Return true if this is wireframe.
 void remove(IShape shape)
          Remove the given child shape.
 void setColor(Color color)
          Set the color.
 void setLightSource(boolean isLightSource)
           
 void setName(String name)
           
 void setStatefulParent(IStateful parent)
          Set the parent.
 void setTextureFilepath(String textureFilepath)
          Set the texture filepath.
 void setVisible(boolean isVisible)
          Set the visibility flag.
 void setWireframe(boolean isWireframe)
          Set the wireframe flag.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_isWireframe

protected boolean _isWireframe
Flag indicating whether to draw this as a wireframe or solid.


_points

protected Vector[] _points
The absolute point relative to the center.


_screenCenter

protected Vector _screenCenter
The center in screen coordinates.


_screenPoints

protected Vector[] _screenPoints
The shape's points in screen coordinates.


_shapeGroup

protected ShapeGroup _shapeGroup
Collection of child shapes to this shape.


_zNormal

protected double _zNormal
The z normal value.

Constructor Detail

AbstractShape

public AbstractShape(double width,
                     double height,
                     double depth)
Construct this object with the given parameters.

Parameters:
width - Width.
height - Height.
depth - Depth.
Since:
v0.2
Method Detail

add

public void add(IShape shape)
Add the given shape as a child of this.

Specified by:
add in interface IShape
Parameters:
shape - The new child shape.
Since:
v0.2

clear

public void clear()
Clear all child shapes.

Specified by:
clear in interface IShape
Since:
v0.2

compareTo

public int compareTo(Object object)
Compare this shape to the given object.

Specified by:
compareTo in interface Comparable
Since:
v0.2

computeNormalZComponent

public final double computeNormalZComponent(int i1,
                                            int i2,
                                            int i3)
Compute the normal z component of the plane define by the points with the given indices in screen coordinates.

Specified by:
computeNormalZComponent in interface IShape
Since:
v0.2

computeScreenPoints

public void computeScreenPoints(Quaternion q,
                                Vector v,
                                double magnify,
                                int offsetX,
                                int offsetY,
                                double d)
Compute the points of this shape in screen coordinates.

Specified by:
computeScreenPoints in interface IShape
Parameters:
q - Rotation of the parent to world coordinates.
v - The parent position in world coordinates..
magnify - The magnification.
offsetX - The offset X coordinate.
offsetY - The offset Y coordinate.
d - Perspective constant.
Since:
v0.2

contains

public boolean contains(Point point)
Return true if the given point is within this shape.

Specified by:
contains in interface IShape
Since:
v0.2

drawOn

public void drawOn(Graphics g,
                   double magnify)
Draw this shape on the given graphics with the given magnification.

Specified by:
drawOn in interface IShape
Parameters:
g - The graphics.
magnify - The magnification.
Since:
v0.2

getAbsoluteState

public IState getAbsoluteState()
Return the absolute state.

Specified by:
getAbsoluteState in interface IStateful
Since:
v0.2

getBounds

public Rectangle getBounds()
Return the bounding box of the screen coordinates.

Specified by:
getBounds in interface IShape
Since:
v0.2

getChildren

public ShapeGroup getChildren()
Return the child shapes.

Specified by:
getChildren in interface IShape
Since:
v0.2

getColor

public Color getColor()
Return the color of this shape.

Specified by:
getColor in interface IShape
Since:
v0.2

getDepth

public double getDepth()
Specified by:
getDepth in interface IShape
Returns:
Return depth.
Since:
v0.3

getDimensions

public Vector getDimensions()
Return the dimensions in world coordinates.

Specified by:
getDimensions in interface IShape
Since:
v0.3

getHeight

public double getHeight()
Specified by:
getHeight in interface IShape
Returns:
Return height.
Since:
v0.3

getMinDimension

public double getMinDimension()
Return the minimum dimension.

Specified by:
getMinDimension in interface IShape
Since:
v0.3

getName

public String getName()
Specified by:
getName in interface IShape
Returns:
Return name.
Since:
v0.3

getScreenCenter

public Vector getScreenCenter()
Return this shape's center in screen coordinates.

Specified by:
getScreenCenter in interface IShape
Since:
v0.2

getShapeGroup

public ShapeGroup getShapeGroup()
Return the shape group.

Since:
v0.2

getState

public IState getState()
Return the state.

Specified by:
getState in interface IStateful
Since:
v0.2

getStatefulParent

public IStateful getStatefulParent()
Return the parent.

Specified by:
getStatefulParent in interface IStateful
Since:
v0.2

getTextureFilepath

public String getTextureFilepath()
Description copied from interface: IShape
Return the texture filepath.

Specified by:
getTextureFilepath in interface IShape
Returns:
Return textureFilepath.
Since:
v0.3

getWidth

public double getWidth()
Specified by:
getWidth in interface IShape
Returns:
Return width.
Since:
v0.3

isLightSource

public boolean isLightSource()
Specified by:
isLightSource in interface IShape
Returns:
Return isLightSource.
Since:
v0.3

isTextureFilepathSet

public boolean isTextureFilepathSet()
Return true if a texture filepath is set.

Specified by:
isTextureFilepathSet in interface IShape
Since:
v0.3

isVisible

public boolean isVisible()
Return true if this is visible.

Specified by:
isVisible in interface IShape
Since:
v0.2

isWireframe

public boolean isWireframe()
Return true if this is wireframe.

Specified by:
isWireframe in interface IShape
Since:
v0.2

remove

public void remove(IShape shape)
Remove the given child shape.

Specified by:
remove in interface IShape
Since:
v0.2

setColor

public void setColor(Color color)
Set the color.

Specified by:
setColor in interface IShape
Since:
v0.2

setLightSource

public void setLightSource(boolean isLightSource)
Specified by:
setLightSource in interface IShape
Parameters:
isLightSource - the isLightSource to set
Since:
v0.3

setName

public void setName(String name)
Specified by:
setName in interface IShape
Parameters:
name - the name to set
Since:
v0.3

setStatefulParent

public void setStatefulParent(IStateful parent)
Set the parent.

Specified by:
setStatefulParent in interface IStateful
Since:
v0.2

setTextureFilepath

public void setTextureFilepath(String textureFilepath)
Description copied from interface: IShape
Set the texture filepath.

Specified by:
setTextureFilepath in interface IShape
Parameters:
textureFilepath - the textureFilepath to set
Since:
v0.3

setVisible

public void setVisible(boolean isVisible)
Set the visibility flag. If false, neither this shape nor its children are drawn.

Specified by:
setVisible in interface IShape
Since:
v0.2

setWireframe

public void setWireframe(boolean isWireframe)
Set the wireframe flag.

Specified by:
setWireframe in interface IShape
Since:
v0.2

toString

public String toString()
Return a string representation of this object.

Specified by:
toString in interface IShape
Overrides:
toString in class Object
Since:
v0.2

computeCenteredScreenPoints

protected void computeCenteredScreenPoints()
Translate the screen points by the screen center.

Since:
v0.2

computeScreenCenter

protected Vector computeScreenCenter(Quaternion q,
                                     Vector v,
                                     double magnify,
                                     int offsetX,
                                     int offsetY)
Compute the center in screen coordinates.

Parameters:
q - The parent quaternion.
v - The parent center.
magnify - The magnification.
offsetX - The offset X coordinate.
offsetY - The offset Y coordinate.
Since:
v0.2

createState

protected IState createState()
Create the state.

Since:
v0.2

createStatefulSupport

protected StatefulSupport createStatefulSupport()
Create a stateful support object.

Since:
v0.2

drawOn

protected void drawOn(Graphics g,
                      double magnify,
                      boolean isWireframe)
Draw this shape on the given graphics with the given magnification. Subclasses should override this method if their solid and wireframe representations are the same.

Parameters:
g - The graphics.
magnify - The magnification.
isWireframe - Flag indicating if this shape is wireframe or solid.
Since:
v0.2

drawOnSolid

protected void drawOnSolid(Graphics g,
                           double magnify)
Draw a solid representation of this shape on the given graphics with the given magnification.

Parameters:
g - The graphics.
magnify - The magnification.
Since:
v0.2

drawOnWireframe

protected void drawOnWireframe(Graphics g,
                               double magnify)
Draw a wireframe representation of this shape on the given graphics with the given magnification.

Parameters:
g - The graphics.
magnify - The magnification.
Since:
v0.2

getColorForIntensity

protected Color getColorForIntensity(double intensity)
Return this shape's color scaled by the given intensity.

Parameters:
intensity - The desired color intensity between 0.0 and 1.0.
Since:
v0.2

isInFrontOf

protected boolean isInFrontOf(IShape s)
Return true if the given shape is in front of this.

Parameters:
s - Shape to compare.
Since:
v0.2


Copyright © 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02