Transform class
A transform is a translation and a rotation. It represents the position and orientation of rigid frames.
class Transform { /** The translation caused by a transform. */ final Vector position; /** A matrix representing a rotation. */ final Matrix22 rotation; /** * Constructs a new transform with a vector at the origin and no rotation. */ Transform() : position = new Vector(), rotation = new Matrix22(); /** * Constructs a new transform equal to the given transform. */ Transform.copy(Transform other) : position = new Vector.copy(other.position), rotation = new Matrix22.copy(other.rotation); bool operator ==(other) { return position == other.position && rotation == other.rotation; } /** * Sets this transform with the given position and rotation. */ void setFromPositionAndRotation(Vector argPosition, Matrix22 argRotation) { position.setFrom(argPosition); rotation.setFrom(argRotation); } /** * Sets this transform equal to the given transform. */ void setFrom(Transform other) { position.setFrom(other.position); rotation.setFrom(other.rotation); } /** * Multiply the given transform and given vector and return a new Vector with * the result. */ static Vector mul(Transform T, Vector v) { return new Vector(T.position.x + T.rotation.col1.x * v.x + T.rotation.col2.x * v.y, T.position.y + T.rotation.col1.y * v.x + T.rotation.col2.y * v.y); } /** * Multiplies the given transform and the given vector and places the result * in the given out parameter. */ static void mulToOut(Transform transform, Vector vector, Vector out) { assert(out != null); num tempY = transform.position.y + transform.rotation.col1.y * vector.x + transform.rotation.col2.y * vector.y; out.x = transform.position.x + transform.rotation.col1.x * vector.x + transform.rotation.col2.x * vector.y; out.y = tempY; } static void mulTransToOut(Transform T, Vector v, Vector out) { num v1x = v.x - T.position.x; num v1y = v.y - T.position.y; Vector b = T.rotation.col1; Vector b1 = T.rotation.col2; num tempy = v1x * b1.x + v1y * b1.y; out.x = v1x * b.x + v1y * b.y; out.y = tempy; } }
Constructors
new Transform() #
Constructs a new transform with a vector at the origin and no rotation.
Transform() : position = new Vector(), rotation = new Matrix22();
Static Methods
Vector mul(Transform T, Vector v) #
Multiply the given transform and given vector and return a new Vector with the result.
static Vector mul(Transform T, Vector v) { return new Vector(T.position.x + T.rotation.col1.x * v.x + T.rotation.col2.x * v.y, T.position.y + T.rotation.col1.y * v.x + T.rotation.col2.y * v.y); }
void mulToOut(Transform transform, Vector vector, Vector out) #
Multiplies the given transform and the given vector and places the result in the given out parameter.
static void mulToOut(Transform transform, Vector vector, Vector out) { assert(out != null); num tempY = transform.position.y + transform.rotation.col1.y * vector.x + transform.rotation.col2.y * vector.y; out.x = transform.position.x + transform.rotation.col1.x * vector.x + transform.rotation.col2.x * vector.y; out.y = tempY; }
void mulTransToOut(Transform T, Vector v, Vector out) #
static void mulTransToOut(Transform T, Vector v, Vector out) { num v1x = v.x - T.position.x; num v1y = v.y - T.position.y; Vector b = T.rotation.col1; Vector b1 = T.rotation.col2; num tempy = v1x * b1.x + v1y * b1.y; out.x = v1x * b.x + v1y * b.y; out.y = tempy; }
Properties
final Type runtimeType #
A representation of the runtime type of the object.
external Type get runtimeType;
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode
method as well to maintain consistency.
bool operator ==(other) { return position == other.position && rotation == other.rotation; }
Methods
int hashCode() #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==
. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode
it should override the
equality operator as well to maintain consistency.
external int hashCode();
noSuchMethod(String name, List args) #
noSuchMethod
is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod
. If noSuchMethod
returns a value, that value becomes the result of the original
invocation.
The default behavior of noSuchMethod
is to throw a
noSuchMethodError
.
external Dynamic noSuchMethod(String name, List args);
const Object() #
Creates a new Object
instance.
Object
instances have no meaningful state, and are only useful
through their identity. An Object
instance is equal to itself
only.
const Object();
void setFrom(Transform other) #
Sets this transform equal to the given transform.
void setFrom(Transform other) { position.setFrom(other.position); rotation.setFrom(other.rotation); }
void setFromPositionAndRotation(Vector argPosition, Matrix22 argRotation) #
Sets this transform with the given position and rotation.
void setFromPositionAndRotation(Vector argPosition, Matrix22 argRotation) { position.setFrom(argPosition); rotation.setFrom(argRotation); }
String toString() #
Returns a string representation of this object.
external String toString();
new Transform() #
Constructs a new transform with a vector at the origin and no rotation.
Transform() : position = new Vector(), rotation = new Matrix22();