Пример #1
0
        public void Draw(Camera cam, bool mirror)
        {
            cam.device.RenderState.DepthBufferWriteEnable = false;

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

            Matrix wMatrix = Matrix.CreateTranslation(0, -0.4f, 0) * Matrix.CreateScale(500) * Matrix.CreateTranslation(cam.location);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix;
                    currentEffect.CurrentTechnique = currentEffect.Techniques["SkyDome"];
                    currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
                    if (mirror)
                        currentEffect.Parameters["xView"].SetValue(cam.Mirror);
                    else
                        currentEffect.Parameters["xView"].SetValue(cam.View);
                    currentEffect.Parameters["xProjection"].SetValue(cam.Projection);
                    currentEffect.Parameters["xTexture"].SetValue(clouds);
                    currentEffect.Parameters["xAmbient"].SetValue(1.0f);
                    currentEffect.Parameters["xEnableLighting"].SetValue(false);
                }
                mesh.Draw();
            }
            cam.device.RenderState.DepthBufferWriteEnable = true;
        }
Пример #2
0
 public void LoadContent(ContentManager cm, Camera cam)
 {
     model = cm.Load<Model>("Models\\dome");
     model.Meshes[0].MeshParts[0].Effect = cam.CloneFX();
     perlin.Initialize(cam.device, 96);
     cloudsRenderTarget = cam.MakeTarget();
     vDeclaration = new VertexDeclaration(cam.device, VertexPositionTexture.VertexElements);
 }
Пример #3
0
 /// <summary>
 /// Отрисовывает сцену с указанной камерой
 /// </summary>
 /// <remarks>
 /// Этот метод необходимо вызывать каждый раз, как требуется перерисовка сцены.
 /// Внутри происходит обновление камеры, поэтому нет нужды делать это где-либо еще
 /// </remarks>
 /// <param name="cam">Камера, настроенная необходимым образом</param>
 public static void Draw(Camera cam)
 {
     if (_locked) return;
     _locked = true;
     Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_STENCIL_BUFFER_BIT);
     Gl.glLoadIdentity();
     cam.Look(); //Обновляем взгляд камеры
     Gl.glPushMatrix();
     //iMap = GenIMap(vertexTree, (int) Math.Sqrt(hMap.Length / 3), new FrustrumCuller());
     DrawMap();
     Gl.glPopMatrix();
     Gl.glFlush();
     ++_frames;
     _locked = false;
 }
Пример #4
0
        public void MapClouds(Camera cam, float time)
        {
            cam.SetTarget(cloudsRenderTarget);
            cam.SetTechnique("PerlinNoise");
            cam.SetParam("xTexture", perlin.Map);
            cam.SetParam("xOvercast", 1.5f);
            cam.SetParam("xTime", time * 0.0005f);

            cam.Begin();
            foreach (EffectPass pass in cam.Technique.Passes)
            {
                pass.Begin();

                cam.device.VertexDeclaration = vDeclaration;
                cam.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, perlin.Vertices, 0, 2);

                pass.End();
            }
            cam.End();
            cam.RevertTarget();
            clouds = cloudsRenderTarget.GetTexture();
        }
Пример #5
0
        public void DrawBase(Camera camera, bool mirror)
        {
            camera.Reflecting = mirror;
            camera.Snap();
            camera.SetTechnique("MultiTextured");
            camera.SetParam("xTexture0", Textures[0]);
            camera.SetParam("xTexture1", Textures[1]);
            camera.SetParam("xTexture2", Textures[2]);
            camera.SetParam("xTexture3", Textures[3]);
            camera.SetParam("xWorld", Matrix.Identity);

            camera.Begin();
            foreach (EffectPass pass in camera.Technique.Passes)
            {
                pass.Begin();

                camera.device.Vertices[0].SetSource(vBuffer, 0, VertexMultitextured.SizeInBytes);
                camera.device.Indices = iBuffer;
                camera.device.VertexDeclaration = vDeclaration;

                int noVertices = vBuffer.SizeInBytes / VertexMultitextured.SizeInBytes;
                int noTriangles = iBuffer.SizeInBytes / sizeof(int) / 3;
                camera.device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, noVertices, 0, noTriangles);

                pass.End();
            }
            camera.End();
        }
