Class Transform
Encapsulates a 3D transform that can be used in com.codename1.ui.Graphics contexts
or with com.codename1.ui.geom.Shapes 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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant for transform type.static final intConstant for transform type.static final intConstant for transform type.static final intConstant for transform type. -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the current transform to be the concatenation of the current transform and the provided transform.copy()Creates a copy of the current transform.booleanbooleanGets the inverse transformation for this transform.voidgetInverse(Transform inverseOut) Gets the native transform object.floatGets the x scale factor of this transformation.floatGets the y scale factor of this transformation.floatGets the z scale factor of this transformation.floatGets the x translation of this transformation.floatGets the y translation of this transformation.floatGets the z translation of this transformation.inthashCode()static Transformidentity()static TransformIDENTITY()Deprecated.voidinvert()booleanChecks if this transform is the identity transform.static booleanChecks if perspective transforms are supported on this platform.booleanisScale()Checks if this transform is a scale transformation .static booleanChecks if transforms are supported on this platform.booleanChecks if this transform is a translation transform.static TransformmakeAffine(double m00, double m10, double m01, double m11, double m02, double m12) static TransformmakeCamera(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 TransformMakes a new identity transform.static TransformmakeOrtho(float left, float right, float bottom, float top, float near, float far) Makes a new orthographic projection transform.static TransformmakePerspective(float fovy, float aspect, float zNear, float zFar) Makes a new perspective transform.static TransformmakeRotation(float angle, float x, float y) static TransformmakeRotation(float angle, float x, float y, float z) Makes a new rotation transformation.static TransformmakeScale(float x, float y) Creates a new scale transform.static TransformmakeScale(float x, float y, float z) Makes a new scale transformation.static TransformmakeTranslation(float x, float y) static TransformmakeTranslation(float x, float y, float z) Makes a new translation transformation.voidrotate(float angle, float px, float py) voidrotate(float angle, float x, float y, float z) Rotates the current transform.voidscale(float x, float y) voidscale(float x, float y, float z) Scales the current transform by the provide scale factors.voidsetAffine(double m00, double m10, double m01, double m11, double m02, double m12) voidsetCamera(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.voidSets the transform to the identity transform.voidsetOrtho(float left, float right, float bottom, float top, float near, float far) Sets the transform to be the specified orthogonal view.voidsetPerspective(float fovy, float aspect, float zNear, float zFar) Sets the transform to be the specified perspective transformation.voidsetRotation(float angle, float px, float py) voidsetRotation(float angle, float x, float y, float z) Sets the transform to be the provided rotation.voidsetScale(float x, float y) Resets the transformation to scale transform.voidsetScale(float x, float y, float z) Resets the transformation to a scale transformation.voidSets the current transform to be identical to the provided transform.voidsetTranslation(float x, float y) voidsetTranslation(float x, float y, float z) Sets the current transform to be the specified translation.toString()float[]transformPoint(float[] point) Transforms a provided point.voidtransformPoint(float[] in, float[] out) Transforms a provided point and places the result in the provided array.voidtransformPoints(int pointSize, float[] in, int srcPos, float[] out, int destPos, int numPoints) Transforms a set of points using the current transform.voidtranslate(float x, float y) voidtranslate(float x, float y, float z) Translates the transform by the specified amounts.
-
Field Details
-
TYPE_UNKNOWN
public static final int TYPE_UNKNOWNConstant for transform type. Transform is not a special matrix.- See Also:
-
TYPE_IDENTITY
public static final int TYPE_IDENTITYConstant for transform type. Transform is the identity transform.- See Also:
-
TYPE_TRANSLATION
public static final int TYPE_TRANSLATIONConstant for transform type. Transform is a translation transform only.- See Also:
-
TYPE_SCALE
public static final int TYPE_SCALEConstant for transform type. Transform is a scale transform only.- See Also:
-
-
Method Details
-
IDENTITY
-
identity
-
makeIdentity
Makes a new identity transform.
Returns
An identity transform.
-
makeRotation
Makes a new rotation transformation.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
Returns
A transform that makes the appropriate rotation.
Throws
RuntimeException: If#isSupported()is false.
-
-
makeRotation
-
makeTranslation
Makes a new translation transformation.
Parameters
-
x: The x component of the translation. -
y: The y component of the translation. -
z: The z component of the translation.
Returns
A transform that makes the specified translation.
-
-
makeTranslation
-
makeScale
Makes a new scale transformation.
Parameters
-
x: The x scale factor. -
y: The y scale factor. -
z: The z scale factor.
Returns
A transform that scales values according to the provided scale factors.
-
-
makeScale
Creates a new scale transform.
Parameters
-
x: Factor to scale in x axis. -
y: Factor to scale by in y axis.
Returns
A new transform with the specified scale.
-
-
makeAffine
public static Transform makeAffine(double m00, double m10, double m01, double m11, double m02, double m12) -
makePerspective
Makes a new perspective transform.
Note: If
#isPerspectiveSupported()is false, then this will throw a Runtime Exception.Parameters
-
fovy: The y field of view angle. -
aspect: The aspect ratio. -
zNear: The nearest visible z coordinate. -
zFar: The farthest z coordinate.
Returns
A transform for the given perspective.
-
-
makeOrtho
public static Transform makeOrtho(float left, float right, float bottom, float top, float near, float far) Makes a new orthographic projection transform.
Note: If
#isPerspectiveSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
Returns
A transform with the provided orthographic projection.
-
-
makeCamera
public 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.
Note: If
#isPerspectiveSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
Returns
A transform with the provided camera's view perspective.
-
-
isSupported
public static boolean isSupported()Checks if transforms are supported on this platform. If this returns false, you cannot use this class.
Returns
True if and only if this platform supports transforms.
-
isPerspectiveSupported
public static boolean isPerspectiveSupported()Checks if perspective transforms are supported on this platform. If this returns false, you cannot use this class.
Returns
True if and only if this platform supports transforms.
-
isIdentity
public boolean isIdentity()Checks if this transform is the identity transform.
Returns
True if the transform is the identity.
-
isTranslation
public boolean isTranslation()Checks if this transform is a translation transform.
Returns
- Returns:
- True if this transform performs translation only. Note that this will return false if the transform is the identity (i.e. is actually a translation of (0,0,0).
-
getScaleX
public float getScaleX()Gets the x scale factor of this transformation. This value is only reliable if the transform is a scale transform.
Returns
The x scale factor of this transformation.
See also
-
#isScale()
-
#setScale()
-
-
getScaleY
public float getScaleY()Gets the y scale factor of this transformation. This value is only reliable if the transform is a scale transform.
See also
-
#isScale()
-
#setScale()
-
-
getScaleZ
public float getScaleZ()Gets the z scale factor of this transformation. This value is only reliable if the transform is a scale transform.
See also
-
#isScale()
-
#setScale()
-
-
getTranslateX
public float getTranslateX()Gets the x translation of this transformation. This value is only reliable if the transform is a translation transform.
Returns
The x translation of this transform.
See also
-
#isTranslation()
-
#setTranslation()
-
#translate()
-
-
getTranslateY
public float getTranslateY()Gets the y translation of this transformation. This value is only reliable if the transform is a translation transform.
Returns
The y translation of this transform.
See also
-
#isTranslation()
-
#setTranslation()
-
#translate()
-
-
getTranslateZ
public float getTranslateZ()Gets the z translation of this transformation. This value is only reliable if the transform is a translation transform.
Returns
The z translation of this transform.
See also
-
#isTranslation()
-
#setTranslation()
-
#translate()
-
-
isScale
public boolean isScale()Checks if this transform is a scale transformation .
Returns
Returns true if and only if this is a non-identity scale transformation.
-
setScale
public void setScale(float x, float y, float z) Resets the transformation to a scale transformation.
Parameters
-
x: x-axis scaling -
y: y-axis scaling -
z: z-axis scaling
-
-
setScale
public void setScale(float x, float y) Resets the transformation to scale transform.
Parameters
-
x: x-axis scaling. -
y: y-axis scaling.
-
-
rotate
public void rotate(float angle, float x, float y, float z) Rotates the current transform.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
See also
- #setRotation
-
-
rotate
public void rotate(float angle, float px, float py) -
setRotation
public void setRotation(float angle, float x, float y, float z) Sets the transform to be the provided rotation. This replaces the current transform whereas
#rotate()further rotates the current transform.Note: If
#isSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
See also
- #rotate()
-
-
setRotation
public void setRotation(float angle, float px, float py) -
setIdentity
public void setIdentity()Sets the transform to the identity transform. -
toString
-
translate
public void translate(float x, float y, float z) Translates the transform by the specified amounts. This adds additional translations to whereas
#setTranslation()replaces the transform with the specified translation.Note: If
#isSupported()is false, then this may throw a Runtime Exception.Parameters
-
x: The x translation. -
y: The y translation. -
z: The z translation.
See also
- #setTranslation()
-
-
translate
public void translate(float x, float y) -
setTranslation
public void setTranslation(float x, float y, float z) Sets the current transform to be the specified translation. This replaces the current transform with the given translation whereas
#translate()adds additional translation to the existing translation.Parameters
-
x: The x translation. -
y: The y translation. -
z: The z translation.
See also
- #translate()
-
-
setTranslation
public void setTranslation(float x, float y) -
scale
public void scale(float x, float y, float z) Scales the current transform by the provide scale factors. Not to be confused with
#setScale()which replaces the transform.Note: If
#isSupported()is false, then this may throw a Runtime Exception.Parameters
-
x: The x-scale factor -
y: The y-scale factor -
z: The z-scale factor
See also
- #setScale()
-
-
scale
public void scale(float x, float y) -
getInverse
Gets the inverse transformation for this transform.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Returns
The inverse transform.
Deprecated
Use
#getInverse(com.codename1.ui.Transform)instead. -
getInverse
- Throws:
Transform.NotInvertibleException
-
invert
- Throws:
Transform.NotInvertibleException
-
setTransform
Sets the current transform to be identical to the provided transform.
Note: If
#isSupported()is false, then this will may throw a Runtime Exception.Parameters
t: A transform to copy into the current transform.
-
concatenate
Sets the current transform to be the concatenation of the current transform and the provided transform.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Parameters
t: The transform to concatenate to this one.
-
setPerspective
public void setPerspective(float fovy, float aspect, float zNear, float zFar) Sets the transform to be the specified perspective transformation.
Note: If
#isPerspectiveSupported()is false, then this will throw a Runtime Exception.Parameters
-
fovy: Y-field of view angle. -
aspect: Apspect ratio of the view window. -
zNear: Nearest visible z-coordinate. -
zFar: Farthest visible z-coordinate.
See also
- #makePerspective()
-
-
setAffine
public void setAffine(double m00, double m10, double m01, double m11, double m02, double m12) -
setOrtho
public void setOrtho(float left, float right, float bottom, float top, float near, float far) Sets the transform to be the specified orthogonal view.
Note: If
#isPerspectiveSupported()is false, then this will throw a Runtime Exception.Parameters
-
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-coordinate -
far: Farthest visible z-coordinate
-
-
setCamera
public 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.
Note: If
#isPerspectiveSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
-
-
transformPoints
public void transformPoints(int pointSize, float[] in, int srcPos, float[] out, int destPos, int numPoints) Transforms a set of points using the current transform.
Parameters
-
pointSize: The size of the points to transform (2 or 3) -
in: Input array of points. -
srcPos: Start position in input array -
out: Output array of points -
destPos: Start position in output array -
numPoints: Number of points to transform.
-
-
transformPoint
public float[] transformPoint(float[] point) Transforms a provided point.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Parameters
point: 2 or 3 element array representing either an (x,y) or (x,y,z) tuple.
Returns
A 3-element array representing transformed (x,y,z) tuple.
-
transformPoint
public void transformPoint(float[] in, float[] out) Transforms a provided point and places the result in the provided array.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Parameters
-
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.
-
-
getNativeTransform
Gets the native transform object. This object is implementation dependent so this method should really only be used by the implementation.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Returns
The native transform object.
-
copy
Creates a copy of the current transform.
Note: If
#isSupported()is false, then this will throw a Runtime Exception.Returns
A copy of the current transform.
-
equals
-
equals
-
hashCode
-