Esempio n. 1
0
        public Player(Scene parent, Vector3 spawnPos, Vector3 viewDir, GameInput gameInput)
        {
            Parent = parent;
            this.gameInput = gameInput;

            //create hud renderer
            hud = new Hud(this);
            parent.guis.Add(hud);

            Position = spawnPos;
            PointingDirection = viewDir;

            upVector = new Vector3(0, 1, 0);
            zNear = 0.1f;
            zFar = 100;

            Shape boxShape = new BoxShape(new JVector(0.5f, 2, 0.5f));

            Body = new RigidBody(boxShape);
            Body.Position = new JVector(Position.X, Position.Y, Position.Z);
            Body.AllowDeactivation = false;

            JMatrix mMatrix = JMatrix.Identity;

            //mBody.SetMassProperties(mMatrix, 2,false);

            Jitter.Dynamics.Constraints.SingleBody.FixedAngle mConstraint = new Jitter.Dynamics.Constraints.SingleBody.FixedAngle(Body);

            parent.world.AddConstraint(mConstraint);
            parent.world.AddBody(Body);

            viewInfo = new ViewInfo(this);
            viewInfo.aspect = (float)gameWindow.Width / (float)gameWindow.Height;
            viewInfo.updateProjectionMatrix();

            tools.Add(new GameMenu(this, gameInput));
            tools.Add(new Spawner(this, gameInput));
            tools.Add(new Grabber(this, gameInput));
            tools.Add(new Remover(this, gameInput));
            tools.Add(new TerrainGun(this, gameInput));

            tool = tools[1];
        }
Esempio n. 2
0
        public Player(Scene parent, Vector3 spawnPos, Vector3 viewDir, GameInput gameInput)
        {
            Parent         = parent;
            this.gameInput = gameInput;

            //create hud renderer
            hud = new Hud(this);
            parent.guis.Add(hud);

            Position          = spawnPos;
            PointingDirection = viewDir;

            upVector = new Vector3(0, 1, 0);

            Shape boxShape = new BoxShape(new JVector(0.5f, 2, 0.5f));

            Body                   = new RigidBody(boxShape);
            Body.Position          = new JVector(Position.X, Position.Y, Position.Z);
            Body.AllowDeactivation = false;

            JMatrix mMatrix = JMatrix.Identity;

            //mBody.SetMassProperties(mMatrix, 2,false);

            Jitter.Dynamics.Constraints.SingleBody.FixedAngle mConstraint = new Jitter.Dynamics.Constraints.SingleBody.FixedAngle(Body);

            parent.world.AddConstraint(mConstraint);
            parent.world.AddBody(Body);

            viewInfo        = new ViewInfo(this);
            viewInfo.aspect = (float)gameWindow.Width / (float)gameWindow.Height;
            viewInfo.updateProjectionMatrix();

            tools.Add(new GameMenu(this, gameInput));
            tools.Add(new Spawner(this, gameInput));
            tools.Add(new TerrainGun(this, gameInput));
            tools.Add(new Grabber(this, gameInput));
            tools.Add(new Remover(this, gameInput));

            tool = tools[1];
        }
