Example #1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var debugSheet = Asset.Load<SpriteSheet>("DebugSpriteSheet");

            // normal reference one
            var normal = CreateSpriteEntity(debugSheet, "Normal");
            normal.Transform.Position = new Vector3(75, 75, 0);
            normal.Transform.RotationEulerXYZ = new Vector3(0.8f, 1.2f, 0.3f);
            normal.Get<SpriteComponent>().CurrentSprite.Center = new Vector2(75);

            // billboard
            var billboard = CreateSpriteEntity(debugSheet, "Billboard");
            billboard.Transform.Position = new Vector3(150, 150, 0);
            billboard.Transform.RotationEulerXYZ = new Vector3(0.5f, 1f, 1.5f);
            billboard.Get<SpriteComponent>().SpriteType = SpriteType.Billboard;

            // ratio
            var child = CreateSpriteEntity(debugSheet, "Child", false);
            child.Transform.Position = new Vector3(100, 0, 0);
            ratio = CreateSpriteEntity(debugSheet, "OtherRatio");
            ratio.Transform.Position = new Vector3(350, 150, 0);
            ratio.AddChild(child);

            // depth test
            var onBack = CreateSpriteEntity(debugSheet, "OnBack");
            onBack.Transform.Position = new Vector3(75, 250, 0);
            onBack.Transform.RotationEulerXYZ = new Vector3(0, 1f, 0);
            onBack.Get<SpriteComponent>().CurrentSprite.Center = new Vector2(75);
            var onFront = CreateSpriteEntity(debugSheet, "OnFront");
            onFront.Transform.Position = new Vector3(75, 350, 0.1f);
            onFront.Transform.RotationEulerXYZ = new Vector3(0, 1f, 0);
            onFront.Get<SpriteComponent>().CurrentSprite.Center = new Vector2(75);
            var noDepth = CreateSpriteEntity(debugSheet, "NoDepth");
            noDepth.Transform.Position = new Vector3(75, 450, 0.2f);
            noDepth.Get<SpriteComponent>().CurrentSprite.Center = new Vector2(75);
            noDepth.Get<SpriteComponent>().IgnoreDepth = true;

            // create the rotating sprites
            rotatingSprites.Add(CreateSpriteEntity(debugSheet, "Center"));
            rotatingSprites.Add(CreateSpriteEntity(debugSheet, "TopLeft"));
            rotatingSprites.Add(CreateSpriteEntity(debugSheet, "OutOfImage"));

            for (int i = 0; i < rotatingSprites.Count; i++)
                rotatingSprites[i].Transform.Position = new Vector3(ScreenWidth, ScreenHeight, 0) / 2;

            // add all the entities to the scene
            foreach (var entity in entities)
                SceneSystem.SceneInstance.Scene.Entities.Add(entity);

            cameraScript = new TestCamera();
            CameraComponent = cameraScript.Camera;
            Script.Add(cameraScript);

            cameraScript.Yaw = 0;
            cameraScript.Pitch = 0;
            cameraScript.Position = new Vector3(400, 300, 800);
        }
Example #2
0
 public override Entity CreateEntity(EntityWorld world, Entity ship, Entity parent, int? index = default(int?))
 {
     var entity = world.CreateEntity();
     parent.AddChild(entity);
     var xform = entity.AddComponentFromPool<Transform>();
     xform.CopyValuesFrom(Transform);
     var component = new DummyPartComponent(this, ship);
     entity.AddComponent(component);
     entity.AddComponent<IShipPartComponent>(component);
     entity.AddComponent(new BoundingBoxComponent(new FloatRect(-10, -10, 20, 20)));
     return entity;
 }
