private static void OnRagdollTransformsUpdate(MySyncCharacter syncObject, ref RagdollTransformsMsg message, MyNetworkClient sender) { var ragdollComponent = syncObject.Entity.Components.Get <MyCharacterRagdollComponent>(); if (ragdollComponent == null) { return; } if (syncObject.Entity.Physics == null) { return; } if (syncObject.Entity.Physics.Ragdoll == null) { return; } if (ragdollComponent.RagdollMapper == null) { return; } if (!syncObject.Entity.Physics.Ragdoll.InWorld) { return; } if (!ragdollComponent.RagdollMapper.IsActive) { return; } Debug.Assert(message.worldOrientation != null && message.worldOrientation != Quaternion.Zero, "Received invalid ragdoll orientation from server!"); Debug.Assert(message.worldPosition != null && message.worldPosition != Vector3.Zero, "Received invalid ragdoll orientation from server!"); Debug.Assert(message.transformsOrientations != null && message.transformsPositions != null, "Received empty ragdoll transformations from server!"); Debug.Assert(message.transformsPositions.Length == message.TransformsCount && message.transformsOrientations.Length == message.TransformsCount, "Received ragdoll data count doesn't match!"); Matrix worldMatrix = Matrix.CreateFromQuaternion(message.worldOrientation); worldMatrix.Translation = message.worldPosition; Matrix[] transforms = new Matrix[message.TransformsCount]; for (int i = 0; i < message.TransformsCount; ++i) { transforms[i] = Matrix.CreateFromQuaternion(message.transformsOrientations[i]); transforms[i].Translation = message.transformsPositions[i]; } ragdollComponent.RagdollMapper.UpdateRigidBodiesTransformsSynced(message.TransformsCount, worldMatrix, transforms); }
public void SendRagdollTransforms(Matrix world, Matrix[] localBodiesTransforms) { if (ResponsibleForUpdate(this)) { var msg = new RagdollTransformsMsg(); msg.CharacterEntityId = Entity.EntityId; msg.worldPosition = world.Translation; msg.TransformsCount = localBodiesTransforms.Count(); msg.worldOrientation = Quaternion.CreateFromRotationMatrix(world.GetOrientation()); msg.transformsPositions = new Vector3[msg.TransformsCount]; msg.transformsOrientations = new Quaternion[msg.TransformsCount]; for (int i = 0; i < localBodiesTransforms.Count(); ++i) { msg.transformsPositions[i] = localBodiesTransforms[i].Translation; msg.transformsOrientations[i] = Quaternion.CreateFromRotationMatrix(localBodiesTransforms[i].GetOrientation()); } Sync.Layer.SendMessageToAll(ref msg); } }
public void SendRagdollTransforms(Matrix world, Matrix[] localBodiesTransforms) { if (ResponsibleForUpdate(this)) { var msg = new RagdollTransformsMsg(); msg.CharacterEntityId = Entity.EntityId; msg.worldPosition = world.Translation; msg.TransformsCount = localBodiesTransforms.Count(); msg.worldOrientation = Quaternion.CreateFromRotationMatrix(world.GetOrientation()); msg.transformsPositions = new Vector3[msg.TransformsCount]; msg.transformsOrientations = new Quaternion[msg.TransformsCount]; for (int i = 0; i < localBodiesTransforms.Count(); ++i) { msg.transformsPositions[i] = localBodiesTransforms[i].Translation; msg.transformsOrientations[i] = Quaternion.CreateFromRotationMatrix(localBodiesTransforms[i].GetOrientation()); } Sync.Layer.SendMessageToAll(ref msg); } }
private static void OnRagdollTransformsUpdate(MySyncCharacter syncObject, ref RagdollTransformsMsg message, MyNetworkClient sender) { var ragdollComponent = syncObject.Entity.Components.Get<MyCharacterRagdollComponent>(); if (ragdollComponent == null) return; if (syncObject.Entity.Physics == null) return; if (syncObject.Entity.Physics.Ragdoll == null) return; if (ragdollComponent.RagdollMapper == null) return; if (!syncObject.Entity.Physics.Ragdoll.InWorld) return; if (!ragdollComponent.RagdollMapper.IsActive) return; Debug.Assert(message.worldOrientation != null && message.worldOrientation != Quaternion.Zero, "Received invalid ragdoll orientation from server!"); Debug.Assert(message.worldPosition != null && message.worldPosition != Vector3.Zero, "Received invalid ragdoll orientation from server!"); Debug.Assert(message.transformsOrientations != null && message.transformsPositions != null, "Received empty ragdoll transformations from server!"); Debug.Assert(message.transformsPositions.Count() == message.TransformsCount && message.transformsOrientations.Count() == message.TransformsCount, "Received ragdoll data count doesn't match!"); Matrix worldMatrix = Matrix.CreateFromQuaternion(message.worldOrientation); worldMatrix.Translation = message.worldPosition; Matrix[] transforms = new Matrix[message.TransformsCount]; for (int i = 0; i < message.TransformsCount; ++i) { transforms[i] = Matrix.CreateFromQuaternion(message.transformsOrientations[i]); transforms[i].Translation = message.transformsPositions[i]; } ragdollComponent.RagdollMapper.UpdateRigidBodiesTransformsSynced(message.TransformsCount, worldMatrix, transforms); }