示例#1
0
  public Matrix4x4 lookAt(Vector3 eye, Vector3 center, Vector3 up) {
    Vector3 forward = (center.subtract(eye)).normalized();
    Vector3 side = Vector3.crossProduct(forward, up).normalized();
    Vector3 upVector = Vector3.crossProduct(side, forward);

    Matrix4x4 m = new Matrix4x4(1);

    m.set_value(0, 0, side.x());
    m.set_value(1, 0, side.y());
    m.set_value(2, 0, side.z());
    m.set_value(3, 0, 0.0f);
    m.set_value(0, 1, upVector.x());
    m.set_value(1, 1, upVector.y());
    m.set_value(2, 1, upVector.z());
    m.set_value(3, 1, 0.0f);
    m.set_value(0, 2, -forward.x());
    m.set_value(1, 2, -forward.y());
    m.set_value(2, 2, -forward.z());
    m.set_value(3, 2, 0.0f);
    m.set_value(0, 3, 0.0f);
    m.set_value(1, 3, 0.0f);
    m.set_value(2, 3, 0.0f);
    m.set_value(3, 3, 1.0f);

    Matrix4x4 m2 = this.multiply(m);
    m2.translate(-eye.x(), -eye.y(), -eye.z());
    return m2;
  }
示例#2
0
 public void rotate(double angle, Vector3 vector) {
   rotate(angle, vector.x(), vector.y(), vector.z());
 }
示例#3
0
 public void translate(Vector3 translate_vector) {
   translate(translate_vector.x(), translate_vector.y(), translate_vector.z());
 }
示例#4
0
 public void scale(Vector3 scale_vector) {
   scale(scale_vector.x(), scale_vector.y(), scale_vector.z());
 }
示例#5
0
 public Vector3 multiply(Vector3 vector) {
   double x, y, z, w;
   if (this.flagBits == Mathematics.mat_type_Identity) {
     return vector;
   } else if (this.flagBits == Mathematics.mat_type_Translation) {
     return new Vector3(
         vector.x() + this.mat4[12], vector.y() + this.mat4[13], vector.z() + this.mat4[14]);
   } else if (this.flagBits == (Mathematics.mat_type_Translation | Mathematics.mat_type_Scale)) {
     return new Vector3(
         vector.x() * this.mat4[0] + this.mat4[12],
         vector.y() * this.mat4[5] + this.mat4[13],
         vector.z() * this.mat4[10] + this.mat4[14]);
   } else if (this.flagBits == Mathematics.mat_type_Scale) {
     return new Vector3(
         vector.x() * this.mat4[0], vector.y() * this.mat4[5], vector.z() * this.mat4[10]);
   } else {
     x =
         vector.x() * this.mat4[0]
             + vector.y() * this.mat4[4]
             + vector.z() * this.mat4[8]
             + this.mat4[12];
     y =
         vector.x() * this.mat4[1]
             + vector.y() * this.mat4[5]
             + vector.z() * this.mat4[9]
             + this.mat4[13];
     z =
         vector.x() * this.mat4[2]
             + vector.y() * this.mat4[6]
             + vector.z() * this.mat4[10]
             + this.mat4[14];
     w =
         vector.x() * this.mat4[3]
             + vector.y() * this.mat4[7]
             + vector.z() * this.mat4[11]
             + this.mat4[15];
     if (w == 1.0f) return new Vector3(x, y, z);
     else return new Vector3(x / w, y / w, z / w);
   }
 }