Esempio n. 3
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (state == GameState.Playing || state == GameState.Menu)
            {
                // calculate mouse movement
                //gameInput.calcDelta();

                // calculate frame Times
                frameTime += (float)e.Time;
                lastFrameDuration = (float)e.Time;

                // exit game?
                bool ESC = Keyboard[Key.Escape];
                if (ESC && !prevESC)
                {
                    if (state == GameState.Menu)
                    {
                        exitGame();
                    }
                    if (state == GameState.Playing)
                    {
                        enterMenu();
                    }
                }
                prevESC = ESC;

                bool F5 = Keyboard[Key.F5];
                if (F5 && !prevF5)
                {
                    if (state == GameState.Playing)
                    {
                        textureLoader.GrabScreenshot();
                    }
                }
                prevF5 = F5;

                // call scene tree to update
                mScene.update();
            }
            else if (state == GameState.Started)
            {
                //search for related files
                FileSeeker mFileSeeker = new FileSeeker(this);

                //create framebufferset for waterreflections
                waterFramebuffer = framebufferCreator.createFrameBuffer("waterFramebuffer", (int)(virtual_size.X * 0.5), (int)(virtual_size.Y * 0.5));

                RenderOptions mOptionsWater = new RenderOptions(virtual_size);
                mOptionsWater.postProcessing = true;
                mOptionsWater.ssAmbientOccluison = false;
                mOptionsWater.bloom = false;
                mOptionsWater.depthOfField = false;

                waterFramebufferSet = new FramebufferSet(framebufferCreator, waterFramebuffer, mOptionsWater);

                //crate shadow framebuffer
                shadowFramebuffer = framebufferCreator.createFrameBuffer("shadowFramebuffer", mScene.ShadowRes, mScene.ShadowRes, PixelInternalFormat.Rgba16f, false);

                //create main framebufferset
                RenderOptions mOptions = new RenderOptions(virtual_size);
                mOptions.postProcessing = true;
                mOptions.ssAmbientOccluison = true;
                mOptions.bloom = true;
                //mOptions.depthOfField = true;

                mainFramebufferSet = new FramebufferSet(framebufferCreator, framebufferCreator.defaultFb, mOptions);

                state = GameState.InitLoading;

            }
            else if (state == GameState.InitLoading)
            {
                //loading rutine - loads one object each time its called
                float percentageA = 0;
                float percentageB = 0;
                float percentageC = 0;
                float percentageD = 0;
                float percentageE = 0;

                percentageA = meshLoader.loadSingleMeshes();
                if (percentageA == 1)
                {
                    percentageB = shaderLoader.loadSingleShaders();
                }
                if (percentageB == 1)
                {
                    percentageC = textureLoader.loadSingleTextures();
                }
                if (percentageC == 1)
                {
                    percentageD = materialLoader.loadSingleMaterials();
                }
                if (percentageD == 1)
                {
                    percentageE = templateLoader.loadSingleTemplates();
                }

                loadingPercentage = (percentageA + percentageB + percentageC + percentageD + percentageE) / 5f;

                //loadingPercentage = (float)Math.Sqrt(loadingPercentage);

                if (loadingPercentage == 1)
                {
                    //create cubemap buffers
                    mCubemapBufferSets = new CubemapBufferSets(mScene, framebufferCreator, 128);
                    mScene.envTextures = mCubemapBufferSets.outTextures;

                    // create viewInfo for reflection
                    waterViewInfo = new ViewInfo();
                    waterViewInfo.aspect = (float)Width / (float)Height;
                    waterViewInfo.updateProjectionMatrix();

                    //set noise texture
                    mScene.noiseTexture = textureLoader.getTexture("noise_pixel.png");

                    //set shaders for postprocessing
                    mScene.ssaoShader = shaderLoader.getShader("ssao.xsp");
                    mScene.ssaoBlrShader = shaderLoader.getShader("ao_blur.xsp");
                    mScene.ssaoBlrShaderA = shaderLoader.getShader("ao_blur_a.xsp");
                    mScene.bloomCurveShader = shaderLoader.getShader("bloom_curve.xsp");
                    mScene.bloomShader = shaderLoader.getShader("bloom_shader.xsp");
                    mScene.dofpreShader = shaderLoader.getShader("dof_preshader.xsp");
                    mScene.dofShader = shaderLoader.getShader("dof_shader.xsp");
                    mScene.compositeShader = shaderLoader.getShader("composite.xsp");
                    mScene.ssaoBlendShader = shaderLoader.getShader("ssao_blend.xsp");
                    mScene.normalShader = shaderLoader.getShader("ssnormals.xsp");
                    mScene.selectionShader = shaderLoader.getShader("selection.xsp");
                    mScene.copycatShader = shaderLoader.getShader("backdrop.xsp");
                    mScene.wipingShader = shaderLoader.getShader("sMapWipe.xsp");

                    // spawn the player
                    player = new Player(mScene, new Vector3(0, 3, 10), new Vector3(0, 0, -1), gameInput);
                    mScene.sunLight.Parent = player;
                    //player.setInput(gameInput);

                    mScene.init();

                    // load objects saved in database
                    mScene.loadObjects();

                    mScene.selectionShader = shaderLoader.getShader("selection.xsp");
                    mScene.ssNormalShader = shaderLoader.getShader("ssnormals.xsp");
                    mScene.ssNormalShaderNoTex = shaderLoader.getShader("ssnormals_notex.xsp");

                    state = GameState.Playing;
                }

            }
        }
