Exemple #1
0
        private void CommandReceived(CommandReader cr)
        {
            Commands cmd = cr.ReadCommand();

            if (cmd == Commands.UpdateEntity)
            {
                int        entityID   = cr.ReadData <int>();
                EntityType entityType = (EntityType)cr.ReadData <byte>();
                Matrix     world      = cr.ReadMatrix();
                Vector3    scale      = cr.ReadVector3();

                PhysicsShape physicsShape    = (PhysicsShape)cr.ReadData <byte>();
                float        radius          = cr.ReadData <float>();
                float        angularDamping  = cr.ReadData <float>();
                float        linearDamping   = cr.ReadData <float>();
                Vector3      angularVelocity = cr.ReadVector3();
                Vector3      linearVelocity  = cr.ReadVector3();

                GameEntity entity = gameManager.GetEntity(entityID);
                if (entity == null)
                {
                    lock (gameManager)
                    {
                        if (entityType == EntityType.PlanetEarth)
                        {
                            entity = new PlanetEntity(this, entityType, new Sphere(MathConverter.Convert(world.Translation), radius));
                        }
                        else
                        {
                            entity = new GameEntity(this, entityType, new Sphere(MathConverter.Convert(world.Translation), radius));
                        }
                        entity.ID = entityID;
                        gameManager.RegisterEntity(entity);
                    }
                }
                else
                {
                    entity.SetScale(scale.X, scale.Y, scale.Z);
                    entity.PhysicsEntity.AngularDamping  = angularDamping;
                    entity.PhysicsEntity.LinearDamping   = linearDamping;
                    entity.PhysicsEntity.AngularVelocity = MathConverter.Convert(angularVelocity);
                    entity.PhysicsEntity.LinearVelocity  = MathConverter.Convert(linearVelocity);
                    entity.PhysicsEntity.WorldTransform  = MathConverter.Convert(world);
                    //BEPUutilities.Matrix.
                    //entity.World = world;
                    //entity.PhysicsEntity.WorldTransform = new BEPUutilities.Matrix(world.M11, world.M12, world.M13, world.M14, world.M21, world.M22, world.M23, world.M24, world.M31, world.M32, world.M33, world.M34, world.M41, world.M42, world.M43, world.M44);
                }
                if (entityType == EntityType.Player)
                {
                    cameraTarget = entity;
                }

                /*
                 * ServerEntity entity = ServerEntities.ContainsKey(entityID) ? ServerEntities[entityID] : null;
                 * if (entity == null)
                 * {
                 *  entity = new ServerEntity() { ID = entityID, EntityType = entityType, World = world, Model = GetModel(entityType) };
                 *  if (entity.Model != null) entity.BoneTransforms = new Matrix[entity.Model.Bones.Count];
                 *  ServerEntities.Add(entityID, entity);
                 *  ServerEntityIDs.Add(entityID);
                 *  if (entityType == EntityType.Player) CameraTarget = entity;
                 * }
                 * else entity.World = world;
                 */
            }
        }