示例#1
0
  static final boolean normalize(Vector3f v) {
    float len = v.length();

    if (len > 0) {
      len = 1.0f / len;
      v.x *= len;
      v.y *= len;
      v.z *= len;
      return true;
    }
    return false;
  }
示例#2
0
  static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) {
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();

    // Must compute normal
    v1.sub(p2, p1);
    v2.sub(p2, p3);
    normal.cross(v1, v2);
    normal.negate();

    float length = normal.length();

    if (length > 0) {
      length = 1 / length;
      normal.x *= length;
      normal.y *= length;
      normal.z *= length;
      return true;
    }
    return false;
  }