Example #3
0
        public virtual Entity Install(EntityWorld world, Entity shipEntity, Entity hardpointEntity)
        {
            var slot = hardpointEntity.GetComponent<HardpointComponent>();
            if (!hardpointEntity.IsChildOf(shipEntity)) throw new InvalidOperationException("Cannot install, ship entity does not own hardpoint entity.");
            if (slot == null) throw new InvalidOperationException("Cannot install on non-hardpoint entity.");
            var shipComponent = shipEntity.GetComponent<ShipComponent>();
            var moduleEntity = world.CreateEntity();

            var hardpointTransform = hardpointEntity.GetComponent<Transform>();
            var moduleTransform = moduleEntity.AddComponentFromPool<Transform>();
            moduleTransform.Position = Vector2.Zero;
            moduleTransform.Rotation = 0;
            moduleTransform.Scale = Vector2.One;
            moduleTransform.Origin = -hardpointTransform.Origin;            

            var scale = hardpointTransform.Scale;
            var origin = -hardpointTransform.Origin;
            if (scale.X < 0)
            {
                scale.X = Math.Abs(scale.X);
                origin.X *= -1;
            }
            if (scale.Y < 0)
            {
                scale.Y *= Math.Abs(scale.Y);
                origin.Y *= -1;
            }
            moduleTransform.Scale = scale;
            moduleTransform.Origin = origin;

            hardpointEntity.AddChild(moduleEntity);
            var previousInstalled = slot.InstalledEntity;
            if (previousInstalled != null)
            {
                previousInstalled.GetComponent<ModuleComponent>().Module.Uninstall(shipEntity, previousInstalled);
            }

            if (!string.IsNullOrWhiteSpace(PartGroupId))
            {
                ShipEntityFactory.GetShipModel(PartGroupId).CreateChildEntities(world, moduleEntity);
            }

            var moduleComponent = new ModuleComponent
            {
                HardpointEntity = hardpointEntity,
                Module = this
            };
            slot.InstalledEntity = moduleEntity;
            moduleEntity.AddComponent(moduleComponent);
            return moduleEntity;
        }
            public void Setup()
            {
                entity = new EntityImpl("Child");
                parent = new EntityImpl("Parent");
                parent.AddChild(entity);

                property = new PropertyImpl { Name = "Prop1"};
                parent.AddProperty(property);
            }
Example #5
0
 public override Entity CreateEntity(EntityWorld world, Entity ship, Entity parent, int? index=null)
 {
     var entity = world.CreateEntity();
     parent.AddChild(entity, index);
     var thruster = new ThrusterComponent(this, ship);
     entity.AddComponent<IShipPartComponent>(thruster);
     entity.AddComponent(thruster);
     entity.AddSceneGraphRendererComponent<StandardShipModelRenderer>();
     entity.AddComponentFromPool<Transform>(t=>t.CopyValuesFrom(Transform));
     var spriteManager = ServiceLocator.Instance.GetService<ISpriteManagerService>();
     var spriteComponent = spriteManager.CreateSpriteComponent(SpriteId);
     entity.AddComponent(spriteComponent);
     entity.AddComponent(new BoundingBoxComponent(new FloatRect(0, 0, spriteComponent.TextureRect.Width, spriteComponent.TextureRect.Height)));
     ship.GetComponent<ShipComponent>()?.Thrusters.Add(entity);
     return entity;
 }
        public void SetUp()
        {
            entities = new EntitySetImpl();

            entityParent = new EntityImpl("EntityParent");
            entityParent.AddProperty(new PropertyImpl("PrimaryKey") { Type = "int", IsKeyProperty = true });

            entityChild = new EntityImpl("EntityChild");
            entityParent.AddChild(entityChild);
            entityChild.CopyPropertyFromParent(entityParent.ConcreteProperties[0]);
            entityChild.AddProperty(new PropertyImpl("ActualProperty"){ Type = "string" });

            entities.AddEntity(entityParent);
            entities.AddEntity(entityChild);

            var proc = new MappingProcessor(new OneToOneEntityProcessor());
            mappingSet = proc.CreateOneToOneMapping(entities);
        }
 /// <summary>
 /// Creates a standard entity object. Add it to the scene to get it to render and stuff
 /// </summary>
 public static Entity Create( string name, Point3 pos, float facing, ISource graphicsSource )
 {
     Entity entity = new Entity( );
     entity.Name = name;
     entity.Position = pos;
     entity.Angle = facing;
     entity.AddChild( new EntityGraphics( graphicsSource ) );
     entity.AddChild( new Body( ) );
     return entity;
 }
