Ejemplo n.º 1
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(75f), //Field of View Vertical
                16f / 9f,                         //Aspect Ratio
                0.1f,                             //Near Plane
                1000f);                           //Far Plane

            BasicCamera bc = new BasicCamera(proj, Vector3.Zero);

            Add(bc);                                                     //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events
            SetCamera(bc);                                               //Sets the Camera as the "active" camera that the scene will be rendered from.

            GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box");  //Creating a new Empty GameObject
            LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component
                DefaultFilepaths.DefaultLitShader,                       //The OpenGL Shader used(Unlit and Lit shaders are provided)
                Prefabs.Cube,                                            //The Mesh that is going to be used by the MeshRenderer
                TextureLoader.ColorToTexture(Color.Red),                 //Diffuse Texture to put on the mesh
                1);                                                      //Render Mask (UI = 1 << 30)

            box.AddComponent(lmr);                                       //Attaching the Renderer to the GameObject
            box.AddComponent(new RotateSelfComponent());                 //Adding a component that rotates the Object on the Y-Axis
            Add(box);                                                    //Adding the Object to the Scene.
        }
Ejemplo n.º 2
0
        protected override void InitializeScene()
        {
            LayerManager.RegisterLayer("raycast", new Layer(1, 2));
            int hybridLayer = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2));

            LayerManager.RegisterLayer("physics", new Layer(1, 1));


            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            LoadTestScene(c);
            LoadGameScene(camera);
            Texture bg = null;

            if (!ComesFromMenu)
            {
                bg = TextureLoader.ColorToTexture(Color.Black);
            }

            LoadLoadingScreen(bg);
            LoadTimer = new GeneralTimer(0.0015f, FinalizeLoad, true);
            AddComponent(LoadTimer);
            TextureGenerator.OnProcessFinished += FinishedTexGen;
            LoadTime = Stopwatch.StartNew();
            TextureGenerator.Process();
        }
Ejemplo n.º 3
0
        private static GameObject CreateGoal(Vector3 position)
        {
            GameObject ret = TileCreator.CreateCube(position, Vector3.One, Quaternion.Identity,
                                                    TextureLoader.ColorToTexture(Color.Red), DefaultFilepaths.DefaultLitShader,
                                                    TextureLoader.ColorToTexture(Color.White));

            ret.AddComponent(new MapEndTrigger());
            return(ret);
        }
Ejemplo n.º 4
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            BasicCamera bc =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), 16 / 9f, 0.1f, 1000f),
                    new Vector3(0, 5, 7)); //Creating a Basic Camera

            SetCamera(bc);
            Add(bc);
            bc.AddComponent(new MouseTrackerComponent());

            GameObject box = new GameObject(Vector3.UnitX * 3, "Box");
            LitMeshRendererComponent boxlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                           Prefabs.Cube,
                                                                           TextureLoader.ColorToTexture(Color.Red), 1);

            box.AddComponent(boxlmr);
            Add(box);

            GameObject box2 = new GameObject(Vector3.UnitX * -3, "Box");
            LitMeshRendererComponent box2lmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                            Prefabs.Cube,
                                                                            TextureLoader.ColorToTexture(Color.Red), 1);

            box2.AddComponent(box2lmr);
            Add(box2);

            //Creating the Collider Shapes
            Entity boxShape = new Box(
                Physics.BEPUutilities.Vector3.Zero,
                2f,
                2f,
                2f);

            Entity box2Shape = new Box(
                Physics.BEPUutilities.Vector3.Zero,
                2f,
                2f,
                2f);


            //Creating A physics layer to be able to control which objects are meant to collide with each other
            int raycastLayerID = LayerManager.RegisterLayer("raycast", new Layer(1, 1));

            //Creating the Components for the Physics Engine
            //Note: There are different ways to get the LayerID than storing it.
            Collider boxCollider  = new Collider(boxShape, raycastLayerID);
            Collider box2Collider = new Collider(box2Shape, LayerManager.LayerToName(raycastLayerID));


            //Adding the Components
            box.AddComponent(boxCollider);
            box2.AddComponent(box2Collider);
            //Making the Camera LookAt the origin
            bc.LookAt(Vector3.Zero);
        }
