Example #1
0
 public void draw(Graphics g, Screen s) {
   int x = s.translateXToScreen(location.xInt());
   int y = s.translateYToScreen(location.yInt());
   if (team != null)
     draw(g, x, y, angle.getValue(), sightAngle.getValue(), 1, (int) (team.getByte()), kills);
   else draw(g, x, y, angle.getValue(), sightAngle.getValue(), 1, -1, kills);
 }
Example #2
0
  @Test
  public void givenLocationInAngle_CanRetrieveTheLongitude() {
    Angle latitude = Angle.fromDegrees(39.54);
    Angle longitude = Angle.fromDegrees(-54.76);
    Coordinates location = Coordinates.locatedAt(latitude, longitude);

    assertThat(location.getLongitude()).isEqualTo(longitude);
  }
  /**
   * Returns a Quaternion created from latitude and longitude rotations. Latitude and longitude can
   * be extracted from a Quaternion by calling {@link #getLatLon}.
   *
   * @param latitude Angle rotation of latitude.
   * @param longitude Angle rotation of longitude.
   * @return Quaternion representing combined latitude and longitude rotation.
   */
  public static Quaternion fromLatLon(Angle latitude, Angle longitude) {
    if (latitude == null || longitude == null) {
      throw new IllegalArgumentException("Angle Is Null");
    }

    double clat = latitude.cosHalfAngle();
    double clon = longitude.cosHalfAngle();
    double slat = latitude.sinHalfAngle();
    double slon = longitude.sinHalfAngle();

    // The order in which the lat/lon angles are applied is critical. This can be thought of as
    // multiplying two
    // quaternions together, one for each lat/lon angle. Like matrices, quaternions affect vectors
    // in reverse
    // order. For example, suppose we construct a quaternion
    //     Q = QLat * QLon
    // then transform some vector V by Q. This can be thought of as first transforming V by QLat,
    // then QLon. This
    // means that the order of quaternion multiplication is the reverse of the order in which the
    // lat/lon angles
    // are applied.
    //
    // The ordering below refers to order in which angles are applied.
    //
    // QLat = (0,    slat, 0, clat)
    // QLon = (slon, 0,    0, clon)
    //
    // 1. LatLon Ordering
    // (QLon * QLat)
    // qw = clat * clon;
    // qx = clat * slon;
    // qy = slat * clon;
    // qz = slat * slon;
    //
    // 2. LonLat Ordering
    // (QLat * QLon)
    // qw = clat * clon;
    // qx = clat * slon;
    // qy = slat * clon;
    // qz = - slat * slon;
    //

    double qw = clat * clon;
    double qx = clat * slon;
    double qy = slat * clon;
    double qz = 0.0 - slat * slon;

    return new Quaternion(qx, qy, qz, qw);
  }
Example #4
0
 public final void incDegrees(double value) {
   _degrees += value;
   if (_degrees > 360) {
     _degrees -= 360;
   }
   _modelviewMatrix.copyValue(
       MutableMatrix44D.createRotationMatrix(Angle.fromDegrees(_degrees), new Vector3D(0, 0, -1)));
 }
  public final Angle getRotationY() {
    double radians =
        Math.atan2(
            (2.0 * this.y * this.w) - (2.0 * this.x * this.z),
            1.0 - (2.0 * this.y * this.y) - (2.0 * this.z * this.z));
    if (Double.isNaN(radians)) return null;

    return Angle.fromRadians(radians);
  }
  private static Quaternion fromAxisAngle(
      Angle angle, double axisX, double axisY, double axisZ, boolean normalize) {
    if (angle == null) {
      throw new IllegalArgumentException("Angle Is Null");
    }

    if (normalize) {
      double length = Math.sqrt((axisX * axisX) + (axisY * axisY) + (axisZ * axisZ));
      if (!isZero(length) && (length != 1.0)) {
        axisX /= length;
        axisY /= length;
        axisZ /= length;
      }
    }

    double s = angle.sinHalfAngle();
    double c = angle.cosHalfAngle();
    return new Quaternion(axisX * s, axisY * s, axisZ * s, c);
  }
  public final Angle getAngle() {
    double w = this.w;

    double length = this.getLength();
    if (!isZero(length) && (length != 1.0)) w /= length;

    double radians = 2.0 * Math.acos(w);
    if (Double.isNaN(radians)) return null;

    return Angle.fromRadians(radians);
  }
