Пример #1
0
 //Pulls the map, camera, heroes and model from the gamestate.
 public void pullChanges()
 {
     this.worldMap = gameState.getMap("OverWorld");
     this.worldCamera = gameState.Camera;
     this.heroes = gameState.Party.Heroes;
     this.model = gameState.WorldModel;
 }
Пример #2
0
        public void Draw(Camera camera, Effect effect)
        {
            if (!IsAlive)
            {
                return;
            }
            Matrix worldMatrix = Matrix.CreateScale(0.05f, 0.05f, 0.05f) * Matrix.CreateRotationY(MathHelper.Pi) *
                Matrix.CreateFromQuaternion(this.rotation) * Matrix.CreateTranslation(this.position);
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
                    currentEffect.Parameters["xWorld"].SetValue(transforms[mesh.ParentBone.Index] * worldMatrix);
                    currentEffect.Parameters["xView"].SetValue(camera.viewMatrix);
                    currentEffect.Parameters["xProjection"].SetValue(camera.projectionMatrix);
                    currentEffect.Parameters["xEnableLighting"].SetValue(true);
                    currentEffect.Parameters["xLightDirection"].SetValue(new Vector3(-0.5f, -1, -0.5f));
                    currentEffect.Parameters["xAmbient"].SetValue(0.4f);
                }
                mesh.Draw();
            }
        }
Пример #3
0
 public GameState(Game game)
 {
     this.game = game;
     camera = new Camera(game.GraphicsDevice);
     state = "MainMenu";
     observers = new List<IObserver>();
 }
Пример #4
0
        public void DrawSkyDome(Camera camera)
        {
            game.GraphicsDevice.DepthStencilState = DepthStencilState.None;

            Matrix[] modelTransforms = new Matrix[skyDome.Bones.Count];
            skyDome.CopyAbsoluteBoneTransformsTo(modelTransforms);

            Matrix wMatrix = Matrix.CreateTranslation(0, -0.3f, 0) * Matrix.CreateScale(100) * Matrix.CreateTranslation(camera.cameraPos);
            foreach (ModelMesh mesh in skyDome.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix;
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
                    currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
                    currentEffect.Parameters["xView"].SetValue(camera.viewMatrix);
                    currentEffect.Parameters["xProjection"].SetValue(camera.projectionMatrix);
                    currentEffect.Parameters["xTexture"].SetValue(skyTexture);
                    currentEffect.Parameters["xEnableLighting"].SetValue(false);
                }
                mesh.Draw();
            }
            game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
Пример #5
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 //When new game is chosen from the main menu this method initializes some basic values to party, camera etc.
 public void NewGame()
 {
     maps = new Dictionary<string, Map>();
     Hero hero1 = new Hero("Taistelu Jaska", new Vector3(50, 12.1f, -100));
     party = new Party();
     party.addCompany(hero1);
     party.attachObserver(new CameraObserver(this));
     party.addItem("Potion");
     party.addItem("Ether");
     party.addItem("Grenade");
     setModels();
     worldModel = ModelManager.instance(game).models["Taistelu Jaska"];
     worldModel.setPosition(party.Position, party.PartyRotation);
     maps.Add("OverWorld", new Map("eternia", game));
     maps.Add("Battle1", new Map("battle1", game));
     camera = new Camera(game.GraphicsDevice);
     camera.SetUpCamera(Party.Position, Party.PartyRotation);
 }
Пример #6
0
        //Draws the terrain from the indices.
        private void DrawTerrain(Matrix currentViewMatrix, Camera camera)
        {
            effect.CurrentTechnique = effect.Techniques["MultiTextured"];
            effect.Parameters["xWorld"].SetValue(Matrix.Identity);
            effect.Parameters["xView"].SetValue(camera.viewMatrix);
            effect.Parameters["xProjection"].SetValue(camera.projectionMatrix);
            effect.Parameters["xTexture0"].SetValue(sandTexture);
            effect.Parameters["xTexture1"].SetValue(grassTexture);
            effect.Parameters["xTexture2"].SetValue(rockTexture);
            effect.Parameters["xTexture3"].SetValue(snowTexture);
            effect.Parameters["xEnableLighting"].SetValue(true);
            effect.Parameters["xAmbient"].SetValue(0.4f);
            effect.Parameters["xLightDirection"].SetValue(new Vector3(-0.5f, -1, -0.5f));

            game.GraphicsDevice.Indices = terrainIndexBuffer;
            game.GraphicsDevice.SetVertexBuffer(terrainVertexBuffer);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, terrainVertexBuffer.VertexCount, 0, terrainIndexBuffer.IndexCount / 3);
            }
        }
Пример #7
0
        //Draws well a refraction map that draws only things below a clipping plane that we have created horizontally.
        private void DrawRefractionMap(Camera camera)
        {
            Plane refractionPlane = CreatePlane(waterHeight + 1.5f, new Vector3(0, -1, 0), camera.viewMatrix, false, camera);
            effect.Parameters["ClipPlane0"].SetValue(new Vector4(refractionPlane.Normal, refractionPlane.D));
            effect.Parameters["Clipping"].SetValue(true);
            game.GraphicsDevice.SetRenderTarget(refractionRenderTarget);
            game.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
            DrawTerrain(camera.viewMatrix, camera);
            effect.Parameters["Clipping"].SetValue(false);

            refractionMap = refractionRenderTarget;
        }
Пример #8
0
        //defines a horizontal plane at the height of the water, so everything above that plane will not be drawn(or below depending)
        private Plane CreatePlane(float height, Vector3 planeNormalDirection, Matrix currentViewMatrix, bool clipSide, Camera camera)
        {
            planeNormalDirection.Normalize();
            Vector4 planeCoeffs = new Vector4(planeNormalDirection, height);
            if (clipSide)
                planeCoeffs *= -1;

            Matrix worldViewProjection = currentViewMatrix * camera.projectionMatrix;
            Matrix inverseWorldViewProjection = Matrix.Invert(worldViewProjection);
            inverseWorldViewProjection = Matrix.Transpose(inverseWorldViewProjection);

            planeCoeffs = Vector4.Transform(planeCoeffs, inverseWorldViewProjection);
            Plane finalPlane = new Plane(planeCoeffs);

            return finalPlane;
        }
Пример #9
0
        /*
        //doesn't work yet
        public void UpdateViewMatrix(Camera camera)
        {
            Vector3 reflCameraPosition = camera.cameraPos;
            reflCameraPosition.Y = -camera.cameraPos.Y + waterHeight * 2;
            Vector3 reflTargetPos = camera.Target;
            reflTargetPos.Y = -camera.Target.Y + waterHeight * 2;

            Vector3 cameraRight = Vector3.Transform(new Vector3(1, 0, 0), camera.Targetrot);
            Vector3 invUpVector = Vector3.Cross(cameraRight, reflTargetPos - reflCameraPosition);

            reflectionViewMatrix = Matrix.CreateLookAt(reflCameraPosition, reflTargetPos, invUpVector);
        }*/
        //Basically drawing the terrain part by part. First the refraction from the terrain and reflection from the sky and then the skybox / skydome and then the terrain.
        public void Draw(GameTime gameTime, Camera camera)
        {
            DrawRefractionMap(camera);
            DrawReflectionMap(camera);
            game.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            DrawSkyDome(camera.viewMatrix, camera);
            DrawTerrain(camera.viewMatrix, camera);
        }