Пример #6
0
        private Plane CreatePlane(float height, Vector3 normal, Camera cam, bool clipSide)
        {
            normal.Normalize();
            Vector4 planeCoeffs = new Vector4(normal, height);
            if (clipSide)
                planeCoeffs *= -1;
            planeCoeffs = Vector4.Transform(planeCoeffs, cam.InverseView());
            Plane finalPlane = new Plane(planeCoeffs);

            return finalPlane;
        }
Пример #7
0
        public void MapWater(Camera camera)
        {
            camera.Reflecting = false;
            Plane seaPlane = CreatePlane(waterHeight + 1.5f, Vector3.Down, camera, false);
            camera.device.ClipPlanes[0].Plane = seaPlane;
            camera.device.ClipPlanes[0].IsEnabled = true;
            camera.SetTarget(Refractor);
            DrawBase(camera, false);
            camera.device.ClipPlanes[0].IsEnabled = false;

            camera.RevertTarget();
            waterMap = Refractor.GetTexture();
            //waterMap.Save("watermap.jpg", ImageFileFormat.Jpg);
        }
Пример #8
0
        public void MapMirror(Camera camera, Skydome sky)
        {
            camera.Reflecting = true;
            Plane seaPlane = CreatePlane(waterHeight - 0.5f, Vector3.Down, camera, true);
            camera.device.ClipPlanes[0].Plane = seaPlane;
            camera.device.ClipPlanes[0].IsEnabled = true;
            camera.SetTarget(Reflector);
            sky.Draw(camera, true);
            DrawBase(camera, true);
            camera.device.ClipPlanes[0].IsEnabled = false;

            camera.RevertTarget();
            mirrorMap = Reflector.GetTexture();
            //mirrorMap.Save("mirrormap.jpg", ImageFileFormat.Jpg);
        }
Пример #9
0
 public void LoadContent(ContentManager cm, Camera cam)
 {
     location = Matrix.Identity;
     wind = Vector3.Right;
     if (Name != "")
     {
         Map = cm.Load<Texture2D>(Name);
         width = Map.Width;
         length = Map.Height;
     }
     rippleMap = cm.Load<Texture2D>("Textures\\waterbump");
     Textures[0] = cm.Load<Texture2D>("Textures\\sand");
     Textures[1] = cm.Load<Texture2D>("Textures\\grass");
     Textures[2] = cm.Load<Texture2D>("Textures\\rock");
     Textures[3] = cm.Load<Texture2D>("Textures\\snow");
     Refractor = cam.MakeTarget();
     Reflector = cam.MakeTarget();
     LoadHeights();
     Vertices = SetVertices();
     int[] indices = SetIndices();
     Vertices = CalculateNormals(Vertices, indices);
     SetBuffers(cam.device, Vertices, indices);
     vDeclaration = new VertexDeclaration(cam.device, VertexMultitextured.VertexElements);
     SetWater(cam.device);
     cam.sealevel = waterHeight;
 }
Пример #10
0
        public void DrawWater(Camera camera, float time)
        {
            camera.SetTechnique("Water");
            camera.SetParam("xWorld", Matrix.Identity);
            camera.SetParam("xView", camera.View);
            camera.SetParam("xProjection", camera.Projection);
            camera.SetParam("xReflectionView", camera.Mirror);
            camera.SetParam("xReflectionMap", mirrorMap);
            camera.SetParam("xRefractionMap", waterMap);
            camera.SetParam("xWaterBumpMap", rippleMap);
            camera.SetParam("xWaveLength", 0.1f);
            camera.SetParam("xWaveHeight", 0.3f);
            camera.SetParam("xCamPos", camera.location);
            camera.SetParam("xTime", time);
            camera.SetParam("xWindForce", windPower);
            camera.SetParam("xWindDirection", wind);

            camera.Begin();
            foreach (EffectPass pass in camera.Technique.Passes)
            {
                pass.Begin();

                camera.device.Vertices[0].SetSource(seaBuffer, 0, VertexPositionTexture.SizeInBytes);
                camera.device.Indices = iBuffer;
                camera.device.VertexDeclaration = seaDeclaration;

                int noVertices = seaBuffer.SizeInBytes / VertexPositionTexture.SizeInBytes;
                camera.device.DrawPrimitives(PrimitiveType.TriangleList, 0, noVertices / 3);

                pass.End();
            }
            camera.End();
        }
Пример #11
0
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 1280;
            graphics.PreferredBackBufferHeight = 1024;

            graphics.ApplyChanges();
            Window.Title = "TerrainGen";
            land = new Terrain(300, 300);
            camera = new Camera(land);
            dome = new Skydome();

            base.Initialize();
        }