Environment2D
Class Shape2D

java.lang.Object
  extended by Environment2D.Shape2D
Direct Known Subclasses:
Rectangle2D

public class Shape2D
extends java.lang.Object

Represents a single shape to the plane. Shapes can be moved and their properties changed during execution. They are transformed from the theoretical plane through the viewport and onto the graphics plane provided when rendering.

Extend this class in order to add new shapes or features such as collision detection code


Field Summary
 java.awt.Color colour
          Holds the colour of this shape.
 double h
          Holds the height on the plane of this shape.
 double w
          Holds the width on the plane of this shape.
 double x
          Holds the x co-ordinate on the plane of this shape.
 double y
          Holds the y co-ordinate on the plane of this shape.
 
Constructor Summary
Shape2D(double p_x, double p_y, double p_w, double p_h, java.awt.Color p_colour)
          Creates a new shape at a given position and of given dimensions.
 
Method Summary
protected  double getAdjustedScalar(double x, double p_viewMin, double p_viewMax, double p_graphcsWidth)
          Returns a scalar distance transformed to match a set output distance.
protected  Shape2D getAdjustedShape(Shape2D p_shape, Viewport2D p_view, java.awt.Dimension p_graphicsSize)
          Returns a new shape with dimensions that have been adjusted to fit a set viewport and dimension.
 void paintAdjusted(java.awt.Graphics g, java.awt.Dimension p_graphicsSize, Viewport2D p_view)
          Paints a shape onto a graphics plane, adjusting for the viewport and final output size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

public double x
Holds the x co-ordinate on the plane of this shape.


y

public double y
Holds the y co-ordinate on the plane of this shape.


w

public double w
Holds the width on the plane of this shape.


h

public double h
Holds the height on the plane of this shape.


colour

public java.awt.Color colour
Holds the colour of this shape.

Constructor Detail

Shape2D

public Shape2D(double p_x,
               double p_y,
               double p_w,
               double p_h,
               java.awt.Color p_colour)
Creates a new shape at a given position and of given dimensions.

Parameters:
p_x - The x co-ordinate to draw the top-left from.
p_y - The y co-ordinate to draw the top-left from.
p_w - The width of the shape
p_h - The height of the shape
p_colour - The colour of this shape
Method Detail

getAdjustedShape

protected Shape2D getAdjustedShape(Shape2D p_shape,
                                   Viewport2D p_view,
                                   java.awt.Dimension p_graphicsSize)
Returns a new shape with dimensions that have been adjusted to fit a set viewport and dimension. This is used when outputting to a graphics plane.

Parameters:
p_shape - The shape to transform.
p_view - The viewport to 'see' the plane through.
p_graphicsSize - The dimensions of the final output.

getAdjustedScalar

protected double getAdjustedScalar(double x,
                                   double p_viewMin,
                                   double p_viewMax,
                                   double p_graphcsWidth)
Returns a scalar distance transformed to match a set output distance. Used in scaling output for drawing on graphics planes.

The ratio of sizes is clearly (p_viewMax - p_viewMin):p_graphcsWidth

Parameters:
x - The value to transform
p_viewMin - The min. bound of the viewport
p_viewMax - The max. bound of the viewport
p_graphcsWidth - The width of the final output

paintAdjusted

public void paintAdjusted(java.awt.Graphics g,
                          java.awt.Dimension p_graphicsSize,
                          Viewport2D p_view)
Paints a shape onto a graphics plane, adjusting for the viewport and final output size.

Parameters:
g - The graphics plane on which to draw.
p_graphicsSize - The size of the graphics plane (or portion to output onto)
p_view - The viewport, defining what portions of the plane to output