Beispiel #1
0
 @Override
 public boolean equals(Object obj) {
   if (obj == null) return false;
   if (obj instanceof Vector) {
     Vector vec = (Vector) obj;
     return this.x() == vec.x() && this.y() == vec.y() && this.z() == vec.z();
   } else {
     return false;
   }
 }
Beispiel #2
0
 /**
  * Returns the euler angles from position 1 to position 2.
  *
  * <p>The returned vector has Y for yaw, and X for pitch. Measurements are in radians.
  *
  * @param pos1 Where we are
  * @param pos2 Where to look at
  */
 public static Vector getRotations(Vector pos1, Vector pos2) {
   Vector diff = pos2.minus(pos1);
   diff.normalize();
   double x = diff.x();
   double y = diff.y();
   double z = diff.z();
   double d0 = x;
   double d1 = y;
   double d2 = z;
   double d3 = (double) MathHelper.sqrt_double(d0 * d0 + d2 * d2);
   double rotY = Math.atan2(d2, d0) - Math.PI / 2;
   double rotX = -Math.atan2(d1, d3);
   double rotZ = 0;
   return new Vector(rotX, rotY, rotZ);
 }
Beispiel #3
0
 public static Vector reflect(Vector vec, Vector normal) {
   return vec.reflect(normal);
 }
Beispiel #4
0
 /**
  * <strong>Assuming</strong> this vector represents rectangular coordinates, returns the rotations
  * (in radians) for this vector.
  *
  * <p>Does not modify this vector.
  */
 public Vector toSpherical() {
   return Vector.getRotations(Vector.ZERO, this);
 }
Beispiel #5
0
 /**
  * Returns this vector reflected across the given normal. Does not modify this vector or the
  * normal.
  *
  * @param normal Must be normalized
  */
 public Vector reflect(Vector normal) {
   if (normal.sqrMagnitude() != 1)
     throw new IllegalArgumentException("Normal vector must be normalized");
   return this.minus(normal.times(2).times(this.dot(normal)));
 }
Beispiel #6
0
 /**
  * <strong>Assuming</strong> this vector represents spherical coordinates (in radians), returns a
  * unit vector in Cartesian space which has the rotations of this vector.
  *
  * <p>Does not modify this vector.
  */
 public Vector toRectangular() {
   return Vector.fromDirection(this);
 }
Beispiel #7
0
 /**
  * Returns the cross product of the given vector. This creates a new vector.
  *
  * @param vec The vector to cross with
  */
 public Vector cross(Vector vec) {
   return cross(vec.x(), vec.y(), vec.z());
 }
Beispiel #8
0
 /**
  * Add the given vector to this vector.
  *
  * @param vec The vector to add
  * @return this
  */
 public Vector add(Vector vec) {
   return add(vec.x(), vec.y(), vec.z());
 }
Beispiel #9
0
 /**
  * Get the square distance from the given vector.
  *
  * @param vec The other vector
  */
 public double sqrDist(Vector vec) {
   return sqrDist(vec.x(), vec.y(), vec.z());
 }
Beispiel #10
0
 /**
  * Get the dot product with the given vector.
  *
  * @param vec The other vector
  */
 public double dot(Vector vec) {
   return dot(vec.x(), vec.y(), vec.z());
 }
Beispiel #11
0
 /**
  * Creates a new vector from this vector minus the given vector.
  *
  * @param vec Other vector
  */
 public Vector minus(Vector vec) {
   return minus(vec.x(), vec.y(), vec.z());
 }
Beispiel #12
0
 /**
  * Subtract the given vector from this vector.
  *
  * @param vec The reduction vector
  * @return this
  */
 public Vector subtract(Vector vec) {
   return subtract(vec.x(), vec.y(), vec.z());
 }
Beispiel #13
0
 /**
  * Creates a new vector from the sum of this vector and the given vector.
  *
  * @param vec Vector for sum
  */
 public Vector plus(Vector vec) {
   return plus(vec.x(), vec.y(), vec.z());
 }
Beispiel #14
0
 public static Vector getEyePos(Entity entity) {
   Vector pos = getEntityPos(entity);
   pos.setY(pos.y() + entity.getEyeHeight());
   return pos;
 }
Beispiel #15
0
 /**
  * Returns the angle between the other vector, in radians. (result is ranged 0-PI).
  *
  * @param vec Other vector
  */
 public double angle(Vector vec) {
   double dot = dot(vec);
   return Math.acos(dot / (this.magnitude() * vec.magnitude()));
 }
Beispiel #16
0
 /** Create a unit vector from the given euler angles. Measurements should be in radians. */
 public static Vector fromDirection(Vector euler) {
   return fromYawPitch(euler.y(), euler.x());
 }
Beispiel #17
0
 /**
  * Set this vector to the given vector.
  *
  * @param vec Vector to set to
  * @return this
  */
 public Vector set(Vector vec) {
   set(vec.x(), vec.y(), vec.z());
   return this;
 }