org.jrabbit.base.graphics.transforms
Class Scalar

java.lang.Object
  extended by org.jrabbit.base.graphics.transforms.Scalar
All Implemented Interfaces:
GLTransform

public class Scalar
extends java.lang.Object
implements GLTransform

A Scalar is an object that scales (and flips) the OpenGL Modelview Matrix. A Scalar can have listeners added to it. These listeners are alerted whenever the Scalar changes.

Author:
Chris Molini

Field Summary
protected  int hFlip
          The multiplier that controls horizontal flipping.
private  java.util.ArrayList<ScalarListener> listeners
          The list of all objects listening to this Scalar's changes.
protected  int vFlip
          The multiplier that controls vertical flipping.
protected  float xScale
          The amount to scale the x-dimension.
protected  float yScale
          The amount to scale the x-dimension.
 
Constructor Summary
Scalar()
          Creates a Scalar that does not change the OpenGL ModelviewMatrix and has an empty list of listeners.
 
Method Summary
 void addListener(ScalarListener listener)
          Adds a listener to the Scalar.
protected  void alertFlip()
          Alerts all listeners that the Scalar has been flipped.
protected  void alertScale()
          Alerts all listeners that the Scalar has been scaled.
 void bind()
          Scales and flips the ModelviewMatrix.
 void bindFlip()
          Only flips the ModelviewMatrix (does not scale).
 void bindScale()
          Only scales the ModelviewMatrix (does not flip).
 boolean equals(java.lang.Object other)
          As equals() in Object, but if the supplied object is a color, it checks to see if their color values are the same.
 void flipHorizontally()
          Flips the scalar horizontally.
 void flipVertically()
          Flips the scalar vertically.
 boolean improperlyScaled()
          It's not recommended to have the scaling factors be zero or negative; this causes odd behavior.
 boolean isFlippedHorizontally()
          Learns if the scalar has been flipped horizontally.
 boolean isFlippedVertically()
          Learns if the scalar has been flipped vertically.
 void release()
          Scales and flips the ModelviewMatrix by the inverse of the value used to bind().
 void removeListener(ScalarListener listener)
          Removes a listener from the Scalar.
 void reset()
          Sets the Scalar to the default values.
 float scale()
          Returns the overall amount that the Scalar scales the Modelview Matrix.
 void scaleBy(float ratio)
          Multiplies the scalar.
 void scaleBy(Scalar scalar)
          Multiplies the values of this scalar by those of the target.
 void scaleLinear(float amount)
          If an object is continuously scaled over time at a constant rate, its apparent increase does not appear to be linear.
 void scaleXBy(float ratio)
          Multiplies the x scale.
 void scaleYBy(float ratio)
          Multiplies the y scale.
 void set(Scalar scalar)
          Makes this Scalar have the same scaling factors as the other.
 void setFlip(boolean hFlip, boolean vFlip)
          Redefines the flipping factors.
 void setFlipHorizontally(boolean flip)
          Redefines the scalar's flipping.
 void setFlipVertically(boolean flip)
          Redefines the scalar's flipping.
 void setScale(float scale)
          Redefines the scaling factors.
 void setScale(float xScale, float yScale)
          Redefines the scaling factors.
 void setXScale(float xScale)
          Redefines the x scaling factor.
 void setYScale(float yScale)
          Redefines the y scaling factor.
 java.lang.String toString()
          Obtains the Scalar as a String.
 float transformX()
          Obtains the x-transform used on OpenGL.
 float transformY()
          Obtains the y-transform used on OpenGL.
 float xScale()
          Accesses the x scaling factor.
 float yScale()
          Accesses the y scaling factor.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hFlip

protected int hFlip
The multiplier that controls horizontal flipping.


vFlip

protected int vFlip
The multiplier that controls vertical flipping.


xScale

protected float xScale
The amount to scale the x-dimension.


yScale

protected float yScale
The amount to scale the x-dimension.


listeners

private java.util.ArrayList<ScalarListener> listeners
The list of all objects listening to this Scalar's changes.

Constructor Detail

Scalar

public Scalar()
Creates a Scalar that does not change the OpenGL ModelviewMatrix and has an empty list of listeners.

Method Detail

addListener

public void addListener(ScalarListener listener)
Adds a listener to the Scalar. This listener will be alerted whenever a change occurs.

Parameters:
listener - The listener to add.

removeListener

public void removeListener(ScalarListener listener)
Removes a listener from the Scalar.

Parameters:
listener - The listener to remove.

alertFlip

protected void alertFlip()
Alerts all listeners that the Scalar has been flipped.


alertScale

