Ejemplo n.º 1
0
        private VisualEntity CreateEntity(Vector3 entityPosition, VisualEntity entityParent, Entities entityType)
        {
            VisualEntity e = null;

            #region Create Entity
            switch (entityType)
            {
            case Entities.HeightFieldEntity:
            {
                e = new HeightFieldEntity("ground", "03RamieSc.dds", new
                                          MaterialProperties("ground", 0.8f, 0.5f, 0.8f));
            } break;

            case Entities.SkyDomeEntity:
            {
                e = new SkyDomeEntity("skydome.dds", "sky_diff.dds");
                SimulationEngine.GlobalInstancePort.Insert(e);
            } break;

            case Entities.LightSourceEntity:
            {
                var lightEntity = new LightSourceEntity();
                e = lightEntity;
                lightEntity.State.Name          = "LightSourceEntity";
                lightEntity.Type                = LightSourceEntityType.Directional;
                lightEntity.Color               = new Vector4(.8f, .8f, .8f, 1);
                lightEntity.State.Pose.Position = new Vector3(0, 1, 0);
                lightEntity.Direction           = new Vector3(0, -1, 0);
                e.Flags = e.Flags | VisualEntityProperties.DisableRendering;
            } break;

            case Entities.MotorBaseWithDrive:
            {
                e            = new MotorBaseWithDrive(entityPosition);
                e.State.Name = "MotorBaseWithDrive";
                MakeNameUnique(e);
            } break;

            case Entities.SimulatedBrightnessSensorEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }
                else
                {
                    e            = new SimulatedBrightnessSensorEntity(32, 32, 2.0f * (float)Math.PI / 180.0f);
                    e.State.Name = "SimulatedBrightnessSensorEntity";
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedColorSensorEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }
                else
                {
                    e            = new SimulatedColorSensorEntity(32, 32, 2.0f * (float)Math.PI / 180.0f);
                    e.State.Name = "SimulatedColorSensorEntity";
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedCompassEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }

                else
                {
                    e            = new SimulatedCompassEntity();
                    e.State.Name = "SimulatedCompassEntity";
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedGPSEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }

                else
                {
                    e            = new SimulatedGPSEntity();
                    e.State.Name = "SimulatedGPSEntity";
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedIREntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }

                else
                {
                    e              = new SimulatedIREntity(new Pose(entityPosition));
                    e.State.Name   = "SimulatedIREntity";
                    e.State.Flags |= EntitySimulationModifiers.DisableCollisions;
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedLRFEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }
                else
                {
                    e              = new SimulatedLRFEntity(new Pose(entityPosition));
                    e.State.Name   = "SimulatedLRFEntity";
                    e.State.Flags |= EntitySimulationModifiers.DisableCollisions;
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedSonarEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }
                else
                {
                    e              = new SimulatedSonarEntity(new Pose(entityPosition));
                    e.State.Name   = "SimulatedSonarEntity";
                    e.State.Flags |= EntitySimulationModifiers.DisableCollisions;
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;

            case Entities.SimulatedWebcamEntity:
            {
                if (entityParent == null)
                {
                    ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                }
                else
                {
                    e = new SimulatedWebcamEntity(entityPosition,
                                                  320, 240, 45.0f * (float)Math.PI / 180.0f);
                    e.State.Name = "SimulatedWebcamEntity";
                    MakeNameUnique(e);
                    entityParent.InsertEntity(e);
                }
            } break;
            }
            #endregion

            return(e);
        }
