public class Transform
- Object
- 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 types
class Transform.NotInvertibleException |
Fields
public static final int TYPE_UNKNOWN = -1 | Constant for transform type. |
public static final int TYPE_IDENTITY = 0 | Constant for transform type. |
public static final int TYPE_TRANSLATION = 1 | Constant for transform type. |
public static final int TYPE_SCALE = 2 | Constant for transform type. |
Methods
Inherited methods
Field details
TYPE_UNKNOWN
public static final int TYPE_UNKNOWN = -1TYPE_IDENTITY
public static final int TYPE_IDENTITY = 0TYPE_TRANSLATION
public static final int TYPE_TRANSLATION = 1TYPE_SCALE
public static final int TYPE_SCALE = 2Method details
IDENTITY
public static Transform IDENTITY()#identity().identity
public static Transform identity()makeIdentity
public static Transform makeIdentity()Returns
makeRotation
public static Transform makeRotation(float angle, float x, float y, float z)Makes a new rotation transformation.
Note: If #isSupported() is false, then this will throw a Runtime Exception.
Parameters
anglefloat- The angle of the rotation in radians.
xfloat- The x component of the vector around which the rotation occurs.
yfloat- The y component of the vector around which the rotation occurs.
zfloat- The z component of the vector around which the rotation occurs.
Returns
Throws
RuntimeException- If
#isSupported()is false.
makeRotation
public static Transform makeRotation(float angle, float x, float y)makeTranslation
public static Transform makeTranslation(float x, float y, float z)Parameters
xfloat- The x component of the translation.
yfloat- The y component of the translation.
zfloat- The z component of the translation.
Returns
makeTranslation
public static Transform makeTranslation(float x, float y)makeScale
public static Transform makeScale(float x, float y, float z)Parameters
xfloat- The x scale factor.
yfloat- The y scale factor.
zfloat- The z scale factor.
Returns
makeScale
public static Transform makeScale(float x, float y)Parameters
xfloat- Factor to scale in x axis.
yfloat- Factor to scale by in y axis.
Returns
makeAffine
public static Transform makeAffine(double m00, double m10, double m01, double m11, double m02, double m12)makePerspective
public static Transform makePerspective(float fovy, float aspect, float zNear, float zFar)Makes a new perspective transform.
Note: If #isPerspectiveSupported() is false, then this will throw a Runtime Exception.
Parameters
fovyfloat- The y field of view angle.
aspectfloat- The aspect ratio.
zNearfloat- The nearest visible z coordinate.
zFarfloat- The farthest z coordinate.
Returns
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
leftfloat- x-coordinate that is the left edge of the view.
rightfloat- The x-coordinate that is the right edge of the view.
bottomfloat- The y-coordinate that is the bottom edge of the view.
topfloat- The y-coordinate that is the top edge of the view.
nearfloat- The nearest visible z-coordinate.
farfloat- The farthest visible z-coordinate.
Returns
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
eyeXfloat- The x-coordinate of the camera’s eye.
eyeYfloat- The y-coordinate of the camera’s eye.
eyeZfloat- The z-coordinate of the camera’s eye.
centerXfloat- The center x coordinate of the view.
centerYfloat- The center y coordinate of the view.
centerZfloat- The center z coordinate of the view.
upXfloat- The x-coordinate of the up vector for the camera.
upYfloat- The y-coordinate of the up vector for the camera.
upZfloat- The z-coordinate of the up vector for the camera.
Returns
isSupported
public static boolean isSupported()Returns
isPerspectiveSupported
public static boolean isPerspectiveSupported()Returns
isIdentity
public boolean isIdentity()Returns
isTranslation
public boolean isTranslation()Returns
getScaleX
public float getScaleX()Returns
See also
#isScale()#setScale()
getScaleY
public float getScaleY()See also
#isScale()#setScale()
getScaleZ
public float getScaleZ()See also
#isScale()#setScale()
getTranslateX
public float getTranslateX()Returns
See also
#isTranslation()#setTranslation()#translate()
getTranslateY
public float getTranslateY()Returns
See also
#isTranslation()#setTranslation()#translate()
getTranslateZ
public float getTranslateZ()Returns
See also
#isTranslation()#setTranslation()#translate()
isScale
public boolean isScale()Returns
setScale
public void setScale(float x, float y, float z)Parameters
xfloat- x-axis scaling
yfloat- y-axis scaling
zfloat- z-axis scaling
setScale
public void setScale(float x, float y)Parameters
xfloat- x-axis scaling.
yfloat- 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
anglefloat- The angle to rotate in radians.
xfloat- The x-coordinate of the vector around which to rotate.
yfloat- The y-coordinate of the vector around which to rotate.
zfloat- The z-coordinate of the vector around which to rotate.
See also
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
anglefloat- The angle to rotate in radians.
xfloat- The x-coordinate of the vector around which to rotate.
yfloat- The y-coordinate of the vector around which to rotate.
zfloat- 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()toString
public String 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
xfloat- The x translation.
yfloat- The y translation.
zfloat- The z translation.
See also
#setTranslation()
translate
public void translate(float x, float y)setTranslation
public void setTranslation(float x, float y, float z)#translate() adds additional translation
to the existing translation.Parameters
xfloat- The x translation.
yfloat- The y translation.
zfloat- 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
xfloat- The x-scale factor
yfloat- The y-scale factor
zfloat- The z-scale factor
See also
#setScale()
scale
public void scale(float x, float y)getInverse
public Transform getInverse()#getInverse(com.codename1.ui.Transform) instead.Gets the inverse transformation for this transform.
Note: If #isSupported() is false, then this will throw a Runtime Exception.
Returns
getInverse
public void getInverse(Transform inverseOut)
throws Transform.NotInvertibleExceptioninvert
public void invert()
throws Transform.NotInvertibleExceptionsetTransform
public void setTransform(Transform t)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
tTransform- A transform to copy into the current transform.
concatenate
public void concatenate(Transform t)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
tTransform- 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
fovyfloat- Y-field of view angle.
aspectfloat- Apspect ratio of the view window.
zNearfloat- Nearest visible z-coordinate.
zFarfloat- 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
leftfloat- Left x-coord of view.
rightfloat- Right x-coord of view.
bottomfloat- Bottom y-coord of view.
topfloat- Top y-coord of view.
nearfloat- Nearest visible z-coordinate
farfloat- 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
eyeXfloat- The x-coordinate of the camera’s eye.
eyeYfloat- The y-coordinate of the camera’s eye.
eyeZfloat- The z-coordinate of the camera’s eye.
centerXfloat- The center x coordinate of the view.
centerYfloat- The center y coordinate of the view.
centerZfloat- The center z coordinate of the view.
upXfloat- The x-coordinate of the up vector for the camera.
upYfloat- The y-coordinate of the up vector for the camera.
upZfloat- 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)Parameters
pointSizeint- The size of the points to transform (2 or 3)
infloat[]- Input array of points.
srcPosint- Start position in input array
outfloat[]- Output array of points
destPosint- Start position in output array
numPointsint- 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
pointfloat[]- 2 or 3 element array representing either an (x,y) or (x,y,z) tuple.
Returns
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
infloat[]- A 2 or 3 element array representing either an (x,y) or (x,y,z) tuple.
outfloat[]- A 2 or 3 element array in which the transformed point will be stored. Should match the length of the in array.
getNativeTransform
public Object 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
copy
public Transform copy()Creates a copy of the current transform.
Note: If #isSupported() is false, then this will throw a Runtime Exception.
Returns
equals
public boolean equals(Transform t2)equals
public boolean equals(Object o)hashCode
public int hashCode()