Ejemplo n.º 5
0
        protected override void InitializeScene()
        {
            int rayLayer     = LayerManager.RegisterLayer("raycast", new Layer(1, 2));
            int hybLayer     = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2));
            int physicsLayer = LayerManager.RegisterLayer("physics", new Layer(1, 1));

            LayerManager.DisableCollisions(rayLayer, physicsLayer);

            PhysicsDemoComponent phys = new PhysicsDemoComponent();

            AddComponent(phys); //Adding Physics Component to world.


            Add(DebugConsoleComponent.CreateConsole());

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG");

            bgObj.Scale = new Vector3(250, 1, 250);
            bgObj.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                         TextureLoader.ColorToTexture(Color.Brown), 1));
            Collider groundCol = new Collider(new Box(Vector3.Zero, 500, 1, 500), hybLayer);

            bgObj.AddComponent(groundCol);
            Add(bgObj);

            GameObject boxO = new GameObject(Vector3.UnitY * 3, "Box");

            boxO.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                        TextureLoader.ColorToTexture(Color.DarkMagenta), 1));
            boxO.AddComponent(new Collider(new Box(Vector3.Zero, 1, 1, 1), physicsLayer));
            boxO.Translate(new Vector3(55, 0, 35));
            Add(boxO);


            GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG");

            mouseTarget.Scale = new Vector3(1, 1, 1);
            mouseTarget.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Sphere,
                                                               TextureLoader.ColorToTexture(Color.GreenYellow), 1));

            Add(mouseTarget);


            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            c.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(-25));
            c.Translate(new Vector3(1, 30, 45));
            c.AddComponent(new CameraRaycaster(mouseTarget, boxO));
            GameEngine.Instance.CurrentScene.Add(c);
            GameEngine.Instance.CurrentScene.SetCamera(c);
        }
Ejemplo n.º 6
0
        public static GameObject[] CreateEnemy(Vector3 position)
        {
            if (!init)
            {
                init      = true;
                headTex   = TextureLoader.FileToTexture("assets/textures/enemyHead.jpg");
                bulletTex = TextureLoader.ColorToTexture(Color.Red);
            }

            Mesh enemyHeadModel = enemyhead_prefab.Copy();
            Mesh enemyModel     = enemy_prefab.Copy();
            Mesh bullet         = bullet_prefab.Copy();


            GameObject enemyHead = new GameObject(new Vector3(0, 0.5f, 0), "Nozzle");
            GameObject enemy     = new GameObject(position, "Enemy");
            Collider   collider  = new Collider(new Sphere(Vector3.Zero, 1, 1), "physics");

            collider.PhysicsCollider.Material      = new Material(10, 10, 0);
            collider.PhysicsCollider.LinearDamping = 0.99f;
            enemy.AddComponent(collider);


            //Movement for Player Head
            OffsetConstraint connection = new OffsetConstraint()
            {
                Damping   = 0,  //Directly over the moving collider, no inertia
                MoveSpeed = 20, //Even less inertia by moving faster in general
            };

            connection.Attach(enemy, Vector3.UnitY * 1);

            enemyHead.AddComponent(connection);
            enemyHead.Scale = new Vector3(0.6f);


            enemyHead.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, enemyHeadModel,
                                                                headTex, 1));
            enemy.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, enemyModel,
                                                            TextureGenerator.GetPlayerTexture(), 1));

            enemy.AddComponent(new EnemyComponent(enemyHead, bullet, DefaultFilepaths.DefaultLitShader, 50, false));


            return(new[] { enemy, enemyHead });
        }
Ejemplo n.º 7
0
        public static GameObject CreateObject_Box(Color input, Vector3 pos, Vector3 scale, ShaderProgram program)
        {
            if (input.R < 128 && input.G < 128 && input.B < 128)
            {
                int r = rnd.Next(0, 2);
                scale.Y += MathF.Clamp((float)(rnd.NextDouble() * 2 - 1) * 10, -1, 10);
                return(CreateCube(pos, scale, Quaternion.Identity, TextureGenerator.GetTexture(r), program,
                                  TextureGenerator.GetSTexture(r)));
            }
            else if (input.R == 255 && input.G == 0 && input.B == 0)
            {
                return(CreateBouncePad(pos - Vector3.UnitY * 2.5f, scale, TextureLoader.ColorToTexture(Color.Red),
                                       program,
                                       TextureLoader.ColorToTexture(Color.White)));
            }

            return(null);
        }