Example #8
0
        /// <summary>
        /// Create the cockpit entity, that contains:
        /// - The stereoscopic 3D camera,
        /// - The player controlled fighter,
        /// - The HUD
        /// </summary>
        private void CreateCockpit()
        {
            // Materials
            Dictionary<string, Material> materials = new Dictionary<string, Material>()
            {
                {
                    "Seat",
                    new BasicMaterial("Content/Textures/Cockpit.png", typeof(CockpitLayer))
                },
                {
                    "Trail",
                    new BasicMaterial("Content/Textures/Trail.wpk", DefaultLayers.Additive)
                    {
                        SamplerMode = AddressMode.LinearClamp
                    }
                }
            };

            // Player fighter entity
            var playerFighter = new Entity("Player")
            .AddComponent(new Transform3D())
            .AddComponent(new Sound3DEmitter())
            .AddComponent(new FollowPathBehavior("Content/Paths/Fighter_1.txt"))
            .AddComponent(new TrailManager())
            .AddComponent(new TrailsRenderer())
            .AddComponent(new MaterialsMap(materials))
            .AddComponent(new AnimatedParamBehavior("Content/Paths/Fighter1_Lasers.txt"))
            .AddComponent(new FighterController(FighterState.Player, new List<Vector3>() { new Vector3(-3, -1.6f, -9f), new Vector3(3f, -1.6f, -9f) }, SoundType.Engines_1, SoundType.Shoot))
            ;

            // Cockpit model
            Entity cockpitEntity = new Entity()
            .AddComponent(new Transform3D() { LocalScale = Vector3.One * 5, LocalPosition = Vector3.UnitZ * -0.8f })
            .AddComponent(new MaterialsMap(materials))
            .AddComponent(new Model("Content/Models/Cockpit.FBX"))
            .AddComponent(new ModelRenderer())
            ;

            playerFighter.AddChild(cockpitEntity);

            // Hud Entity
            var hud = new HudDecorator("hud");
            playerFighter.AddChild(hud.Entity);

            // Stereoscopic camera
            var stereoscopicCamera = new StereoscopicCameraDecorator("stereoCamera");
            playerFighter.AddChild(stereoscopicCamera.Entity);

            // Guns
            Entity projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(3.376f, -2.689f, -3.499f), Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.Pi) })
                .AddComponent(new ProjectileEmitter(800, 7f, 1, 0));
            playerFighter.AddChild(projectileEmitter);

            projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(-3.376f, -2.689f, -3.499f), Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.Pi) })
                .AddComponent(new ProjectileEmitter(800, 7f, 1, 0.5f));
            playerFighter.AddChild(projectileEmitter);

            #if WINDOWS
            // In Windows platform, you must set the Oculus Rift  rendertarget and view proyections for each eye.
            var OVRService = WaveServices.GetService<WaveEngine.OculusRift.OVRService>();
            if (OVRService != null)
            {
                stereoscopicCamera.SetRenderTarget(OVRService.RenderTarget, OVRService.GetProjectionMatrix(WaveEngine.OculusRift.EyeType.Left), OVRService.GetProjectionMatrix(WaveEngine.OculusRift.EyeType.Right));
            }
            #endif

            this.EntityManager.Add(playerFighter);
        }
Example #9
0
        /// <summary>
        /// Create wingman fighter
        /// </summary>
        private void CreateWingman()
        {
            Dictionary<string, Material> materials = new Dictionary<string, Material>()
            {
                {
                    "Fighter",
                    new NormalMappingMaterial(
                    "Content/Textures/fighter_diffuse.png",
                    "Content/Textures/fighter_normal_spec.png")
                    {
                        AmbientColor = GameResources.AmbientColor
                    }
                },
                {
                    "Glow",
                    new BasicMaterial("Content/Textures/fighter_diffuse.png")
                    {
                        DiffuseColor = GameResources.AmbientColor
                    }
                },
                {
                    "Trail",
                    new BasicMaterial("Content/Textures/Trail.wpk", DefaultLayers.Additive)
                    {
                        SamplerMode = AddressMode.LinearClamp
                    }
                },
                {
                    "Thrust",
                    new BasicMaterial("Content/Textures/Thrust.wpk", DefaultLayers.Additive)
                    {
                        SamplerMode = AddressMode.LinearClamp
                    }
                }
            };

            Entity fighter = new Entity("Wingman")
                .AddComponent(new Transform3D())
                .AddComponent(new Sound3DEmitter())
                .AddComponent(new FollowPathBehavior("Content/Paths/Fighter_2.txt", Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.Pi)))
                .AddComponent(new AnimatedParamBehavior("Content/Paths/Fighter2_Lasers.txt"))
                .AddComponent(new Model("Content/Models/Fighter.FBX"))
                .AddComponent(new MaterialsMap(materials))
                .AddComponent(new ModelRenderer())
                .AddComponent(new TrailManager())
                .AddComponent(new TrailsRenderer())
                .AddComponent(new FighterController(FighterState.Wingman, new List<Vector3>() { new Vector3(-3, 0, 6.8f), new Vector3(3f, 0, 6.8f) }, SoundType.Engines_2, SoundType.Shoot))
            ;

            EntityManager.Add(fighter);

            // Wingman guns
            Entity projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(3.376f, -0.689f, -3.499f) })
                .AddComponent(new ProjectileEmitter(800, 7f, 1, 0));
            fighter.AddChild(projectileEmitter);

            projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(-3.376f, -0.689f, -3.499f) })
                .AddComponent(new ProjectileEmitter(800, 7f, 1, 0.5f));
            fighter.AddChild(projectileEmitter);
        }
