Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of Simulation class with a default window and a viewport
        /// </summary>
        public Simulation(EngineWindow window)
        {
            Path contentRoot = Path.CreateDirectory(@"..\..\..\Content\drones").GetAbsolute();

            _viewport = window.AddViewport("Default", 1, 1, 0, 0, false);
            _cameras = new Dictionary<string, PerspectiveCamera>();

            _player = new PlayerInteraction(3030);

            SimplyEnvironment env = SimplyEnvironment.Load(contentRoot + new Path("scene.env"));

            SimplySim.Xna.Engine.Construction engineConstruction = new SimplySim.Xna.Engine.Construction(this);

            SimplySim.Simulation.Engine.Construction simulationConstruction = new SimplySim.Simulation.Engine.Construction(engineConstruction);

            WorldDesc worldDesc = simulationConstruction.GenerateWorldDesc(env);

            worldDesc.FPS = 600;
            worldDesc.MaxIter = 12;

            WorldHandle world = AddWorld("DroneWorld", new NewtonWorld(worldDesc));

            _scene = CreateSceneManager("Drone Simulation");
            simulationConstruction.LoadEnvironment(env, world, _scene);

            _actualCameraName = GlobalCameraName;
            PerspectiveCamera globalCamera = (PerspectiveCamera)_scene[GlobalCameraName].Entities[0];
            _viewport.Camera = globalCamera;
            _cameras.Add(GlobalCameraName, globalCamera);

            engineConstruction.AddControllers(env, _scene, _viewport);

            _scene.PostProcessingManager.ComponentAddedFiltered.Subscribe(new RegexFilter<PostProcessingComponent>("Screen Space Ambient Occlusion"), BindSSAO);

            #region Drones

            // Box drone

            _boxDrone = new Drone(world, BoxDroneName, _player);
            _boxDroneHUD = new DroneSensorsHUD(_boxDrone, window.HUDManager);

            FourHelixBoxDroneCommand _droneBoxController = new FourHelixBoxDroneCommand(_boxDrone.Rotors);

            Parameter altParam = new Parameter(ParameterType.Altitude, new Coefficients(1, 0.1f, 0));
            Parameter yawParam = new Parameter(ParameterType.Yaw, new Coefficients(0.5f, 0.1f, 0));
            Parameter pitchParam = new Parameter(ParameterType.Pitch, new Coefficients(0.3f, 0.05f, 0.05f));
            Parameter rollParam = new Parameter(ParameterType.Roll, new Coefficients(0.3f, 0.05f, 0.05f));
            Parameter[] parameters = new Parameter[] { altParam, yawParam, pitchParam, rollParam };

            //_fourHelixBoxDroneController = new KeyBoardPIDController(_boxDrone, 1, worldDesc.Gravity.Length(), _droneBoxController, parameters);
            _fourHelixBoxDroneController = new PlayerController(_player, _boxDrone, 1, worldDesc.Gravity.Length(), _droneBoxController, parameters);
            #endregion

            world.World.ActorAddedFiltered.Subscribe(new RegexFilter<IActor> ("[.]ComplexObject[.]Body"), BindCameras);

            _scene.Enabled = true;
            world.Enabled = true;
        }
Exemplo n.º 2
0
 public PlayerController(PlayerInteraction player, Drone drone, float mass, float gravity, AbstractDroneCommand droneCommand, Parameter[] parameters)
     : base(drone, mass, gravity, droneCommand, parameters)
 {
     _command = droneCommand;
     _player = player;
     _deltaZ = 0;
     _drone = drone;
     _isStarted = false;
     return;
 }
Exemplo n.º 3
0
        public Drone(WorldHandle world, string name, PlayerInteraction Player)
        {
            DroneConfig config = Serializer.Instance.Deserialize<DroneConfig>(new Path(name + ".drs"));
            _player = Player;

            _dictionaryRotors = new Dictionary<string, Rotor>();

            foreach (RotorDesc rotorSpecified in config.Rotors)
            {
                Rotor r = new Rotor(world.World, rotorSpecified, name);
                _dictionaryRotors.Add(rotorSpecified.Name, r);
            }
            _LIDAR = new LIDAR(world, name,_player, this);

            world.World.ActorAddedFiltered.Subscribe(new RegexFilter<IActor>(name + "[.]ComplexObject[.]" + config.BodyName), BindActor);
        }
Exemplo n.º 4
0
 public LIDAR(WorldHandle world, string name, PlayerInteraction Player, Drone drone)
 {
     //Register to actor insertion
     _name = "LIDAR" + Guid.NewGuid().ToString();
     _player = Player;
     world.World.ActorAddedFiltered.Subscribe(new RegexFilter<IActor>("[.]ComplexObject[.]Body"), BindActor);
     world.World.AddActuator(this);
     _world = world.World;
     _drone = drone;
     desc = new RayDesc();
     origin = new Vector3(0, (float)0.1, 0);
     rayVec = new Vector3[1081];
     iter = 0;
     int index = 0;
     for (double i = -45.0; i <= 225; i += 0.25)
     {
         rayVec[index] = new Vector3((float)(Math.Cos(i*(Math.PI/180.0))), 0, (float)(-1.0 * Math.Sin(i*(Math.PI/180.0))));
         index++;
     }
 }