Ejemplo n.º 8
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG");

            bgObj.Scale = new Vector3(25, 1, 25);
            bgObj.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                         TextureLoader.ColorToTexture(Color.MediumPurple), 1));
            Add(bgObj);

            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            c.Translate(new Vector3(0, 4, 0));
            camLookCommandComponent = new LookAtComponent();

            c.AddComponent(camLookCommandComponent);

            sourceCube = new GameObject(Vector3.UnitZ * -5, "Audio Source");

            AudioSourceComponent source = new AudioSourceComponent();

            sourceCube.AddComponent(source);
            sourceCube.AddComponent(new RotateAroundComponent());
            sourceCube.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                              DefaultFilepaths.DefaultTexture, 1));
            if (!AudioLoader.TryLoad("assets/sounds/test_mono_16.wav", out AudioFile clip))
            {
                Console.ReadLine();
            }

            source.Clip    = clip;
            source.Looping = true;
            source.Play();
            Add(sourceCube);

            AudioListener listener = new AudioListener();

            c.AddComponent(listener);
            Add(c);
            SetCamera(c);
        }
Ejemplo n.º 9
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(75f), //Field of View Vertical
                16f / 9f,                         //Aspect Ratio
                0.1f,                             //Near Plane
                1000f);                           //Far Plane

            BasicCamera bc = new BasicCamera(proj, Vector3.UnitY * 7);

            bc.Rotate(Vector3.UnitX, MathHelper.DegreesToRadians(-90));
            Add(bc);                                                                  //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events
            SetCamera(bc);                                                            //Sets the Camera as the "active" camera that the scene will be rendered from.
            bc.AddComponent(new AudioListener());
            GameObject boxContainer      = new GameObject("Container");               //Empty Container at origin
            GameObject box               = new GameObject(-Vector3.UnitZ * 6, "Box"); //Creating a new Empty GameObject
            LitMeshRendererComponent lmr = new LitMeshRendererComponent(              //Creating a Renderer Component
                DefaultFilepaths.DefaultLitShader,                                    //The OpenGL Shader used(Unlit and Lit shaders are provided)
                Prefabs.Cube,                                                         //The Mesh that is going to be used by the MeshRenderer
                TextureLoader.ColorToTexture(Color.Red),                              //Diffuse Texture to put on the mesh
                1);                                                                   //Render Mask (UI = 1 << 30)

            box.AddComponent(lmr);                                                    //Attaching the Renderer to the GameObject

            AudioSourceComponent asc = new AudioSourceComponent();

            AudioLoader.TryLoad("assets/sound.wav", out AudioFile file);
            asc.Clip    = file;
            asc.Looping = true;
            asc.Play();
            asc.UpdatePosition = true; //Enable 3D Tracking the Gameobjects movements and apply it to the audio source
            asc.Gain           = 0.6f;

            box.AddComponent(asc);
            boxContainer.AddComponent(new RotatingComponent());
            boxContainer.Add(box); //Adding the Object to the Scene.
            Add(boxContainer);
        }
