Vector3 class
class Vector3 { // Each vector is defined as the vector originating from (0,0) to the point // defined by these values. num x; num y; num z; Vector3([this.x = 0, this.y = 0, this.z = 0]); Vector3.copy(Vector3 argCopy) { x = argCopy.x; y = argCopy.y; z = argCopy.z; } bool operator ==(other) { return other is Vector3 && x == other.x && y == other.y && z == other.z; } /** Sets this vector equal to the given vector. */ Vector3 setFrom(Vector3 argVec) { x = argVec.x; y = argVec.y; z = argVec.z; return this; } /** Sets the vectors coordinate values to those given. */ Vector3 setCoords(num argX, num argY, num argZ) { x = argX; y = argY; z = argZ; return this; } Vector3 addLocal(Vector3 argVec) { x += argVec.x; y += argVec.y; z += argVec.z; return this; } Vector3 add(Vector3 argVec) => new Vector3(x + argVec.x, y + argVec.y, z + argVec.z); Vector3 subLocal(Vector3 argVec) { x -= argVec.x; y -= argVec.y; z -= argVec.z; return this; } Vector3 sub(Vector3 argVec) => new Vector3(x - argVec.x, y - argVec.y, z - argVec.z); Vector3 mulLocal(num argScalar) { x *= argScalar; y *= argScalar; z *= argScalar; return this; } Vector3 mul(num argScalar) => new Vector3(x * argScalar, y * argScalar, z * argScalar); Vector3 negateLocal() { x = -x; y = -y; z = -z; return this; } void setZero() { x = 0; y = 0; z = 0; } String toString() => "($x, $y, $z)"; static num dot(Vector3 a, Vector3 b) => a.x * b.x + a.y * b.y + a.z * b.z; static Vector3 cross(Vector3 a, Vector3 b) => new Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); static void crossToOut(Vector3 a, Vector3 b, Vector3 out) { final num tempy = a.z * b.x - a.x * b.z; final num tempz = a.x * b.y - a.y * b.x; out.x = a.y * b.z - a.z * b.y; out.y = tempy; out.z = tempz; } }
Static Methods
num dot(Vector3 a, Vector3 b) #
static num dot(Vector3 a, Vector3 b) => a.x * b.x + a.y * b.y + a.z * b.z;
Constructors
new Vector3([num x = 0, num y = 0, num z = 0]) #
Vector3([this.x = 0, this.y = 0, this.z = 0]);
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 other is Vector3 && x == other.x && y == other.y && z == other.z; }
Methods
Vector3 add(Vector3 argVec) #
Vector3 add(Vector3 argVec) => new Vector3(x + argVec.x, y + argVec.y, z + argVec.z);
Vector3 addLocal(Vector3 argVec) #
Vector3 addLocal(Vector3 argVec) { x += argVec.x; y += argVec.y; z += argVec.z; return this; }
Vector3 mul(num argScalar) #
Vector3 mul(num argScalar) => new Vector3(x * argScalar, y * argScalar, z * argScalar);
Vector3 mulLocal(num argScalar) #
Vector3 mulLocal(num argScalar) { x *= argScalar; y *= argScalar; z *= argScalar; return this; }
Vector3 setCoords(num argX, num argY, num argZ) #
Sets the vectors coordinate values to those given.
Vector3 setCoords(num argX, num argY, num argZ) { x = argX; y = argY; z = argZ; return this; }
Vector3 setFrom(Vector3 argVec) #
Sets this vector equal to the given vector.
Vector3 setFrom(Vector3 argVec) { x = argVec.x; y = argVec.y; z = argVec.z; return this; }
void setZero() #
void setZero() { x = 0; y = 0; z = 0; }
Vector3 sub(Vector3 argVec) #
Vector3 sub(Vector3 argVec) => new Vector3(x - argVec.x, y - argVec.y, z - argVec.z);
Vector3 subLocal(Vector3 argVec) #
Vector3 subLocal(Vector3 argVec) { x -= argVec.x; y -= argVec.y; z -= argVec.z; return this; }
String toString() #
Returns a string representation of this object.
docs inherited from Object
String toString() => "($x, $y, $z)";