Esempio n. 1
0
        protected override void InitializeScene()
        {
            Mesh sphere = MeshLoader.FileToMesh("models/sphere_smooth.obj");
            Mesh plane  = MeshLoader.FileToMesh("models/plane.obj");
            Mesh bgBox  = MeshLoader.FileToMesh("models/cube_flat.obj");


            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/UITextRender.fs" },
                { ShaderType.VertexShader, "shader/UITextRender.vs" }
            }, out ShaderProgram textShader);

            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/texture.fs" },
                { ShaderType.VertexShader, "shader/texture.vs" }
            }, out ShaderProgram shader);

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

            objSphere.AddComponent(new MeshRendererComponent(shader, sphere,
                                                             TextureLoader.FileToTexture("textures/ground4k.png"), 1));
            objSphere.AddComponent(new RotatingComponent());

            GameObject objQuad = new GameObject(new Vector3(-1, 1, 0), "QuadDisplay");

            objQuad.AddComponent(new MeshRendererComponent(shader, plane,
                                                           TextureLoader.FileToTexture("textures/ground4k.png"), 1));
            objQuad.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(90));

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

            uiText.AddComponent(new FLGeneratorComponent(new List <MeshRendererComponent>
            {
                objSphere.GetComponent <MeshRendererComponent>(), objQuad.GetComponent <MeshRendererComponent>()
            },
                                                         512,
                                                         512));


            GameEngine.Instance.CurrentScene.Add(uiText);
            DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>();

            dbg.AddCommand("mov", cmd_ChangeCameraPos);
            dbg.AddCommand("rot", cmd_ChangeCameraRot);
            dbg.AddCommand("reload", cmd_ReLoadScene);
            dbg.AddCommand("next", cmd_NextScene);
            GameEngine.Instance.CurrentScene.Add(dbg.Owner);
            GameEngine.Instance.CurrentScene.Add(objSphere);
            GameEngine.Instance.CurrentScene.Add(objQuad);

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

            bgObj.Scale = new Vector3(25, 1, 25);

            Texture bgTex = TextureLoader.FileToTexture("textures/ground4k.png");

            //BufferOperations.GetRegion<byte>(buf, new int3(), )


            bgObj.AddComponent(new MeshRendererComponent(shader, bgBox, bgTex, 1));
            GameEngine.Instance.CurrentScene.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("configs/camera_fldemo.xml", ref mc);


            GameEngine.Instance.CurrentScene.Add(mainCamera);
            GameEngine.Instance.CurrentScene.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");

            GameEngine.Instance.CurrentScene.Add(zeroPoint);
            LookAtComponent comp = new LookAtComponent();

            comp.SetTarget(zeroPoint);
            inPicCam.AddComponent(comp);
            GameEngine.Instance.CurrentScene.Add(inPicCam);


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

            GameEngine.Instance.CurrentScene.Add(camContainer);
            GameEngine.Instance.AddRenderTarget(splitCam);
        }
Esempio n. 2
0
        protected override void InitializeScene()
        {
            Texture test = TextureLoader.FileToTexture("textures/ground4k.png");


            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);

            Mesh bgBox  = MeshLoader.FileToMesh("models/cube_flat.obj");
            Mesh box    = MeshLoader.FileToMesh("models/cube_flat.obj");
            Mesh sphere = MeshLoader.FileToMesh("models/sphere_smooth.obj");


            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/UITextRender.fs" },
                { ShaderType.VertexShader, "shader/UIRender.vs" }
            }, out ShaderProgram textShader);

            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/texture.fs" },
                { ShaderType.VertexShader, "shader/texture.vs" }
            }, out ShaderProgram shader);

            PhysicsDemoComponent phys = new PhysicsDemoComponent();

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


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

            dbg.AddCommand("mov", cmd_ChangeCameraPos);
            dbg.AddCommand("rot", cmd_ChangeCameraRot);
            dbg.AddCommand("reload", cmd_ReLoadScene);
            dbg.AddCommand("next", cmd_NextScene);
            GameEngine.Instance.CurrentScene.Add(dbg.Owner);

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

            bgObj.Scale = new Vector3(250, 1, 250);
            bgObj.AddComponent(new MeshRendererComponent(shader, bgBox,
                                                         TextureLoader.FileToTexture("textures/ground4k.png"), 1));
            Collider groundCol = new Collider(new Box(Vector3.Zero, 500, 1, 500), hybLayer);

            bgObj.AddComponent(groundCol);
            GameEngine.Instance.CurrentScene.Add(bgObj);

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

            boxO.AddComponent(new MeshRendererComponent(shader, bgBox,
                                                        TextureLoader.FileToTexture("textures/ground4k.png"), 1));
            boxO.AddComponent(new Collider(new Box(Vector3.Zero, 1, 1, 1), physicsLayer));
            boxO.Translate(new Vector3(55, 0, 35));
            GameEngine.Instance.CurrentScene.Add(boxO);


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

            mouseTarget.Scale = new Vector3(1, 1, 1);
            mouseTarget.AddComponent(new MeshRendererComponent(shader, sphere,
                                                               TextureLoader.FileToTexture("textures/ground4k.png"), 1));

            GameEngine.Instance.CurrentScene.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, 3, boxO));
            GameEngine.Instance.CurrentScene.Add(c);
            GameEngine.Instance.CurrentScene.SetCamera(c);
        }