Ejemplo n.º 10
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            BasicCamera bc =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), 16 / 9f, 0.1f, 1000f),
                    new Vector3(0, 5, 30)); //Creating a Basic Camera

            SetCamera(bc);
            Add(bc);

            //Creating a Box that is meant to fall down on the kinetic box
            GameObject box = new GameObject(Vector3.UnitZ * -3 + Vector3.UnitY * 2, "Box");
            LitMeshRendererComponent lmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube,
                                                                        TextureLoader.ColorToTexture(Color.Red), 1);

            box.AddComponent(lmr);
            Add(box);

            //Creating a Kinetic Box that will rotate slowly
            GameObject kinetic = new GameObject(Vector3.UnitZ * -3 + Vector3.UnitY * -2, "Box");
            LitMeshRendererComponent kineticlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                               Prefabs.Cube,
                                                                               TextureLoader.ColorToTexture(Color.Green), 1);

            kinetic.AddComponent(kineticlmr);
            kinetic.AddComponent(new RotateKineticBodyComponent());
            Add(kinetic);

            //A Large sphere that will act as a ground
            GameObject ground = new GameObject(Vector3.UnitZ * -3 + Vector3.UnitY * -1, "Box");
            LitMeshRendererComponent groundlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                              Prefabs.Sphere,
                                                                              TextureLoader.ColorToTexture(Color.Blue), 1);

            ground.AddComponent(groundlmr);
            Add(ground);
            ground.Scale         = new Vector3(20, 20, 20);
            ground.LocalPosition = Physics.BEPUutilities.Vector3.UnitY * -25;

            //Creating the Collider Shapes
            Entity boxShape = new Box(
                Physics.BEPUutilities.Vector3.Zero,
                2f,
                2f,
                2f,
                1f);

            Entity kineticShape = new Box(
                Physics.BEPUutilities.Vector3.Zero,
                2f,
                2f,
                2f,
                1f);

            Entity groundShape = new Sphere(
                Vector3.Zero,
                20f);
            //Note: Not specifying the mass when creating makes the shape a static shape that is really cheap computatinally

            //Ground(Sphere) and the falling box is going to have 0 friction and maximum bounciness.
            Material groundPhysicsMaterial = new Material(0, 0, 1f);
            Material boxPhysicsMaterial    = new Material(0, 0, 1f);

            //Creating A physics layer to be able to control which objects are meant to collide with each other
            int physicsLayerID = LayerManager.RegisterLayer("physics", new Layer(1, 1));

            //Creating the Components for the Physics Engine
            //Note: There are different ways to get the LayerID than storing it.
            Collider boxCollider     = new Collider(boxShape, physicsLayerID);
            Collider groundCollider  = new Collider(groundShape, "physics");
            Collider kineticCollider = new Collider(kineticShape, LayerManager.LayerToName(physicsLayerID));

            //Final Collider Setup
            //Kinetic becomes Kinetic
            kineticCollider.PhysicsCollider.BecomeKinematic();
            //Adding the Physics Materials
            boxCollider.PhysicsCollider.Material    = boxPhysicsMaterial;
            groundCollider.PhysicsCollider.Material = groundPhysicsMaterial;

            //Adding the Components
            box.AddComponent(boxCollider);
            kinetic.AddComponent(kineticCollider);
            ground.AddComponent(groundCollider);

            //Making the Camera LookAt the origin
            bc.LookAt(Vector3.Zero);
        }
