com.flagstone.transform.datatype
Class CoordTransform

java.lang.Object
  extended by com.flagstone.transform.datatype.CoordTransform
All Implemented Interfaces:
SWFEncodeable

public final class CoordTransform
extends Object
implements SWFEncodeable

CoordTransform is used to specify a two-dimensional coordinate transform which allows an object to be scaled, rotated or moved without changing the original definition of how the object is drawn.

A two-dimensional transform is defined using a 3x3 matrix and the new values for a pair of coordinates (x,y) are calculated using the following matrix multiplication:

Different transformations such as scaling, rotation, shearing and translation can be performed using the above matrix multiplication. More complex transformations can be defined by performing successive matrix multiplications in a process known as compositing. This allows a complex transformations to performed on an object. However not that compositing transforms is not commutative, the order in which transformations are applied will affect the final result.


Field Summary
static int DEFAULT_COORD
          The default value used for the translation terms when a scaling or shearing transform is created.
static float DEFAULT_SCALE
          The default value used for the scaling terms when a translation or shearing transform is created.
static float DEFAULT_SHEAR
          The default value used for the shearing terms when a translation or scaling transform is created.
static float SCALE_FACTOR
          The factor applied to real numbers used for scaling terms when storing them as fixed point values.
static float SHEAR_FACTOR
          The factor applied to real numbers used for shearing terms when storing them as fixed point values.
 
Constructor Summary
CoordTransform(float[][] matrix)
          Creates and initialises a CoordTransform object using a 3x3 matrix.
CoordTransform(float xScale, float yScale, float xShear, float yShear, int xCoord, int yCoord)
          Creates an initialises a CoordTransform with scaling, shearing and translation values.
CoordTransform(SWFDecoder coder)
          Creates and initialises a CoordTransform object using values encoded in the Flash binary format.
 
Method Summary
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 boolean equals(Object object)
          
 float[][] getMatrix()
          Returns a matrix that can be used to create composite transforms.
 float getScaleX()
          Returns the scaling factor along the x-axis.
 float getScaleY()
          Returns the scaling factor along the y-axis.
 float getShearX()
          Returns the shearing factor along the x-axis.
 float getShearY()
          Returns the shearing factor along the y-axis.
 int getTranslateX()
          Returns the translation in the x direction.
 int getTranslateY()
          Returns the translation along the y-axis.
 int hashCode()
          
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
static float[][] product(float[][] left, float[][] right)
          Create a new coordinate transform by multiplying two matrices together to calculate the product.
static CoordTransform rotate(int angle)
          Create a CoordTransform initialised for a rotation in degrees.
static CoordTransform scale(float xScale, float yScale)
          Create a scaling transform.
static CoordTransform shear(float xShear, float yShear)
          Create a CoordTransform initialised for a shearing operation.
 String toString()
          
static CoordTransform translate(int xCoord, int yCoord)
          Create a translation transform.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SCALE

public static final float DEFAULT_SCALE
The default value used for the scaling terms when a translation or shearing transform is created.

See Also:
Constant Field Values

DEFAULT_SHEAR

public static final float DEFAULT_SHEAR
The default value used for the shearing terms when a translation or scaling transform is created.

See Also:
Constant Field Values

DEFAULT_COORD

public static final int DEFAULT_COORD
The default value used for the translation terms when a scaling or shearing transform is created.

See Also:
Constant Field Values

SCALE_FACTOR

public static final float SCALE_FACTOR
The factor applied to real numbers used for scaling terms when storing them as fixed point values.

See Also:
Constant Field Values

SHEAR_FACTOR

public static final float SHEAR_FACTOR
The factor applied to real numbers used for shearing terms when storing them as fixed point values.

See Also:
Constant Field Values
Constructor Detail

CoordTransform

public CoordTransform(SWFDecoder coder)
               throws IOException
Creates and initialises a CoordTransform object using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

CoordTransform

public CoordTransform(float[][] matrix)
Creates and initialises a CoordTransform object using a 3x3 matrix.

Parameters:
matrix - a 3x3 matrix containing the transform values.

CoordTransform

public CoordTransform(float xScale,
                      float yScale,
                      float xShear,
                      float yShear,
                      int xCoord,
                      int yCoord)
Creates an initialises a CoordTransform with scaling, shearing and translation values.

Parameters:
xScale - the scaling factor along the x-axis.
yScale - the scaling factor along the y-axis
xShear - the shearing factor along the x-axis.
yShear - the shearing factor along the y-axis
xCoord - the x coordinate of the transformation.
yCoord - the y coordinate of the transformation.
Method Detail

product

public static float[][] product(float[][] left,
                                float[][] right)
Create a new coordinate transform by multiplying two matrices together to calculate the product. Since matrix multiplication is not commutative the order in which the arguments are passed is important.

Parameters:
left - a 3x3 matrix
right - a 3x3 matrix
Returns:
a new 3x3 matrix contains the product of the two arguments.

translate

public static CoordTransform translate(int xCoord,
                                       int yCoord)
Create a translation transform.

Parameters:
xCoord - the x coordinate of the transformation.
yCoord - the y coordinate of the transformation.
Returns:
a CoordTransform containing the translation.

scale

public static CoordTransform scale(float xScale,
                                   float yScale)
Create a scaling transform.

Parameters:
xScale - the scaling factor along the x-axis.
yScale - the scaling factor along the y-axis
Returns:
a CoordTransform containing the scaling transform.

shear

public static CoordTransform shear(float xShear,
                                   float yShear)
Create a CoordTransform initialised for a shearing operation.

Parameters:
xShear - the shearing factor along the x-axis.
yShear - the shearing factor along the y-axis
Returns:
a CoordTransform containing the shearing transform.

rotate

public static CoordTransform rotate(int angle)
Create a CoordTransform initialised for a rotation in degrees.

Parameters:
angle - the of rotation in degrees.
Returns:
a CoordTransform containing the rotation.

getScaleX

public float getScaleX()
Returns the scaling factor along the x-axis.

Returns:
the scaling factor in the x-direction.

getScaleY

public float getScaleY()
Returns the scaling factor along the y-axis.

Returns:
the scaling factor in the y-direction.

getShearX

public float getShearX()
Returns the shearing factor along the x-axis.

Returns:
the shear factor in the x-direction.

getShearY

public float getShearY()
Returns the shearing factor along the y-axis.

Returns:
the shear factor in the y-direction.

getTranslateX

public int getTranslateX()
Returns the translation in the x direction.

Returns:
the translation, measured in twips, in the x-direction.

getTranslateY

public int getTranslateY()
Returns the translation along the y-axis.

Returns:
the translation, measured in twips, in the y-direction.

getMatrix

public float[][] getMatrix()
Returns a matrix that can be used to create composite transforms.

Returns:
the 3 X 3 array that is used to store the transformation values.

toString

public String toString()

Overrides:
toString in class Object

equals

public boolean equals(Object object)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.