Пример #1
0
        void LoadInitialSystem()
        {
            UInt16 count      = ReadInt16();
            int    packetSize = count * MeshFirstPacketSize;

            byte[] b = new byte[packetSize];

            stream.Read(b, 0, b.Length);

            PacketDecoder decoder = new PacketDecoder(ref b);

            //List<SpaceObject> spaceObjects = new List<SpaceObject>();
            foreach (var item in SpaceObjects)
            {
                SceneSystem.SceneInstance.RootScene.Entities.Remove(item.Value.entityRef);
            }
            SpaceObjects.Clear();

            for (ushort i = 0; i < count; i++)
            {
                int           id       = decoder.Read_UInt16();
                ListOf_Entity type     = (ListOf_Entity)decoder.Read_UInt16();
                Vector3       location = decoder.Read_Vector3();
                Vector3       scale    = decoder.Read_Vector3();
                Quaternion    rotation = decoder.Read_Quat();

                Entity entitieRef = AddObject(type, id, location, scale, rotation);
                SpaceObjects.Add(id, new SpaceObject(ref entitieRef, type));
            }
        }
Пример #2
0
        private void UpdateShips()
        {
            UInt16 count = ReadInt16();
            int    size  = ShipPacketSize + (count * MeshUpdatePacketSize);

            byte[] b = new byte[size];
            stream.Read(b, 0, size);
            PacketDecoder decoder = new PacketDecoder(ref b);
            //Ship
            int        shipId = decoder.Read_UInt16();
            Vector3    pos    = decoder.Read_Vector3();
            Quaternion quat   = decoder.Read_Quat();

            for (int i = 0; i < count; i++)
            {
                int id = decoder.Read_UInt16();
                if (SpaceObjects.ContainsKey(id))
                {
                    SpaceObject spaceObject = SpaceObjects[id];
                    spaceObject.entityRef.Transform.Position = decoder.Read_Vector3();
                    spaceObject.entityRef.Transform.Rotation = decoder.Read_Quat();
                }
            }



            //Matrix mat = Matrix.Identity * Matrix.Translation(Ship.Transform.Position) * Matrix.RotationQuaternion(Ship.Transform.Rotation);
            //Matrix mat = Matrix.Translation(Ship.Transform.Position) * Matrix.RotationQuaternion(Ship.Transform.Rotation);

            //mat.Decompose(out Vector3 scale, out Quaternion rotation, out Vector3 translation);
            //Camera.Transform.Position = translation;
            //Camera.Transform.Rotation = rotation;

            //Camera.Transform.Rotation = Ship.Transform.Rotation;
            //Camera.Transform.Position = Ship.Transform.Position;
            //Matrix cameraTransform = Matrix.RotationQuaternion(Ship.Transform.Rotation) + Matrix.Translation(Ship.Transform.Position + new Vector3(0, 1, -5));
            //Camera.Transform.Position = translation;
            //Camera.Transform.Rotation = rotation;

            //Camera.Transform.Position = Vector3.Clamp(
            //	Vector3.Lerp(Camera.Transform.Position, Ship.Transform.Position, 0.125f),
            //	Ship.Transform.Position * 0.01f,
            //	Ship.Transform.Position * 10f
            //	);

            //float glow = Math.Abs(Vector3.Distance(Ship.Transform.Position, pos));

            //Ship.Components.Get<ModelComponent>().GetMaterial(0).Passes[0].Parameters.Set()

            float PositionDistance = Math.Abs(Vector3.Distance(pos, Camera.Transform.Position));
            float PositionSmooth   = 0.2f;

            //> 2 and < 16
            if (PositionDistance > 2)
            {
                if (PositionDistance <= 10)
                {
                    PositionSmooth = PositionDistance * 0.1f;
                }
                else
                {
                    PositionSmooth = 1;
                }
            }

            //float RotationDistance = Math.Abs(Vector3.Distance(pos, Camera.Transform.Position));
            float RotationDistance = Math.Abs(Vector3.Distance(quat.Axis, Camera.Transform.Rotation.Axis));
            float RotationSmooth   = 0.1f;

            //> 2 and < 16
            if (RotationDistance > 1)
            {
                if (RotationDistance <= 10)
                {
                    RotationSmooth = RotationDistance * 0.1f;
                }
                else
                {
                    RotationSmooth = 1;
                }
            }

            Camera.Transform.Position = Vector3.Lerp(Camera.Transform.Position, pos, PositionSmooth);
            Camera.Transform.Rotation = Quaternion.Slerp(Camera.Transform.Rotation, quat, 0.125f);

            Ship.Transform.Position = Vector3.Lerp(Ship.Transform.Position, pos, 0.99f);
            Ship.Transform.Rotation = Quaternion.Slerp(Ship.Transform.Rotation, quat, 0.99f);

            DebugText.Print(pos.X.ToString(), new Int2(20, 20), Color4.White);
            DebugText.Print(pos.Y.ToString(), new Int2(20, 40), Color4.White);
            DebugText.Print(pos.Z.ToString(), new Int2(20, 60), Color4.White);

            //DebugText.Print(Camera.Transform.Position.X.ToString(), new Int2(20, 20), Color4.White);
            //DebugText.Print(Camera.Transform.Position.Y.ToString(), new Int2(20, 40), Color4.White);
            //DebugText.Print(Camera.Transform.Position.Z.ToString(), new Int2(20, 60), Color4.White);

            //DebugText.Print(quat.Angle.ToString(), new Int2(20, 90), Color4.White);
        }