Ejemplo n.º 11
0
        public static GameObject[] CreatePlayer(Vector3 position, BasicCamera cam)
        {
            Mesh mouseTargetModel = MeshLoader.FileToMesh("assets/models/sphere_smooth.obj");


            GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG");

            mouseTarget.Scale = new Vector3(1, 1, 1);
            mouseTarget.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, mouseTargetModel,
                                                                  Prefabs.White, 1));

            Mesh playerModel = MeshLoader.FileToMesh("assets/models/sphere_smooth.obj");
            Mesh headModel   = MeshLoader.FileToMesh("assets/models/cube_flat.obj");
            Mesh bullet      = MeshLoader.FileToMesh("assets/models/cube_flat.obj");


            GameObject player  = new GameObject(new Vector3(0, 10, 0), "Player");
            GameObject playerH = new GameObject(new Vector3(0, 10, 0), "PlayerHead");
            GameObject lightS  = new GameObject(Vector3.UnitY * 2f, "Light");

            playerH.Add(lightS);
            lightS.AddComponent(new LightComponent()
            {
                AmbientContribution = 0f
            });
            lightS.LocalPosition = Vector3.UnitY * 14f;



            //Movement for camera
            OffsetConstraint cameraController = new OffsetConstraint {
                Damping = 0, MoveSpeed = 2
            };

            cameraController.Attach(player, new Vector3(0, 15, 5));
            cam.AddComponent(cameraController);

            //Rotation for Player Head depending on mouse position
            cam.AddComponent(new CameraRaycaster(mouseTarget, playerH));

            //Movement for Player Head
            OffsetConstraint connection = new OffsetConstraint()
            {
                Damping   = 0,  //Directly over the moving collider, no inertia
                MoveSpeed = 20, //Even less inertia by moving faster in general
            };

            connection.Attach(player, Vector3.UnitY * 1);
            playerH.AddComponent(connection);
            playerH.Scale = new Vector3(0.6f);
            playerH.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, headModel,
                                                              TextureLoader.FileToTexture("assets/textures/playerHead.png"), 1));


            //Player Setup
            Collider collider = new Collider(new Sphere(Vector3.Zero, 1, 10), LayerManager.NameToLayer("physics"));

            collider.PhysicsCollider.PositionUpdateMode = PositionUpdateMode.Continuous;
            collider.PhysicsCollider.Material           = new Material(1.5f, 1.5f, 0);
            collider.PhysicsCollider.LinearDamping      = 0.99f;

            player.AddComponent(collider);


            player.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, playerModel,
                                                             TextureGenerator.GetPlayerTexture(), 1));

            AudioSourceComponent source = new AudioSourceComponent();

            AudioLoader.TryLoad("assets/audio/ShootSound.wav", out ShootSound);
            AudioLoader.TryLoad("assets/audio/ShootSound2.wav", out ShootSound2);
            AudioLoader.TryLoad("assets/audio/SpawnSound.wav", out SpawnSound);
            AudioLoader.TryLoad("assets/audio/JumpSound.wav", out JumpSound);
            source.Clip = SpawnSound;
            source.Play();
            source.UpdatePosition = false;
            source.Gain           = 0.5f;
            player.AddComponent(source);

            player.AddComponent(new PlayerController(playerH, bullet,
                                                     TextureLoader.ColorToTexture(Color.Red), DefaultFilepaths.DefaultLitShader, 650, false, source));
            player.LocalPosition = position;


            GameObject playerUI = new GameObject("PlayerHUD");

            playerUI.AddComponent(new PlayerHUD());


            return(new[] { player, playerH, playerUI });
        }
Ejemplo n.º 12
0
        protected override void InitializeScene()
        {
            creator       = BufferCreator.CreateWithBuiltInTypes();
            iset          = FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, "assets/kernel/");
            checkPipeline = FLProgramCheckBuilder.CreateDefaultCheckBuilder(iset, creator);
            parser        = new FLParser(iset, creator);
            checkPipeline.Attach(parser, true);
            Mesh plane = MeshLoader.FileToMesh("assets/models/plane.obj");

            Texture texQuad   = TextureLoader.ParameterToTexture(1024, 1024, "FLDisplayTextureQuad");
            Texture texSphere = TextureLoader.ParameterToTexture(1024, 1024, "FLDisplayTextureSphere");

            GameObject objSphere = new GameObject(new Vector3(1, 1, 0), "SphereDisplay");

            LitMeshRendererComponent sphereLmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                              Prefabs.Sphere,
                                                                              texSphere, 1);

            objSphere.AddComponent(sphereLmr);
            sphereLmr.Textures = new[]
            { sphereLmr.Textures[0], DefaultFilepaths.DefaultTexture };

            objSphere.AddComponent(new RotatingComponent());

            GameObject objQuad = new GameObject(new Vector3(-1, 1, 0), "QuadDisplay");
            LitMeshRendererComponent quadLmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, plane,
                                                                            texQuad, 1);

            objQuad.AddComponent(quadLmr);
            quadLmr.Textures = new[]
            { quadLmr.Textures[0], DefaultFilepaths.DefaultTexture };

            objQuad.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(45));

            GameObject sourceCube = new GameObject(new Vector3(0, 10, 10), "Light Source");

            sourceCube.AddComponent(new LightComponent());
            sourceCube.AddComponent(new RotateAroundComponent {
                Slow = 0.15f
            });
            sourceCube.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube,
                                                                 TextureLoader.ColorToTexture(Color.White), 1));

            GameObject uiText = new GameObject(new Vector3(0), "UIText");

            uiText.AddComponent(new FlGeneratorComponent(new List <LitMeshRendererComponent>
            {
                sphereLmr, quadLmr
            },
                                                         512,
                                                         512, true));

            Add(sourceCube);
            Add(uiText);
            Add(DebugConsoleComponent.CreateConsole());
            Add(objSphere);
            Add(objQuad);

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG")
            {
                Scale = new Vector3(25, 1, 25)
            };


            bgObj.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube,
                                                            GenerateGroundTexture(), 1));
            Add(bgObj);


            BasicCamera mainCamera =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                         GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            object mc = mainCamera;

            EngineConfig.LoadConfig("assets/configs/camera_fldemo.xml", ref mc);


            Add(mainCamera);
            SetCamera(mainCamera);

            GameObject camContainer = new GameObject("CamContainer");

            BasicCamera inPicCam =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                         GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            inPicCam.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(0));
            inPicCam.Translate(new Vector3(0, 2, 4));
            inPicCam.AddComponent(new RotateAroundComponent());
            GameObject zeroPoint = new GameObject("Zero");

            Add(zeroPoint);
            LookAtComponent comp = new LookAtComponent();

            comp.SetTarget(zeroPoint);
            inPicCam.AddComponent(comp);
            Add(inPicCam);


            splitCam = new RenderTarget(inPicCam, 1, Color.FromArgb(0, 0, 0, 0))
            {
                MergeType = RenderTargetMergeType.Additive,
                ViewPort  = new Rectangle(0, 0, (int)(GameEngine.Instance.Width * 0.3f),
                                          (int)(GameEngine.Instance.Height * 0.3f))
            };

            Add(camContainer);
            GameEngine.Instance.AddRenderTarget(splitCam);
        }
