示例#1
0
 public Number3D lerp(Number3D from, Number3D to, float amount) {
   Number3D out = new Number3D();
   out.x = from.x + (to.x - from.x) * amount;
   out.y = from.y + (to.y - from.y) * amount;
   out.z = from.z + (to.z - from.z) * amount;
   return out;
 }
示例#2
0
 public Number3D cross(Number3D w) {
   _temp.setAllFrom(this);
   x = w.y * _temp.z - w.z * _temp.y;
   y = w.z * _temp.x - w.x * _temp.z;
   z = w.x * _temp.y - w.y * _temp.x;
   return this;
 }
示例#3
0
  public static Number3D getAxisVector(Axis axis) {
    Number3D axisVector = new Number3D();

    switch (axis) {
      case X:
        axisVector.setAll(1, 0, 0);
        break;
      case Y:
        axisVector.setAll(0, 1, 0);
        break;
      case Z:
        axisVector.setAll(0, 0, 1);
        break;
    }

    return axisVector;
  }
示例#4
0
  public void rotateZ(float angle) {
    float cosRY = FloatMath.cos(angle);
    float sinRY = FloatMath.sin(angle);

    _temp.setAll(this.x, this.y, this.z);

    this.x = (_temp.x * cosRY) - (_temp.y * sinRY);
    this.y = (_temp.x * sinRY) + (_temp.y * cosRY);
  }
示例#5
0
  /**
   * http://ogre.sourcearchive.com/documentation/1.4.5/classOgre_1_1Vector3_eeef4472ad0c4d5f34a038a9f2faa819.html#eeef4472ad0c4d5f34a038a9f2faa819
   *
   * @param direction
   * @return
   */
  public Quaternion getRotationTo(Number3D direction) {
    // Based on Stan Melax's article in Game Programming Gems
    Quaternion q = new Quaternion();
    // Copy, since cannot modify local
    Number3D v0 = this;
    Number3D v1 = direction;
    v0.normalize();
    v1.normalize();

    float d = Number3D.dot(v0, v1);
    // If dot == 1, vectors are the same
    if (d >= 1.0f) {
      q.setIdentity();
    }
    if (d < 0.000001f - 1.0f) {
      // Generate an axis
      Number3D axis = Number3D.cross(Number3D.getAxisVector(Axis.X), this);
      if (axis.length() == 0) // pick another if colinear
      axis = Number3D.cross(Number3D.getAxisVector(Axis.Y), this);
      axis.normalize();
      q.fromAngleAxis(MathUtil.radiansToDegrees(MathUtil.PI), axis);
    } else {
      float s = FloatMath.sqrt((1 + d) * 2);
      float invs = 1f / s;

      Number3D c = Number3D.cross(v0, v1);

      q.x = c.x * invs;
      q.y = c.y * invs;
      q.z = c.z * invs;
      q.w = s * 0.5f;
      q.normalize();
    }
    return q;
  }