/// <summary> /// Creates a quaternion from a matrix. /// </summary> /// <param name="matrix">A matrix representing an orientation.</param> /// <returns>JQuaternion representing an orientation.</returns> #region public static JQuaternion CreateFromMatrix(JMatrix matrix) public static TSQuaternion CreateFromMatrix(TSMatrix matrix) { TSQuaternion result; TSQuaternion.CreateFromMatrix(ref matrix, out result); return(result); }
private void UpdateChildRotation() { TSMatrix matrix = TSMatrix.CreateFromQuaternion(_rotation); foreach (TSTransform child in tsChildren) { child.localRotation = TSQuaternion.CreateFromMatrix(TSMatrix.Inverse(matrix)) * _rotation; child.localPosition = TSVector.Transform(child.localPosition, TSMatrix.CreateFromQuaternion(child.localRotation)); child.position = TransformPoint(child.localPosition); } }
internal void PostStep() { bool flag = this._freezeConstraints > TSRigidBodyConstraints.None; if (flag) { bool flag2 = (this._freezeConstraints & TSRigidBodyConstraints.FreezePositionX) == TSRigidBodyConstraints.FreezePositionX; bool flag3 = (this._freezeConstraints & TSRigidBodyConstraints.FreezePositionY) == TSRigidBodyConstraints.FreezePositionY; bool flag4 = (this._freezeConstraints & TSRigidBodyConstraints.FreezePositionZ) == TSRigidBodyConstraints.FreezePositionZ; bool flag5 = flag2; if (flag5) { this.position.x = this._freezePosition.x; } bool flag6 = flag3; if (flag6) { this.position.y = this._freezePosition.y; } bool flag7 = flag4; if (flag7) { this.position.z = this._freezePosition.z; } bool flag8 = (this._freezeConstraints & TSRigidBodyConstraints.FreezeRotationX) == TSRigidBodyConstraints.FreezeRotationX; bool flag9 = (this._freezeConstraints & TSRigidBodyConstraints.FreezeRotationY) == TSRigidBodyConstraints.FreezeRotationY; bool flag10 = (this._freezeConstraints & TSRigidBodyConstraints.FreezeRotationZ) == TSRigidBodyConstraints.FreezeRotationZ; bool flag11 = flag8 | flag9 | flag10; if (flag11) { TSQuaternion quaternion = TSQuaternion.CreateFromMatrix(this.Orientation); bool flag12 = flag8; if (flag12) { quaternion.x = this._freezeRotationQuat.x; } bool flag13 = flag9; if (flag13) { quaternion.y = this._freezeRotationQuat.y; } bool flag14 = flag10; if (flag14) { quaternion.z = this._freezeRotationQuat.z; } quaternion.Normalize(); this.Orientation = TSMatrix.CreateFromQuaternion(quaternion); } } }
private void IntegrateCallback(object obj) { RigidBody rigidBody = obj as RigidBody; TSVector tSVector; TSVector.Multiply(ref rigidBody.linearVelocity, this.timestep, out tSVector); TSVector.Add(ref tSVector, ref rigidBody.position, out rigidBody.position); bool flag = !rigidBody.isParticle; if (flag) { FP magnitude = rigidBody.angularVelocity.magnitude; bool flag2 = magnitude < FP.EN3; TSVector tSVector2; if (flag2) { TSVector.Multiply(ref rigidBody.angularVelocity, FP.Half * this.timestep - this.timestep * this.timestep * this.timestep * (2082 * FP.EN6) * magnitude * magnitude, out tSVector2); } else { TSVector.Multiply(ref rigidBody.angularVelocity, FP.Sin(FP.Half * magnitude * this.timestep) / magnitude, out tSVector2); } TSQuaternion tSQuaternion = new TSQuaternion(tSVector2.x, tSVector2.y, tSVector2.z, FP.Cos(magnitude * this.timestep * FP.Half)); TSQuaternion tSQuaternion2; TSQuaternion.CreateFromMatrix(ref rigidBody.orientation, out tSQuaternion2); TSQuaternion.Multiply(ref tSQuaternion, ref tSQuaternion2, out tSQuaternion); tSQuaternion.Normalize(); TSMatrix.CreateFromQuaternion(ref tSQuaternion, out rigidBody.orientation); } bool flag3 = (rigidBody.Damping & RigidBody.DampingType.Linear) > RigidBody.DampingType.None; if (flag3) { TSVector.Multiply(ref rigidBody.linearVelocity, this.currentLinearDampFactor, out rigidBody.linearVelocity); } bool flag4 = (rigidBody.Damping & RigidBody.DampingType.Angular) > RigidBody.DampingType.None; if (flag4) { TSVector.Multiply(ref rigidBody.angularVelocity, this.currentAngularDampFactor, out rigidBody.angularVelocity); } rigidBody.Update(); bool flag5 = this.CollisionSystem.EnableSpeculativeContacts || rigidBody.EnableSpeculativeContacts; if (flag5) { rigidBody.SweptExpandBoundingBox(this.timestep); } }
private void UpdatePlayMode() { if (tsParent != null) { _localPosition = tsParent.InverseTransformPoint(position); TSMatrix matrix = TSMatrix.CreateFromQuaternion(tsParent.rotation); _localRotation = TSQuaternion.CreateFromMatrix(TSMatrix.Inverse(matrix)) * rotation; } else { _localPosition = position; _localRotation = rotation; } if (rb != null) { transform.position = position.ToVector(); transform.rotation = rotation.ToQuaternion(); transform.localScale = localScale.ToVector(); /*if (rb.interpolation == TSRigidBody.InterpolateMode.Interpolate) { * transform.position = Vector3.Lerp(transform.position, position.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR); * transform.rotation = Quaternion.Lerp(transform.rotation, rotation.ToQuaternion(), Time.deltaTime * DELTA_TIME_FACTOR); * transform.localScale = Vector3.Lerp(transform.localScale, localScale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR); * return; * } else if (rb.interpolation == TSRigidBody.InterpolateMode.Extrapolate) { * transform.position = (position + rb.tsCollider.Body.TSLinearVelocity * Time.deltaTime * DELTA_TIME_FACTOR).ToVector(); * transform.rotation = Quaternion.Lerp(transform.rotation, rotation.ToQuaternion(), Time.deltaTime * DELTA_TIME_FACTOR); * transform.localScale = Vector3.Lerp(transform.localScale, localScale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR); * return; * }*/ } transform.position = position.ToVector(); transform.rotation = rotation.ToQuaternion(); transform.localScale = localScale.ToVector(); _scale = transform.lossyScale.ToTSVector(); }
public override void PostStep() { TSVector position = base.Body1.Position; position.z = 0; base.Body1.Position = position; TSQuaternion quaternion = TSQuaternion.CreateFromMatrix(base.Body1.Orientation); quaternion.Normalize(); quaternion.x = 0; quaternion.y = 0; bool flag = this.freezeZAxis; if (flag) { quaternion.z = 0; } base.Body1.Orientation = TSMatrix.CreateFromQuaternion(quaternion); bool isStatic = base.Body1.isStatic; if (!isStatic) { TSVector linearVelocity = base.Body1.LinearVelocity; linearVelocity.z = 0; base.Body1.LinearVelocity = linearVelocity; TSVector angularVelocity = base.Body1.AngularVelocity; angularVelocity.x = 0; angularVelocity.y = 0; bool flag2 = this.freezeZAxis; if (flag2) { angularVelocity.z = 0; } base.Body1.AngularVelocity = angularVelocity; } }
/** * @brief Changes orientation to look at target position. * * @param target A {@link TSVector} representing the position to look at. **/ public void LookAt(TSVector target) { rotation = TSQuaternion.CreateFromMatrix(TSMatrix.CreateFromLookAt(position, target)); }
/** * @brief Changes orientation to look at target position. * * @param target A {@link TSVector} representing the position to look at. **/ public void LookAt(TSVector target) { rotation = TSQuaternion.CreateFromMatrix(TSMatrix.CreateFromLookAt(position, target)); tsCollider.Body.TSUpdate(); }