Ejemplo n.º 13
0
        protected override void InitializeScene()
        {
            int rayLayer     = LayerManager.RegisterLayer("raycast", new Layer(1, 2));
            int hybLayer     = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2));
            int physicsLayer = LayerManager.RegisterLayer("physics", new Layer(1, 1));

            LayerManager.DisableCollisions(rayLayer, physicsLayer);

            BasicCamera mainCamera =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                         GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            object mc = mainCamera;

            EngineConfig.LoadConfig("assets/configs/camera_astardemo.xml", ref mc);

            GameObject sourceCube = new GameObject(new Vector3(0, 0, 0), "Light Source");
            GameObject hackCube   = new GameObject(new Vector3(0, 8, -50), "Workaround");

            Add(sourceCube);
            Add(hackCube);
            sourceCube.AddComponent(new LightComponent());


            mainCamera.AddComponent(new CameraRaycaster(sourceCube, hackCube));

            GameObject bgObj = new GameObject(new Vector3(0, -3, -32), "BG")
            {
                Scale = new Vector3(32, 1, 32)
            };

            Collider groundCol = new Collider(new Box(Vector3.Zero, 64, 1, 64), hybLayer);
            Texture  bgTex     = TextureLoader.ColorToTexture(Color.Yellow);

            bgTex.TexType = TextureType.Diffuse;
            bgObj.AddComponent(groundCol);

            tex         = TextureLoader.ColorToTexture(Color.Green);
            beginTex    = TextureLoader.ColorToTexture(Color.Blue);
            endTex      = TextureLoader.ColorToTexture(Color.Red);
            blockTex    = TextureLoader.ColorToTexture(Color.DarkMagenta);
            tex.TexType = beginTex.TexType = endTex.TexType = blockTex.TexType = TextureType.Diffuse;

            DebugConsoleComponent c = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>();

            c.AddCommand("repath", ResetPaths);
            c.AddCommand("rp", ResetPaths);

            Add(c.Owner);

            bgObj.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, bgTex, 1));
            Add(bgObj);
            Add(mainCamera);
            SetCamera(mainCamera);

            Random rnd = new Random();

            nodes = GenerateNodeGraph(64, 64);
            for (int i = 0; i < nodes.GetLength(0); i++)
            {
                for (int j = 0; j < nodes.GetLength(1); j++)
                {
                    if (rnd.Next(0, 6) == 0)
                    {
                        nodes[i, j].Walkable = false;
                        nodes[i, j].Owner
                        .AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                   Prefabs.Sphere, blockTex, 1));
                    }

                    nodes[i, j].Owner.Scale *= 0.3f;

                    Add(nodes[i, j].Owner);
                }
            }
        }