Exemple #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;
   }
 }
Exemple #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);
 }
Exemple #3
0
 public static Vector reflect(Vector vec, Vector normal) {
   return vec.reflect(normal);
 }
Exemple #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);
 }
Exemple #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)));
 }
Exemple #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);
 }
Exemple #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());
 }
Exemple #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());
 }
Exemple #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());
 }
Exemple #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());
 }
Exemple #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());
 }
Exemple #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());
 }
Exemple #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());
 }
Exemple #14
0
 public static Vector getEyePos(Entity entity) {
   Vector pos = getEntityPos(entity);
   pos.setY(pos.y() + entity.getEyeHeight());
   return pos;
 }
Exemple #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()));
 }
Exemple #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());
 }
Exemple #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;
 }