Example #10
0
        /// <summary>
        /// Create the enemy fighter entity
        /// </summary>
        private void CreateEnemyFighter()
        {
            Dictionary<string, Material> materials = new Dictionary<string, Material>()
            {
                {
                    "EnemyFighter",
                    new NormalMappingMaterial(
                    "Content/Textures/enemyfighter_diffuse.png",
                    "Content/Textures/enemyfighter_normal_spec.png")
                    {
                        AmbientColor = GameResources.AmbientColor
                    }
                },
                {
                    "EnemyGlow",
                    new BasicMaterial("Content/Textures/enemyfighter_diffuse.png")
                    {
                        DiffuseColor = GameResources.AmbientColor
                    }
                },
                {
                    "Trail",
                    new BasicMaterial("Content/Textures/EnemyTrail.wpk", DefaultLayers.Additive)
                    {
                        SamplerMode = AddressMode.LinearClamp
                    }
                },
                {
                    "EnemyThrust",
                    new BasicMaterial("Content/Textures/EnemyThrust.wpk", DefaultLayers.Additive)
                    {
                        SamplerMode = AddressMode.LinearClamp
                    }
                }
            };

            Entity fighter = new Entity()
                .AddComponent(new Transform3D())
                .AddComponent(new Sound3DEmitter())
                .AddComponent(new FollowPathBehavior("Content/Paths/EnemyFighter.txt", Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.Pi)))
                .AddComponent(new AnimatedParamBehavior("Content/Paths/Enemy_Lasers.txt"))
                .AddComponent(new Model("Content/Models/EnemyFighter.FBX"))
                .AddComponent(new MaterialsMap(materials))
                .AddComponent(new ModelRenderer())
                .AddComponent(new TrailManager())
                .AddComponent(new TrailsRenderer())
                .AddComponent(new FighterController(FighterState.Enemy, new List<Vector3>()
                {
                    new Vector3(-4.5f, -3.7f, 9),
                    new Vector3(4.5f , -3.7f, 9),
                    new Vector3(-4.5f, 3.7f, 9),
                    new Vector3(4.5f , 3.7f, 9),
                }, SoundType.Engines_2, SoundType.Shoot))
                ;

            EntityManager.Add(fighter);

            // Gun entities
            Entity projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(9.197f, 1.99f, -13.959f) })
                .AddComponent(new ProjectileEmitter(800, 5f, 1, 0));
            fighter.AddChild(projectileEmitter);

            projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(-9.197f, 1.99f, -13.959f) })
                .AddComponent(new ProjectileEmitter(800, 5f, 1, 0.75f));
            fighter.AddChild(projectileEmitter);

            projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(9.197f, -1.99f, -13.959f) })
                .AddComponent(new ProjectileEmitter(800, 5f, 1, 0.5f));
            fighter.AddChild(projectileEmitter);

            projectileEmitter = new Entity() { Tag = "Gun" }
                .AddComponent(new Transform3D() { LocalPosition = new Vector3(-9.197f, -1.99f, -13.959f) })
                .AddComponent(new ProjectileEmitter(800, 5f, 1, 0.25f));
            fighter.AddChild(projectileEmitter);
        }