Transform class
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; } }
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; }
Constructors
new Transform() #
Constructs a new transform with a vector at the origin and no rotation.
Transform() : position = new Vector(), rotation = new Matrix22();
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.
docs inherited from Object
bool operator ==(other) { return position == other.position && rotation == other.rotation; }