コード例 #1
0
        public void RegisterActors()
        {
            #region 3D Stuff

            SceneGraphManager.CullingActive = false;

            float testTimeOffset = 6000;

            //ship-position path
            Path path = new Path("targetPath",ID);
            path.LoadContent();
            path.AddPoint(new Vector3(0, -100, 0), 0);
            path.AddPoint(new Vector3(0, -300, -8000), testTimeOffset+2000);
            path.AddPoint(new Vector3(500, -100, -16000), 2*testTimeOffset+4000);
            path.AddPoint(new Vector3(000, 500, -24000), 3*testTimeOffset+6000);
            path.AddPoint(new Vector3(0, 0, -30000), 4*testTimeOffset+8000);

            //camera-position path
            Path path2 = new Path("positionPath", ID,Color.Green);
            path2.LoadContent();
            path2.AddPoint(new Vector3(0, 200, 500), 0);
            path2.AddPoint(new Vector3(0, 300, -8000), testTimeOffset+2400);
            path2.AddPoint(new Vector3(500, 100, -16000), 2*testTimeOffset+4400);
            path2.AddPoint(new Vector3(000, 500, -24000), 3*testTimeOffset+6400);
            path2.AddPoint(new Vector3(0, 0, -29000), 4*testTimeOffset+8000);

            path.SetTangents();
            path2.SetTangents();

            SceneGraphManager.RootNode.Children.Add(path);
            SceneGraphManager.RootNode.Children.Add(path2);

            //create a ship
            Ship ship = new Ship("SpaceShip", ID,path);
            ship.LoadContent();
            ship.Updateable = true;

            Planet p = new Planet("testplanet", 1000);
            p.Position = new Vector3(-1000,-1000,-10000);
            p.Visible = true;
            p.LoadContent();

            SceneGraphManager.RootNode.Children.Add(p);

            Laser laser = new Laser("testlaser","laser", 5);
            laser.Visible = false;
            laser.LoadContent();
            SceneGraphManager.RootNode.Children.Add(laser);

            SceneGraphManager.RootNode.Children.Add(ship);

            //cameras
            ChaseCamera chaseCamera = new ChaseCamera("chaseCamera", new Vector3(0, 50, 700), ship);
            chaseCamera.LoadContent();

            FPSCamera fpsCamera = new FPSCamera("fpsCamera", Vector3.Zero, Vector3.UnitZ,500);
            fpsCamera.LoadContent();

            PathCamera pathCamera = new PathCamera("pathCamera",path,path2);
            pathCamera.LoadContent();

            CameraManager.Instance.CurrentCamera = "pathCamera";

            //create a skySphere
            SkySphere skySphere = new SkySphere("skySphere", "level1_skymap", 30000f);
            skySphere.Position = Vector3.Zero;
            skySphere.Visible = true;
            skySphere.LoadContent();

            SceneGraphManager.RootNode.Children.Add(skySphere);

            //100 asteroids with random position, scale and rotation
            Random random = new Random();

            /*
            for (int i = 0; i < 100; i++)
            {
                EffectProperty effectProp = new EffectProperty("TextureMappingEffect");
                effectProp.Effect = ResourceManager.Instance.GetResource<Effect>("TextureMappingEffect");

                MeshObject asteroid01 = new MeshObject("asteroid" + i, "asteroid", 1f);
                //asteroid01.Properties.Add(ActorPropertyType.EFFECT, effectProp);

                CollideableProperty collidable = new CollideableProperty();
                asteroid01.Properties.Add(ActorPropertyType.COLLIDEABLE, collidable);

                asteroid01.Scale = new Vector3(random.Next(15, 100), random.Next(15, 100), random.Next(15, 100));
                asteroid01.Rotation = Quaternion.CreateFromYawPitchRoll(random.Next(20,100),random.Next(20,100),random.Next(20,100));
                asteroid01.Position = new Vector3(random.Next(-1000, 1000), random.Next(-500, 500), random.Next(-100, 0) - i * 300);
                asteroid01.LoadContent();
                asteroid01.SetModelEffect(ResourceManager.Instance.GetResource<Effect>("PPModel"),true);

                SceneGraphManager.RootNode.Children.Add(asteroid01);
            }
             * */

            MeshObject obj = new MeshObject("tea", "teapot", 1.0f);
            obj.LoadContent();
            obj.Position = new Vector3(0,-100,0);
            obj.SetModelEffect(ResourceManager.Instance.GetResource<Effect>("PPModel"), true);
            SceneGraphManager.RootNode.Children.Add(obj);

            #endregion

            #region UI Stuff
            TextElement headline = new TextElement("TextElementHeadline2", new Vector2(500, 20), Color.Yellow, "GamePlayView", ResourceManager.Instance.GetResource<SpriteFont>("Arial"));
            headline.Scale = 1f;
            headline.Visible = false;
            UIManager.Instance.AddActor(headline);

            TextElement TextPositionShip = new TextElement("TextPositionShip", new Vector2(500, 40), Color.Yellow, "GamePlayView", ResourceManager.Instance.GetResource<SpriteFont>("Arial"));
            TextPositionShip.Scale = 1f;
            TextPositionShip.Visible = true;
            UIManager.Instance.AddActor(TextPositionShip);

            //create crossfade
            CrossHair crosshair_near = new CrossHair("crosshair_near", "SpaceShip", "crosshair_near", 1500);
            crosshair_near.LoadContent();
            UIManager.Instance.AddActor(crosshair_near);
            #endregion
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: gbarnes12/atlantis-xna
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            sceneGraph = new SceneGraphManager();
            sceneGraph.CullingActive = false;
            sceneGraph.LightingActive = true;

            #region RESOURCES
            List<Resource> resources = new List<Resource>()
            {
                new Resource() {
                    Name = "crate",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "DefaultEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "TextureMappingEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "NormalMappingEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "FogEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "PPModel",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "PPLight",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "PPDepthNormal",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "chunkheightmap",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "PPLightMesh",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "brick_normal_map",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "Spaceship_nor_hälfte_fertig_NRM",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "wedge_p1_diff_v1",
                    Path = GameApplication.Instance.TexturePath + "SpaceShip\\",
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "wedge_p1_diff_v1_normal",
                    Path = GameApplication.Instance.TexturePath + "SpaceShip\\",
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "Kachel2_bump",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "Checker",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "masonry-wall-normal-map",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "level1_skymap",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "p1_wedge",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "Raumschiff_tex",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "Ground",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "brick_wall",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "sphere",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "raumschiff7",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "wall",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "Arial",
                    Path = GameApplication.Instance.FontPath,
                    Type = ResourceType.SpriteFont
                }
            };

            ResourceManager.Instance.LoadResources(resources);

            sceneGraph.Lighting.Lights.Add(new PointLight("pointLight01", null, new Vector3(2, 1, 0), Color.Red * .85f, 5000));
            sceneGraph.Lighting.Lights.Add(new PointLight("pointLight02", null, new Vector3(-2, 2, 0), Color.Green * .85f, 5000));
            sceneGraph.Lighting.Lights.Add(new PointLight("pointLight02", null, new Vector3(10, 1, 0), Color.White * .85f, 5000));
            sceneGraph.Lighting.LoadContent();
            #endregion

            #region CAMERA
            FPSCamera cam = new FPSCamera("fps", new Vector3(0, 5, -5), new Vector3(0, 3, 0));
            cam.LoadContent();
            CameraManager.Instance.CurrentCamera = "fps";
            #endregion

            #region ACTORS
            FogMaterial mat = new FogMaterial();
            mat.FogStart = 2000;
            mat.LightDirection = new Vector3(1f, 1f, 1);
            mat.LightColor = Vector3.One;

            NormalMapMaterial normal = new NormalMapMaterial();
            normal.NormalMap = ResourceManager.Instance.GetResource<Texture2D>("Spaceship_nor_hälfte_fertig_NRM");
            normal.LightDirection = new Vector3(1f, 1f, .5f);
            normal.LightColor = Vector3.One;
            normal.SpecularPower = 32;

            LightingMaterial lighting = new LightingMaterial();
            lighting.LightDirection = new Vector3(.5f, .5f, .5f);
            //lighting.LightColor = Color.Aqua.ToVector3();

            lighting.SpecularPower = 1;

            MeshObject mesh = new MeshObject("ship", "p1_wedge", 0.01f);
            mesh.Position = new Vector3(0, 3, 0);
            mesh.Scale = new Vector3(0.01f);
            mesh.LoadContent();
            mesh.SetModelEffect(ResourceManager.Instance.GetResource<Effect>("PPModel"), true);
            mesh.Material = lighting;
            sceneGraph.RootNode.Children.Add(mesh);

            MeshObject plane = new MeshObject("plane", "Ground", 0.01f);
            plane.Position = new Vector3(0, 0, 0);
            plane.Scale = new Vector3(0.01f);
            plane.LoadContent();
            plane.Material = lighting;
            plane.SetModelEffect(ResourceManager.Instance.GetResource<Effect>("PPModel"), true);
            sceneGraph.RootNode.Children.Add(plane);

            TextElement element = new TextElement("text", new Vector2(1, 1), Color.Black, "Test", ResourceManager.Instance.GetResource<SpriteFont>("Arial"));
            element.LoadContent();
            UIManager.Instance.AddActor(element);
            #endregion

            MouseDevice.Instance.ResetMouseAfterUpdate = false;
        }