Example #8
0
  public static int[] draw(Graphics g, byte[] data, Screen s) {
    int client = (int) data[8];
    int realX = Util.getInt(data[0], data[1]);
    int realY = Util.getInt(data[2], data[3]);
    int x = s.translateXToScreen(realX);
    int y = s.translateYToScreen(realY);
    int kills = Util.getInt(data[9], data[10]);
    draw(
        g,
        x,
        y,
        Angle.getDouble(data[4]),
        Angle.getDouble(data[5]),
        (int) data[6],
        (int) data[7],
        kills);
    int[] retur = {client, realX, realY, kills, (int) data[7]};

    return retur;
  }
  /**
   * Returns a Quaternion created from three Euler angle rotations. The angles represent rotation
   * about their respective unit-axes. The angles are applied in the order X, Y, Z. Angles can be
   * extracted by calling {@link #getRotationX}, {@link #getRotationY}, {@link #getRotationZ}.
   *
   * @param x Angle rotation about unit-X axis.
   * @param y Angle rotation about unit-Y axis.
   * @param z Angle rotation about unit-Z axis.
   * @return Quaternion representation of the combined X-Y-Z rotation.
   */
  public static Quaternion fromRotationXYZ(Angle x, Angle y, Angle z) {
    if (x == null || y == null || z == null) {
      throw new IllegalArgumentException("Angle Is Null");
    }

    double cx = x.cosHalfAngle();
    double cy = y.cosHalfAngle();
    double cz = z.cosHalfAngle();
    double sx = x.sinHalfAngle();
    double sy = y.sinHalfAngle();
    double sz = z.sinHalfAngle();

    // The order in which the three Euler angles are applied is critical. This can be thought of as
    // multiplying
    // three quaternions together, one for each Euler angle (and corresponding unit axis). Like
    // matrices,
    // quaternions affect vectors in reverse order. For example, suppose we construct a quaternion
    //     Q = (QX * QX) * QZ
    // then transform some vector V by Q. This can be thought of as first transforming V by QZ, then
    // QY, and
    // finally by QX. This means that the order of quaternion multiplication is the reverse of the
    // order in which
    // the Euler angles are applied.
    //
    // The ordering below refers to the order in which angles are applied.
    //
    // QX = (sx, 0,  0,  cx)
    // QY = (0,  sy, 0,  cy)
    // QZ = (0,  0,  sz, cz)
    //
    // 1. XYZ Ordering
    // (QZ * QY * QX)
    // qw = (cx * cy * cz) + (sx * sy * sz);
    // qx = (sx * cy * cz) - (cx * sy * sz);
    // qy = (cx * sy * cz) + (sx * cy * sz);
    // qz = (cx * cy * sz) - (sx * sy * cz);
    //
    // 2. ZYX Ordering
    // (QX * QY * QZ)
    // qw = (cx * cy * cz) - (sx * sy * sz);
    // qx = (sx * cy * cz) + (cx * sy * sz);
    // qy = (cx * sy * cz) - (sx * cy * sz);
    // qz = (cx * cy * sz) + (sx * sy * cz);
    //

    double qw = (cx * cy * cz) + (sx * sy * sz);
    double qx = (sx * cy * cz) - (cx * sy * sz);
    double qy = (cx * sy * cz) + (sx * cy * sz);
    double qz = (cx * cy * sz) - (sx * sy * cz);

    return new Quaternion(qx, qy, qz, qw);
  }
Example #10
0
 public byte[] getData() {
   byte[] coord = location.getBytes();
   byte[] bytekills = Util.getBytes(kills);
   byte teamByte;
   if (team == null) teamByte = (byte) -1;
   else teamByte = team.getByte();
   return new byte[] {
     coord[0],
     coord[1],
     coord[2],
     coord[3],
     angle.getByte(),
     sightAngle.getByte(),
     getState(),
     teamByte,
     client,
     bytekills[0],
     bytekills[1]
   };
 }
 public static double degreesToRadians(int d, int m, int s) {
   Angle a = Angle.fromDegrees(d, m, s);
   return a.radians();
 }
 public static int radiansToSeconds(double r) {
   Angle a = Angle.fromRadians(r);
   return a.seconds();
 }
 public static int radiansToMinutes(double r) {
   Angle a = Angle.fromRadians(r);
   return a.minutes();
 }
 public static int radiansToDegrees(double r) {
   Angle a = Angle.fromRadians(r);
   return a.degrees();
 }
Example #15
0
package model.physicsMIT;
  public final Angle getRotationZ() {
    double radians = Math.asin((2.0 * this.x * this.y) + (2.0 * this.z * this.w));
    if (Double.isNaN(radians)) return null;

    return Angle.fromRadians(radians);
  }
Example #17
0
package physics;
Example #18
0
  @Test
  public void givenNumericLocation_CanRetrieveTheLatitude() {
    Coordinates location = Coordinates.locatedAt(45.34, -73.45);

    assertThat(location.getLatitude()).isEqualTo(Angle.fromDegrees(45.34));
  }
 public FieldOfView() {
   this.area = new Circle(new Vec2(), 1.0f);
   this.up = Angle.fromRad(0);
 }
Example #20
0
 public final Matrix getInitialTransformation() {
   return Matrix.Factory.newRotateMatrix(
       Angle.get(getRotateX()), Angle.get(getRotateY()), Angle.get(getRotateZ()));
 }
Example #21
0
 public void lookAt(Coordinate c) {
   sightAngle.set(location.getAngle(c));
 }