Ejemplo n.º 2
0
        public VisualEntity CreateEntity(Vector3 entityPosition, VisualEntity entityParent, Entities entityType)
        {
            VisualEntity e = null;

            #region Create Entity
            switch (entityType)
            {
                case Entities.HeightFieldEntity:
                    {
                        e = new HeightFieldEntity("ground", "03RamieSc.dds", new
                            MaterialProperties("ground", 0.8f, 0.5f, 0.8f));

                    } break;
                case Entities.SkyDomeEntity:
                    {
                        e = new SkyDomeEntity("skydome.dds", "sky_diff.dds");
                        SimulationEngine.GlobalInstancePort.Insert(e);
                    } break;
                case Entities.LightSourceEntity:
                    {
                        var lightEntity = new LightSourceEntity();
                        e = lightEntity;
                        lightEntity.State.Name = "LightSourceEntity";
                        lightEntity.Type = LightSourceEntityType.Directional;
                        lightEntity.Color = new Vector4(.8f, .8f, .8f, 1);
                        lightEntity.State.Pose.Position = new Vector3(0, 1, 0);
                        lightEntity.Direction = new Vector3(0, -1, 0);
                        e.Flags = e.Flags | VisualEntityProperties.DisableRendering;

                    } break;
                case Entities.MotorBaseWithDrive:
                    {
                        e = new MotorBaseWithDrive(entityPosition);
                        e.State.Name = "MotorBaseWithDrive";
                        MakeNameUnique(e);

                        //Inserting Actual Rover instead of Simple Simulatd Robot.
                        //Needs to be tested

                        /*ColladaToMSRS e = new ColladaToMSRS(@"C:\.....\collada\rover.dae");
                        foreach (VisualEntity entity in e.Entities)
                        {
                            SimulationEngine.GlobalInstancePort.Insert(entity);
                        }*/

                    } break;
                case Entities.SimulatedBrightnessSensorEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }
                        else
                        {
                            e = new SimulatedBrightnessSensorEntity(32, 32, 2.0f * (float)Math.PI / 180.0f);
                            e.State.Name = "SimulatedBrightnessSensorEntity";
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);
                        }

                    } break;
                case Entities.SimulatedColorSensorEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }
                        else
                        {
                            e = new SimulatedColorSensorEntity(32, 32, 2.0f * (float)Math.PI / 180.0f);
                            e.State.Name = "SimulatedColorSensorEntity";
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);
                        }

                    } break;
                case Entities.SimulatedCompassEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }

                        else
                        {
                            e = new SimulatedCompassEntity();
                            e.State.Name = "SimulatedCompassEntity";
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);
                        }

                    } break;

                case Entities.SimulatedGPSEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }

                        else
                        {
                            e = new SimulatedGPSEntity();
                            e.State.Name = "SimulatedGPSEntity";
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);
                        }

                    } break;

                case Entities.SimulatedIREntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }

                        else
                        {
                            e = new SimulatedIREntity(new Pose(entityPosition));
                            e.State.Name = "SimulatedIREntity";
                            e.State.Flags |= EntitySimulationModifiers.DisableCollisions;
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);
                        }

                    } break;
                case Entities.SimulatedLRFEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }
                        else
                        {
                            e = new SimulatedLRFEntity(new Pose(entityPosition));
                            e.State.Name = "SimulatedLRFEntity";
                            e.State.Flags |= EntitySimulationModifiers.DisableCollisions;
                            MakeNameUnique(e);
                            //EntityUIService newservice = new EntityUIService();
                            //newservice.AddBoeBot(new Vector3(1,0,1));
                            //CreateService(laserrangefinder.Contract.Identifier,
                                //Microsoft.Robotics.Simulation.Partners.CreateEntityPartner("http://localhost/" + e.State.Name));
                            entityParent.InsertEntity(e);

                        }

                    } break;
                case Entities.SimulatedSonarEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }
                        else
                        {
                            e = new SimulatedSonarEntity(new Pose(entityPosition));
                            e.State.Name = "SimulatedSonarEntity";
                            e.State.Flags |= EntitySimulationModifiers.DisableCollisions;
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);
                        }

                    } break;
                case Entities.SimulatedWebcamEntity:
                    {
                        if (entityParent == null)
                        {
                            ShowEntityRequiresParentError(entityType.ToString() + " requires parent");
                        }
                        else
                        {
                            e = new SimulatedWebcamEntity(entityPosition,
                                320, 240, 45.0f * (float)Math.PI / 180.0f);
                            e.State.Name = "SimulatedWebcamEntity";
                            MakeNameUnique(e);
                            entityParent.InsertEntity(e);

                        }

                    } break;
            }
            #endregion

            return e;
        }