Esempio n. 4
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (state == GameState.Playing || state == GameState.Menu)
            {
                // calculate mouse movement
                //gameInput.calcDelta();

                // calculate frame Times
                frameTime        += (float)e.Time;
                lastFrameDuration = (float)e.Time;

                // exit game?
                bool ESC = Keyboard[Key.Escape];
                if (ESC && !prevESC)
                {
                    if (state == GameState.Menu)
                    {
                        exitGame();
                    }
                    if (state == GameState.Playing)
                    {
                        enterMenu();
                    }
                }
                prevESC = ESC;

                bool F5 = Keyboard[Key.F5];
                if (F5 && !prevF5)
                {
                    if (state == GameState.Playing)
                    {
                        textureLoader.GrabScreenshot();
                    }
                }
                prevF5 = F5;



                // call scene tree to update
                mScene.update();
            }
            else if (state == GameState.Started)
            {
                //search for related files
                FileSeeker mFileSeeker = new FileSeeker(this);

                //create framebufferset for waterreflections
                waterFramebuffer = framebufferCreator.createFrameBuffer("waterFramebuffer", (int)(virtual_size.X * 0.5), (int)(virtual_size.Y * 0.5));

                RenderOptions mOptionsWater = Settings.Instance.video.CreateRenderOptions(VideoSettings.Target.water);

                waterFramebufferSet = new FramebufferSet(framebufferCreator, waterFramebuffer, mOptionsWater);

                //crate shadow framebuffer
                shadowFramebuffer = framebufferCreator.createFrameBuffer(mScene.ShadowRes, mScene.ShadowRes, PixelInternalFormat.Rgba16f, false);

                //create main framebufferset
                RenderOptions mOptions = Settings.Instance.video.CreateRenderOptions(VideoSettings.Target.main);

                mainFramebufferSet = new FramebufferSet(framebufferCreator, framebufferCreator.defaultFb, mOptions);

                state = GameState.InitLoading;
            }
            else if (state == GameState.InitLoading)
            {
                //loading rutine - loads one object each time its called
                float percentageA = 0;
                float percentageB = 0;
                float percentageC = 0;
                float percentageD = 0;
                float percentageE = 0;

                percentageA = meshLoader.loadSingleMeshes();
                if (percentageA == 1)
                {
                    percentageB = shaderLoader.loadSingleShaders();
                }
                if (percentageB == 1)
                {
                    percentageC = textureLoader.loadSingleTextures();
                }
                if (percentageC == 1)
                {
                    percentageD = materialLoader.loadSingleMaterials();
                }
                if (percentageD == 1)
                {
                    percentageE = templateLoader.loadSingleTemplates();
                }

                loadingPercentage = (percentageA + percentageB + percentageC + percentageD + percentageE) / 5f;

                //loadingPercentage = (float)Math.Sqrt(loadingPercentage);

                if (loadingPercentage == 1)
                {
                    //cache results
                    if (Settings.Instance.game.generateCache)
                    {
                        meshLoader.writeCacheFile();
                        shaderLoader.writeCacheFile();
                        //textureLoader.writeCacheFile();
                        materialLoader.writeCacheFile();
                        templateLoader.writeCacheFile();
                    }

                    //create cubemap buffers
                    mCubemapBufferSets = new CubemapBufferSets(mScene, framebufferCreator, 128);
                    mScene.envTextures = mCubemapBufferSets.outTextures;

                    // create viewInfo for reflection
                    waterViewInfo        = new ViewInfo();
                    waterViewInfo.aspect = (float)Width / (float)Height;
                    waterViewInfo.updateProjectionMatrix();

                    //set noise texture
                    mScene.setTextureId(Material.WorldTexture.noise, textureLoader.getTextureId("noise_pixel.png"));

                    //set shaders for postprocessing

                    /* now managed
                     * mScene.ssaoPreShader = shaderLoader.getShader("ssMaker.xsp");
                     * mScene.ssaoShader = shaderLoader.getShader("ssao.xsp");
                     * mScene.ssaoBlrShader = shaderLoader.getShader("ao_blur.xsp");
                     * mScene.ssaoBlrShaderA = shaderLoader.getShader("ao_blur_a.xsp");
                     * mScene.bloomCurveShader = shaderLoader.getShader("bloom_curve.xsp");
                     * mScene.bloomShader = shaderLoader.getShader("bloom_shader.xsp");
                     * mScene.dofpreShader = shaderLoader.getShader("dof_preshader.xsp");
                     * mScene.dofShader = shaderLoader.getShader("dof_shader.xsp");
                     * mScene.compositeShader = shaderLoader.getShader("composite.xsp");
                     * mScene.ssaoBlendShader = shaderLoader.getShader("ssao_blend.xsp");
                     * mScene.copycatShader = shaderLoader.getShader("backdrop.xsp");
                     * mScene.wipingShader = shaderLoader.getShader("sMapWipe.xsp");
                     * mScene.reflectionShader = shaderLoader.getShader("defReflections.xsp");
                     * mScene.lightBlurShader = shaderLoader.getShader("lightBlur.xsp");
                     */

                    // managed setup of shaders
                    mScene.setupShaders();

                    // spawn the player
                    player = new Player(mScene, new Vector3(0, 3, 10), new Vector3(0, 0, -1), gameInput);

                    mScene.init();
                    mScene.sunLight.Parent = player;

                    // load objects saved in database
                    mScene.loadObjects();

                    state = GameState.Playing;
                }
            }
        }