internal void ApplyPatch(RigidBodyPatch patch) { // Apply any changes made to the state of the mixed reality extension runtime version of the rigid body. if (patch.Velocity != null && patch.Velocity.IsPatched()) { _rigidbody.velocity = _rigidbody.velocity.GetPatchApplied(_sceneRoot.TransformDirection(Velocity.ApplyPatch(patch.Velocity).ToVector3())); } if (patch.AngularVelocity != null && patch.AngularVelocity.IsPatched()) { _rigidbody.angularVelocity = _rigidbody.angularVelocity.GetPatchApplied(_sceneRoot.TransformDirection(AngularVelocity.ApplyPatch(patch.AngularVelocity).ToVector3())); } if (patch.Mass.HasValue) { _rigidbody.mass = _rigidbody.mass.GetPatchApplied(Mass.ApplyPatch(patch.Mass)); } if (patch.DetectCollisions.HasValue) { _rigidbody.detectCollisions = _rigidbody.detectCollisions.GetPatchApplied(DetectCollisions.ApplyPatch(patch.DetectCollisions)); } if (patch.CollisionDetectionMode.HasValue) { _rigidbody.collisionDetectionMode = _rigidbody.collisionDetectionMode.GetPatchApplied(CollisionDetectionMode.ApplyPatch(patch.CollisionDetectionMode)); } if (patch.UseGravity.HasValue) { _rigidbody.useGravity = _rigidbody.useGravity.GetPatchApplied(UseGravity.ApplyPatch(patch.UseGravity)); } if (patch.IsKinematic.HasValue) { _rigidbody.isKinematic = _rigidbody.isKinematic.GetPatchApplied(IsKinematic.ApplyPatch(patch.IsKinematic)); } _rigidbody.constraints = (RigidbodyConstraints)((int)_rigidbody.constraints).GetPatchApplied((int)ConstraintFlags.ApplyPatch(patch.ConstraintFlags)); }
public override XmlElement SerializeData(XmlDocument doc) { XmlElement element = base.SerializeData(doc); element.SetAttribute("mass", string.Empty, Mass.ToString("G4")); element.SetAttribute("drag", string.Empty, Drag.ToString("G4")); element.SetAttribute("angular-drag", string.Empty, AngularDrag.ToString("G4")); element.SetAttribute("use-gravity", string.Empty, UseGravity.ToString()); element.SetAttribute("constraints", string.Empty, Constraints.ToString()); return(element); }
internal void ApplyPatch(RigidBodyPatch patch) { // Apply any changes made to the state of the mixed reality extension runtime version of the rigid body. if (patch.Position != null && patch.Position.IsPatched()) { var localPosition = _sceneRoot.InverseTransformPoint(_rigidbody.position).ToMWVector3(); _rigidbody.position = _rigidbody.position.GetPatchApplied(_sceneRoot.TransformPoint(localPosition.ApplyPatch(patch.Position).ToVector3())); } if (patch.Rotation != null && patch.Rotation.IsPatched()) { var localRotation = (_rigidbody.rotation * _sceneRoot.rotation).ToMWQuaternion(); _rigidbody.rotation = _sceneRoot.rotation * _rigidbody.rotation.GetPatchApplied(localRotation.ApplyPatch(patch.Rotation)); } if (patch.Velocity != null && patch.Velocity.IsPatched()) { _rigidbody.velocity = _rigidbody.velocity.GetPatchApplied(_sceneRoot.TransformDirection(Velocity.ApplyPatch(patch.Velocity).ToVector3())); } if (patch.AngularVelocity != null && patch.AngularVelocity.IsPatched()) { _rigidbody.angularVelocity = _rigidbody.angularVelocity.GetPatchApplied(_sceneRoot.TransformDirection(AngularVelocity.ApplyPatch(patch.AngularVelocity).ToVector3())); } if (patch.Mass.HasValue) { _rigidbody.mass = _rigidbody.mass.GetPatchApplied(Mass.ApplyPatch(patch.Mass)); } if (patch.DetectCollisions.HasValue) { _rigidbody.detectCollisions = _rigidbody.detectCollisions.GetPatchApplied(DetectCollisions.ApplyPatch(patch.DetectCollisions)); } if (patch.CollisionDetectionMode.HasValue) { _rigidbody.collisionDetectionMode = _rigidbody.collisionDetectionMode.GetPatchApplied(CollisionDetectionMode.ApplyPatch(patch.CollisionDetectionMode)); } if (patch.UseGravity.HasValue) { _rigidbody.useGravity = _rigidbody.useGravity.GetPatchApplied(UseGravity.ApplyPatch(patch.UseGravity)); } _rigidbody.constraints = (RigidbodyConstraints)((int)_rigidbody.constraints).GetPatchApplied((int)ConstraintFlags.ApplyPatch(patch.ConstraintFlags)); }