// // Resumen: // Creates a rotation matrix. public static MyMatrix4x4 Rotate(MyQuatern q) { // Manipulacion algebraica de p' = q*p*q^-1 // Cos(angulo/2) + Sin(angulo)(ijk) // Vec3 angel = q.eulerAngles; /* * m00 = 1 - 2 * qy2 - 2 * qz2 | m01 = 2 * qx * qy - 2 * qz * qw | m02 = 2 * qx * qz + 2 * qy * qw * m10 = 2 * qx * qy + 2 * qz * qw | m11 = 1 - 2 * qx2 - 2 * qz2 | m12 = 2 * qy * qz - 2 * qx * qw * m20 = 2 * qx * qz - 2 * qy * qw | m21 = 2 * qy * qz + 2 * qx * qw | m22 = 1 - 2 * qx2 - 2 * qy2 */ MyMatrix4x4 newM = MyMatrix4x4.identity; newM.m00 = 1 - 2 * (q.y * q.y) - 2 * (q.z * q.z); newM.m01 = 2 * q.x * q.y - 2 * q.z * q.w; newM.m02 = 2 * q.x * q.z + 2 * q.y * q.w; newM.m10 = 2 * q.x * q.y + 2 * q.z * q.w; newM.m11 = 1 - 2 * (q.x * q.x) - 2 * (q.z * q.z); newM.m12 = 2 * q.y * q.z - 2 * q.x * q.w; newM.m20 = 2 * q.x * q.z - 2 * q.y * q.w; newM.m21 = 2 * q.y * q.z + 2 * q.x * q.w; newM.m22 = 1 - 2 * (q.x * q.x) - 2 * (q.y * q.y); return(newM); }
void FixedUpdate() { switch (ejercicio) { case Funciones.Uno: Vector3Debugger.EnableEditorView("primero"); Vector3Debugger.DisableEditorView("segundo"); Vector3Debugger.DisableEditorView("tercero"); // --------------- MyQuatern miQuat1 = MyQuatern.Euler(0, valor, 0); ejer1 = (miQuat1 * new Vec3(ejer1)); // --------------- Vector3Debugger.UpdatePosition("primero", ejer1); break; case Funciones.Dos: Vector3Debugger.EnableEditorView("segundo"); Vector3Debugger.DisableEditorView("primero"); Vector3Debugger.DisableEditorView("tercero"); // --------------- MyQuatern miQuat2 = MyQuatern.Euler(0, valor, 0); ejer2[1] = (miQuat2 * new Vec3(ejer2[1])); ejer2[2] = (miQuat2 * new Vec3(ejer2[2])); ejer2[3] = (miQuat2 * new Vec3(ejer2[3])); // --------------- Vector3Debugger.UpdatePositionsSecuence("segundo", ejer2); break; case Funciones.Tres: Vector3Debugger.EnableEditorView("tercero"); Vector3Debugger.DisableEditorView("primero"); Vector3Debugger.DisableEditorView("segundo"); // --------------- MyQuatern miQuat3 = MyQuatern.Euler(valor * 1.5f, valor * 1.5f, 0); ejer3[1] = (miQuat3 * new Vec3(ejer3[1])); ejer3[3] = (MyQuatern.Inverse(miQuat3) * new Vec3(ejer3[3])); // --------------- Vector3Debugger.UpdatePositionsSecuence("tercero", ejer3); break; } }
// // Resumen: // Creates a translation, rotation and scaling matrix. public static MyMatrix4x4 TRS(Vec3 pos, MyQuatern q, Vec3 s) { MyMatrix4x4 translate = MyMatrix4x4.Translate(pos); MyMatrix4x4 rotate = MyMatrix4x4.Rotate(q); MyMatrix4x4 scale = MyMatrix4x4.Scale(s); MyMatrix4x4 newM = translate * rotate * scale; return(newM); }
// // Resumen: // Sets this matrix to a translation, rotation and scaling matrix. public void SetTRS(Vec3 pos, MyQuatern q, Vec3 s) { this = MyMatrix4x4.TRS(pos, q, s); }