public class Transform extends Object
Graphics
contexts
or with Shape
s to transform in various ways.
Use the isSupported()
and isPerspectiveSupported()
to check if transforms and
perspective transforms are supported on this platform. If they are not supported, this
class will throw RuntimeExceptions if you try to use it.Modifier and Type | Class and Description |
---|---|
static class |
Transform.NotInvertibleException |
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_IDENTITY
Constant for transform type.
|
static int |
TYPE_SCALE
Constant for transform type.
|
static int |
TYPE_TRANSLATION
Constant for transform type.
|
static int |
TYPE_UNKNOWN
Constant for transform type.
|
Modifier and Type | Method and Description |
---|---|
void |
concatenate(Transform t)
Sets the current transform to be the concatenation of the current transform and
the provided transform.
|
Transform |
copy()
Creates a copy of the current transform.
|
boolean |
equals(Transform t2) |
Transform |
getInverse()
Deprecated.
Use
getInverse(com.codename1.ui.Transform) instead. |
void |
getInverse(Transform inverseOut) |
Object |
getNativeTransform()
Gets the native transform object.
|
float |
getScaleX()
Gets the x scale factor of this transformation.
|
float |
getScaleY()
Gets the y scale factor of this transformation.
|
float |
getScaleZ()
Gets the z scale factor of this transformation.
|
float |
getTranslateX()
Gets the x translation of this transformation.
|
float |
getTranslateY()
Gets the y translation of this transformation.
|
float |
getTranslateZ()
Gets the z translation of this transformation.
|
static Transform |
IDENTITY() |
void |
invert() |
boolean |
isIdentity()
Checks if this transform is the identity transform.
|
static boolean |
isPerspectiveSupported()
Checks if perspective transforms are supported on this platform.
|
boolean |
isScale()
Checks if this transform is a scale transformation .
|
static boolean |
isSupported()
Checks if transforms are supported on this platform.
|
boolean |
isTranslation()
Checks if this transform is a translation transform.
|
static Transform |
makeAffine(double m00,
double m10,
double m01,
double m11,
double m02,
double m12) |
static Transform |
makeCamera(float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ)
Makes a transform to simulate a camera's perspective at a given location.
|
static Transform |
makeIdentity()
Makes a new identity transform.
|
static Transform |
makeOrtho(float left,
float right,
float bottom,
float top,
float near,
float far)
Makes a new orthographic projection transform.
|
static Transform |
makePerspective(float fovy,
float aspect,
float zNear,
float zFar)
Makes a new perspective transform.
|
static Transform |
makeRotation(float angle,
float x,
float y) |
static Transform |
makeRotation(float angle,
float x,
float y,
float z)
Makes a new rotation transformation.
|
static Transform |
makeScale(float x,
float y)
Creates a new scale transform.
|
static Transform |
makeScale(float x,
float y,
float z)
Makes a new scale transformation.
|
static Transform |
makeTranslation(float x,
float y) |
static Transform |
makeTranslation(float x,
float y,
float z)
Makes a new translation transformation.
|
void |
rotate(float angle,
float px,
float py) |
void |
rotate(float angle,
float x,
float y,
float z)
Rotates the current transform.
|
void |
scale(float x,
float y) |
void |
scale(float x,
float y,
float z)
Scales the current transform by the provide scale factors.
|
void |
setAffine(double m00,
double m10,
double m01,
double m11,
double m02,
double m12) |
void |
setCamera(float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ)
Sets the transform to the specified camera's perspective.
|
void |
setIdentity()
Sets the transform to the identity transform.
|
void |
setOrtho(float left,
float right,
float bottom,
float top,
float near,
float far)
Sets the transform to be the specified orthogonal view.
|
void |
setPerspective(float fovy,
float aspect,
float zNear,
float zFar)
Sets the transform to be the specified perspective transformation.
|
void |
setRotation(float angle,
float px,
float py) |
void |
setRotation(float angle,
float x,
float y,
float z)
Sets the transform to be the provided rotation.
|
void |
setScale(float x,
float y)
Resets the transformation to scale transform.
|
void |
setScale(float x,
float y,
float z)
Resets the transformation to a scale transformation.
|
void |
setTransform(Transform t)
Sets the current transform to be identical to the provided transform.
|
void |
setTranslation(float x,
float y) |
void |
setTranslation(float x,
float y,
float z)
Sets the current transform to be the specified translation.
|
String |
toString()
Returns a string representation of the object.
|
float[] |
transformPoint(float[] point)
Transforms a provided point.
|
void |
transformPoint(float[] in,
float[] out)
Transforms a provided point and places the result in the provided array.
|
void |
transformPoints(int pointSize,
float[] in,
int srcPos,
float[] out,
int destPos,
int numPoints)
Transforms a set of points using the current transform.
|
void |
translate(float x,
float y) |
void |
translate(float x,
float y,
float z)
Translates the transform by the specified amounts.
|
public static final int TYPE_UNKNOWN
public static final int TYPE_IDENTITY
public static final int TYPE_TRANSLATION
public static final int TYPE_SCALE
public static Transform IDENTITY()
public static Transform makeIdentity()
public boolean isIdentity()
public boolean isTranslation()
public float getScaleX()
isScale()
,
#setScale()
public float getScaleY()
isScale()
,
#setScale()
public float getScaleZ()
isScale()
,
#setScale()
public float getTranslateX()
isTranslation()
,
#setTranslation()
,
#translate()
public float getTranslateY()
isTranslation()
,
#setTranslation()
,
#translate()
public float getTranslateZ()
isTranslation()
,
#setTranslation()
,
#translate()
public boolean isScale()
public static Transform makeRotation(float angle, float x, float y, float z)
Note: If isSupported()
is false, then this will throw a Runtime Exception.
angle
- The angle of the rotation in radians.x
- The x component of the vector around which the rotation occurs.y
- The y component of the vector around which the rotation occurs.z
- The z component of the vector around which the rotation occurs.RuntimeException
- If isSupported()
is false.public static Transform makeRotation(float angle, float x, float y)
public static Transform makeTranslation(float x, float y, float z)
x
- The x component of the translation.y
- The y component of the translation.z
- The z component of the translation.public static Transform makeTranslation(float x, float y)
public static Transform makeScale(float x, float y, float z)
x
- The x scale factor.y
- The y scale factor.z
- The z scale factor.public static Transform makeScale(float x, float y)
x
- Factor to scale in x axis.y
- Factor to scale by in y axis.public static Transform makeAffine(double m00, double m10, double m01, double m11, double m02, double m12)
public void setScale(float x, float y, float z)
x
- x-axis scalingy
- y-axis scalingz
- z-axis scalingpublic void setScale(float x, float y)
x
- x-axis scaling.y
- y-axis scaling.public static Transform makePerspective(float fovy, float aspect, float zNear, float zFar)
Note: If isPerspectiveSupported()
is false, then this will throw a Runtime Exception.
fovy
- The y field of view angle.aspect
- The aspect ratio.zNear
- The nearest visible z coordinate.zFar
- The farthest z coordinate.public static Transform makeOrtho(float left, float right, float bottom, float top, float near, float far)
Note: If isPerspectiveSupported()
is false, then this will throw a Runtime Exception.
left
- x-coordinate that is the left edge of the view.right
- The x-coordinate that is the right edge of the view.bottom
- The y-coordinate that is the bottom edge of the view.top
- The y-coordinate that is the top edge of the view.near
- The nearest visible z-coordinate.far
- The farthest visible z-coordinate.public static Transform makeCamera(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Note: If isPerspectiveSupported()
is false, then this will throw a Runtime Exception.
eyeX
- The x-coordinate of the camera's eye.eyeY
- The y-coordinate of the camera's eye.eyeZ
- The z-coordinate of the camera's eye.centerX
- The center x coordinate of the view.centerY
- The center y coordinate of the view.centerZ
- The center z coordinate of the view.upX
- The x-coordinate of the up vector for the camera.upY
- The y-coordinate of the up vector for the camera.upZ
- The z-coordinate of the up vector for the camera.public void rotate(float angle, float x, float y, float z)
Note: If isSupported()
is false, then this will throw a Runtime Exception.
angle
- The angle to rotate in radians.x
- The x-coordinate of the vector around which to rotate.y
- The y-coordinate of the vector around which to rotate.z
- The z-coordinate of the vector around which to rotate.setRotation(float, float, float, float)
public void rotate(float angle, float px, float py)
public void setRotation(float angle, float x, float y, float z)
#rotate()
further rotates the current transform.
Note: If isSupported()
is false, then this will throw a Runtime Exception.
angle
- The angle to rotate in radians.x
- The x-coordinate of the vector around which to rotate.y
- The y-coordinate of the vector around which to rotate.z
- The z-coordinate of the vector around which to rotate.#rotate()
public void setRotation(float angle, float px, float py)
public void setIdentity()
public String toString()
Object
public void translate(float x, float y, float z)
#setTranslation()
replaces the transform
with the specified translation.
Note: If isSupported()
is false, then this may throw a Runtime Exception.
x
- The x translation.y
- The y translation.z
- The z translation.#setTranslation()
public void translate(float x, float y)
public void setTranslation(float x, float y, float z)
#translate()
adds additional translation
to the existing translation.x
- The x translation.y
- The y translation.z
- The z translation.#translate()
public void setTranslation(float x, float y)
public void scale(float x, float y, float z)
#setScale()
which replaces the transform.
Note: If isSupported()
is false, then this may throw a Runtime Exception.
x
- The x-scale factory
- The y-scale factorz
- The z-scale factor#setScale()
public void scale(float x, float y)
public Transform getInverse()
getInverse(com.codename1.ui.Transform)
instead.Note: If isSupported()
is false, then this will throw a Runtime Exception.
public void getInverse(Transform inverseOut) throws Transform.NotInvertibleException
Transform.NotInvertibleException
public void invert() throws Transform.NotInvertibleException
Transform.NotInvertibleException
public void setTransform(Transform t)
Note: If isSupported()
is false, then this will may throw a Runtime Exception.
t
- A transform to copy into the current transform.public void concatenate(Transform t)
Note: If isSupported()
is false, then this will throw a Runtime Exception.
t
- The transform to concatenate to this one.public void setPerspective(float fovy, float aspect, float zNear, float zFar)
Note: If isPerspectiveSupported()
is false, then this will throw a Runtime Exception.
fovy
- Y-field of view angle.aspect
- Apspect ratio of the view window.zNear
- Nearest visible z-coordinate.zFar
- Farthest visible z-coordinate.#makePerspective()
public void setAffine(double m00, double m10, double m01, double m11, double m02, double m12)
public void setOrtho(float left, float right, float bottom, float top, float near, float far)
Note: If isPerspectiveSupported()
is false, then this will throw a Runtime Exception.
left
- Left x-coord of view.right
- Right x-coord of view.bottom
- Bottom y-coord of view.top
- Top y-coord of view.near
- Nearest visible z-coordinatefar
- Farthest visible z-coordinatepublic void setCamera(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Note: If isPerspectiveSupported()
is false, then this will throw a Runtime Exception.
eyeX
- The x-coordinate of the camera's eye.eyeY
- The y-coordinate of the camera's eye.eyeZ
- The z-coordinate of the camera's eye.centerX
- The center x coordinate of the view.centerY
- The center y coordinate of the view.centerZ
- The center z coordinate of the view.upX
- The x-coordinate of the up vector for the camera.upY
- The y-coordinate of the up vector for the camera.upZ
- The z-coordinate of the up vector for the camera.public void transformPoints(int pointSize, float[] in, int srcPos, float[] out, int destPos, int numPoints)
pointSize
- The size of the points to transform (2 or 3)in
- Input array of points.srcPos
- Start position in input arrayout
- Output array of pointsdestPos
- Start position in output arraynumPoints
- Number of points to transform.public float[] transformPoint(float[] point)
Note: If isSupported()
is false, then this will throw a Runtime Exception.
point
- 2 or 3 element array representing either an (x,y) or (x,y,z) tuple.public void transformPoint(float[] in, float[] out)
Note: If isSupported()
is false, then this will throw a Runtime Exception.
in
- A 2 or 3 element array representing either an (x,y) or (x,y,z) tuple.out
- A 2 or 3 element array in which the transformed point will be stored. Should match the length of the in array.public Object getNativeTransform()
Note: If isSupported()
is false, then this will throw a Runtime Exception.
public Transform copy()
Note: If isSupported()
is false, then this will throw a Runtime Exception.
public static boolean isSupported()
public static boolean isPerspectiveSupported()
public boolean equals(Transform t2)