public static Quat Slerping(Quat lhs, Quat rhs, float t) { t = Mathf.Clamp(t, 0.0f, 1.0f); Quat d = rhs * lhs.Inverse(); Vector4 AxisAngle = d.GetAxisAngle(); Quat dt = new Quat(AxisAngle.w * t, new MyVector3(AxisAngle.x, AxisAngle.y, AxisAngle.z)); return(dt * lhs); }
public static Quat SLERP(Quat q, Quat r, float t) { t = Mathf.Clamp(t, 0.0f, 1.0f); Quat d = r * q.Inverse(); Vector4 AxisAngle = d.GetAxisAngle(); Quat dT = new Quat(AxisAngle.w * t, new Vector3(AxisAngle.x, AxisAngle.y, AxisAngle.z)); return(dT * q); }
// Update is called once per frame void Update() { Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length]; angle += Time.deltaTime * 1; Rotation *= new Quat(EulerMaths.DegtoRag(RotationSpeed), VectorMaths.VectorNormalised(new Vector3(0, 1, 0))); for (int i = 0; i < TransformedVertices.Length; i++) { Quat p = new Quat(ModelSpaceVertices[i]); Quat newp = ((Rotation * p) * Rotation.Inverse()); Vector3 newpos = newp.GetAxisAngle(); TransformedVertices[i] = newpos; } MeshFilter MF = GetComponent <MeshFilter>(); MF.mesh.vertices = TransformedVertices; MF.mesh.RecalculateNormals(); MF.mesh.RecalculateBounds(); }
void RotatePlanet() //Same concept just x it by all the vertices e.t.c { Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length]; angle += Time.deltaTime * 50; Quat Rotation = new Quat(VectorMaths.DegToRad(angle), VectorMaths.VectorNormalize(new Vector3(1, 1, 1))); for (int i = 0; i < TransformedVertices.Length; i++) { Quat p = new Quat(ModelSpaceVertices[i]); Quat newp = ((Rotation * p) * Rotation.Inverse()); Vector3 newpos = newp.GetAxisAngle(); TransformedVertices[i] = newpos; } // TransformedVertices[0].x = -300; MeshFilter MF = GetComponent <MeshFilter>(); MF.mesh.vertices = TransformedVertices; MF.mesh.RecalculateNormals(); MF.mesh.RecalculateBounds(); }
//rotates the vertices of the planet model using the custom-made quaternions void Rotate() { Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length]; rotAngle += Time.deltaTime * rotSpeed * speedScalar; Quat Rotation = new Quat(VectorMaths.DegToRad(rotAngle), VectorMaths.VectorNormalize(new Vector3(1, 1, 1))); for (int i = 0; i < TransformedVertices.Length; i++) { Quat p = new Quat(ModelSpaceVertices[i]); Quat newp = ((Rotation * p) * Rotation.Inverse()); Vector3 newpos = newp.GetAxisAngle(); TransformedVertices[i] = newpos; } // TransformedVertices[0].x = -300; MeshFilter MF = GetComponent <MeshFilter>(); MF.mesh.vertices = TransformedVertices; MF.mesh.RecalculateNormals(); MF.mesh.RecalculateBounds(); }