public void UpdatePosition(MyFloatingObject floatingObject)
        {
            var m = floatingObject.WorldMatrix;

            FloatingObjectPositionUpdateMsg msg = new FloatingObjectPositionUpdateMsg();

            msg.EntityId = floatingObject.EntityId;
            msg.Forward  = m.Forward;
            msg.Up       = m.Up;
            msg.Position = m.Translation;
            if (floatingObject.Physics != null)
            {
                msg.LinearVelocity  = floatingObject.Physics.LinearVelocity;
                msg.AngularVelocity = floatingObject.Physics.AngularVelocity;
            }

            //PositionUpdateCompressedMsg msg = new PositionUpdateCompressedMsg();
            //msg.EntityId = floatingObject.EntityId;
            //msg.SetWorldMatrix(m);
            //if (floatingObject.Physics != null)
            //{
            //    if (floatingObject.Physics.RigidBody.IsActive)
            //    {
            //        if (floatingObject.Physics.LinearVelocity.Length() > 0.1f || floatingObject.Physics.AngularVelocity.Length() > 0.1f)
            //          msg.SetVelocities(floatingObject.Physics.LinearVelocity, floatingObject.Physics.AngularVelocity);
            //    }
            //}

            MySession.Static.SyncLayer.SendMessageToAll(ref msg);
        }
        static void OnUpdateCallback(ref FloatingObjectPositionUpdateMsg msg, MyNetworkClient sender)
        {
            MyEntity entity;

            if (MyEntities.TryGetEntityById(msg.EntityId, out entity))
            {
                MyFloatingObject floatingObject = entity as MyFloatingObject;
                if (floatingObject != null)
                {
                    MatrixD matrix = MatrixD.CreateWorld(msg.Position, msg.Forward, msg.Up);

                    Vector3D translation = floatingObject.PositionComp.GetPosition();
                    //Quaternion rotation = Quaternion.CreateFromRotationMatrix(floatingObject.WorldMatrix.GetOrientation());
                    Quaternion rotation = Quaternion.Identity;
                    m_rigidBodyList.Clear();
                    Sandbox.Engine.Physics.MyPhysics.GetPenetrationsShape(floatingObject.Physics.RigidBody.GetShape(), ref translation, ref rotation, m_rigidBodyList, 0);
                    if (m_rigidBodyList.Count == 0)
                    {
                        floatingObject.PositionComp.SetWorldMatrix(matrix, sender);
                    }
                    if (floatingObject.Physics != null)
                    {
                        if (m_rigidBodyList.Count == 1 && m_rigidBodyList[0] == floatingObject.Physics.RigidBody)
                        {
                            floatingObject.PositionComp.SetWorldMatrix(matrix, sender);
                        }

                        floatingObject.Physics.LinearVelocity  = msg.LinearVelocity;
                        floatingObject.Physics.AngularVelocity = msg.AngularVelocity;
                    }
                }
            }
        }
Пример #3
0
        static void OnUpdateCallback(ref FloatingObjectPositionUpdateMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(!Sync.IsServer);

            MyEntity entity;

            if (MyEntities.TryGetEntityById(msg.EntityId, out entity))
            {
                MyFloatingObject floatingObject = entity as MyFloatingObject;
                if (floatingObject != null)
                {
                    MatrixD  matrix      = MatrixD.CreateWorld(msg.Position, msg.Forward, msg.Up);
                    Vector3D translation = floatingObject.PositionComp.GetPosition();
                    //Quaternion rotation = Quaternion.CreateFromRotationMatrix(floatingObject.WorldMatrix.GetOrientation());
                    Quaternion rotation = Quaternion.Identity;
                    m_rigidBodyList.Clear();

                    Sandbox.Engine.Physics.MyPhysics.GetPenetrationsShape(floatingObject.Physics.RigidBody.GetShape(), ref translation, ref rotation, m_rigidBodyList, Sandbox.Engine.Physics.MyPhysics.NotCollideWithStaticLayer);

                    //if (m_rigidBodyList.Count == 0 || MyPerGameSettings.EnableFloatingObjectsActiveSync)
                    //{
                    //    floatingObject.PositionComp.SetWorldMatrix(matrix, sender);
                    //}

                    if (floatingObject.Physics != null)
                    {
                        if (m_rigidBodyList.Count == 1 && m_rigidBodyList[0].Body == floatingObject.Physics.RigidBody)
                        {
                            floatingObject.PositionComp.SetWorldMatrix(matrix, sender);
                        }

                        floatingObject.Physics.LinearVelocity  = msg.LinearVelocity;
                        floatingObject.Physics.AngularVelocity = msg.AngularVelocity;
                    }
                }
            }
        }