Dart Documentationbox2d_consoleVector3

Vector3 class

A three dimensional vector.

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;
  }
}

Constructors

new Vector3([num x = 0, num y = 0, num z = 0]) #

Vector3([this.x = 0, this.y = 0, this.z = 0]);

new Vector3.copy(Vector3 argCopy) #

Vector3.copy(Vector3 argCopy) {
  x = argCopy.x;
  y = argCopy.y;
  z = argCopy.z;
}

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;

Vector3 cross(Vector3 a, Vector3 b) #

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);

void crossToOut(Vector3 a, Vector3 b, Vector3 out) #

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;
}

Properties

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

num x #

num x;

num y #

num y;

num z #

num z;

Operators

bool operator ==(other) #

The equality operator.

The default behavior for all Objects 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;
}

int hashCode() #

inherited from Object

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();

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 negateLocal() #

Vector3 negateLocal() {
  x = -x;
  y = -y;
  z = -z;
  return this;
}

noSuchMethod(String name, List args) #

inherited from Object

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() #

inherited from 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();

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)";

new Vector3([num x = 0, num y = 0, num z = 0]) #

Vector3([this.x = 0, this.y = 0, this.z = 0]);

new Vector3.copy(Vector3 argCopy) #

Vector3.copy(Vector3 argCopy) {
  x = argCopy.x;
  y = argCopy.y;
  z = argCopy.z;
}