protected void alertScale()
Alerts all listeners that the Scalar has been scaled.


reset

public void reset()
Sets the Scalar to the default values.


set

public void set(Scalar scalar)
Makes this Scalar have the same scaling factors as the other.

Parameters:
scalar - The Scalar to copy.

setFlip

public void setFlip(boolean hFlip,
                    boolean vFlip)
Redefines the flipping factors.

Parameters:
hFlip - Whether or not to flip horizontally.
vFlip - Whether or not to flip vertically.

isFlippedHorizontally

public boolean isFlippedHorizontally()
Learns if the scalar has been flipped horizontally.

Returns:
True if flipped, false if not.

flipHorizontally

public void flipHorizontally()
Flips the scalar horizontally.


setFlipHorizontally

public void setFlipHorizontally(boolean flip)
Redefines the scalar's flipping.

Parameters:
flip - Whether or not the scalar should flip horizontally.

isFlippedVertically

public boolean isFlippedVertically()
Learns if the scalar has been flipped vertically.

Returns:
True if flipped, false if not.

flipVertically

public void flipVertically()
Flips the scalar vertically.


setFlipVertically

public void setFlipVertically(boolean flip)
Redefines the scalar's flipping.

Parameters:
flip - Whether or not the scalar should flip vertically.

transformX

public float transformX()
Obtains the x-transform used on OpenGL.

Returns:
The float used to scale the x dimension of the Modelview Matrix.

transformY

public float transformY()
Obtains the y-transform used on OpenGL.

Returns:
The float used to scale the y dimension of the Modelview Matrix.

scaleXBy

public void scaleXBy(float ratio)
Multiplies the x scale.

Parameters:
ratio - The amount to multiply the x scale factor.

scaleYBy

public void scaleYBy(float ratio)
Multiplies the y scale.

Parameters:
ratio - The amount to multiply the y scale factor.

scaleBy

public void scaleBy(float ratio)
Multiplies the scalar.

Parameters:
ratio - The amount to multiply the scaling factors by.

scaleBy

public void scaleBy(Scalar scalar)
Multiplies the values of this scalar by those of the target.

Parameters:
scalar - The scalar to multiply by.

scaleLinear

public void scaleLinear(float amount)
If an object is continuously scaled over time at a constant rate, its apparent increase does not appear to be linear. When its size is less than 1, it appears to shrink very quickly, but when its size is greater than 1, it appears to grow much more slowly. Using this method will smooth the process. NOTE: This method is a bit inexact.

Parameters:
amount - The amount to increase the scale by.

setScale

public void setScale(float scale)
Redefines the scaling factors.

Parameters:
scale - The new amount to scale both the x and y dimensions by.

setScale

public void setScale(float xScale,
                     float yScale)
Redefines the scaling factors.

Parameters:
xScale - The new amount to scale the x dimension by.
yScale - The new amount to scale the y dimension by.

setXScale

public void setXScale(float xScale)
Redefines the x scaling factor.

Parameters:
xScale - The new scaling factor.

setYScale

public void setYScale(float yScale)
Redefines the y scaling factor.

Parameters:
yScale - The new scaling factor.

scale

public float scale()
Returns the overall amount that the Scalar scales the Modelview Matrix. If the x and y scaling factors are different, this returns the square root of their product.

Returns:
The amount scaled.

xScale

public float xScale()
Accesses the x scaling factor.

Returns:
The ratio by which the Scalar scales the x dimension.

yScale

public float yScale()
Accesses the y scaling factor.

Returns:
The ratio by which the Scalar scales the y dimension.

improperlyScaled

public boolean improperlyScaled()
It's not recommended to have the scaling factors be zero or negative; this causes odd behavior. Scaling may still technically work, but it's better to simply use positive scaling and use flipping to achieve reversing.

Returns:
Whether or not either scaling factor is less than or equal to 0.

bind

public void bind()
Scales and flips the ModelviewMatrix.

Specified by:
bind in interface GLTransform

bindScale

public void bindScale()
Only scales the ModelviewMatrix (does not flip).


bindFlip

public void bindFlip()
Only flips the ModelviewMatrix (does not scale).


release

public void release()
Scales and flips the ModelviewMatrix by the inverse of the value used to bind().

Specified by:
release in interface GLTransform

equals

public boolean equals(java.lang.Object other)
As equals() in Object, but if the supplied object is a color, it checks to see if their color values are the same.

Overrides:
equals in class java.lang.Object
Parameters:
other - The object to check against.
Returns:
Whether or not this object is equivalent to the target.

toString

public java.lang.String toString()
Obtains the Scalar as a String.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of the Scalar.