Exemple #1
0
        public void renderScene(float elapsedTime, bool cubemap)
        {
            Device device = GuiController.Instance.D3dDevice;

            //Renderizar terreno
            terrain.render();
            //Renderizar SkyBox
            skyBox.render();
            // dibujo el bosque
            foreach (TgcMesh instance in bosque)
            {
                instance.render();
            }

            // avion
            //avion.Technique = cubemap ? "RenderCubeMap" : "RenderScene";
            avion.render();

            if (!cubemap)
            {
                // dibujo el mesh
                mesh.Technique = "RenderCubeMap";
                mesh.render();
            }
        }
Exemple #2
0
        /// <summary>
        /// Render Loop
        /// </summary>
        internal void render()
        {
            //Frustum culling
            doFrustumCulling();

            //Input
            handleInput();

            //Renderizar terreno
            if (tgcTerrain != null)
            {
                tgcTerrain.render();
            }

            //Renderizar modelos visibles
            foreach (SceneEditorMeshObject meshObj in meshObjects)
            {
                if (meshObj.visible)
                {
                    meshObj.mesh.render();
                }
            }

            //Mostrar BoundingBox de modelos seleccionados
            foreach (SceneEditorMeshObject selectedMeshObj in selectedMeshList)
            {
                selectedMeshObj.mesh.BoundingBox.render();
            }

            //Renderizar gizmo
            translateGizmo.render();
        }
Exemple #3
0
        public static void Render()
        {
            if (!ParametrosDeConfiguracion.RenderIsla)
            {
                return;
            }

            terrain.render();
        }
Exemple #4
0
        public void renderScene(float elapsedTime, String Technique)
        {
            //Dibujamos todos los meshes del escenario
            Random rnd = new Random(1);

            pasto.Effect    = effect;
            pasto.Technique = Technique;
            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    pasto.Position = new Vector3(-i * 200 + rnd.Next(0, 50), 0, -j * 200 + rnd.Next(0, 50));
                    pasto.Scale    = new Vector3(3, 4 + rnd.Next(0, 4), 5);
                    pasto.render();
                }
            }

            arbusto.Effect    = effect;
            arbusto.Technique = Technique;
            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 5; ++j)
                {
                    arbusto.Position = new Vector3(-i * 400 + rnd.Next(0, 50), 0, -j * 400 + rnd.Next(0, 50));
                    arbusto.render();
                }
            }


            arbol.Effect    = effect;
            arbol.Technique = Technique;
            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    arbol.Position = new Vector3(-i * 700 + rnd.Next(0, 50), 0, -j * 700 + rnd.Next(0, 50));
                    arbol.render();
                }
            }


            // -------------------------------------
            //Renderizar terreno
            terrain.Effect    = effect;
            terrain.Technique = Technique;
            terrain.render();
        }
        public override void Render()
        {
            PreRender();

            //Ver si cambio el heightmap
            var selectedHeightmap = (string)Modifiers["heightmap"];

            if (currentHeightmap != selectedHeightmap)
            {
                //Volver a cargar el Heightmap
                currentHeightmap = selectedHeightmap;
                terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0));
            }

            //Ver si cambio alguno de los valores de escala
            var selectedScaleXZ = (float)Modifiers["scaleXZ"];
            var selectedScaleY  = (float)Modifiers["scaleY"];

            if (currentScaleXZ != selectedScaleXZ || currentScaleY != selectedScaleY)
            {
                //Volver a cargar el Heightmap
                currentScaleXZ = selectedScaleXZ;
                currentScaleY  = selectedScaleY;
                terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0));
            }

            //Ver si cambio la textura del terreno
            var selectedTexture = (string)Modifiers["texture"];

            if (currentTexture != selectedTexture)
            {
                //Volver a cargar el DiffuseMap
                currentTexture = selectedTexture;
                terrain.loadTexture(currentTexture);
            }

            //Renderizar terreno
            terrain.render();

            PostRender();
        }
        public override void render(float elapsedTime)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Ver si cambio el heightmap
            string selectedHeightmap = (string)GuiController.Instance.Modifiers["heightmap"];

            if (currentHeightmap != selectedHeightmap)
            {
                //Volver a cargar el Heightmap
                currentHeightmap = selectedHeightmap;
                terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0));
            }

            //Ver si cambio alguno de los valores de escala
            float selectedScaleXZ = (float)GuiController.Instance.Modifiers["scaleXZ"];
            float selectedScaleY  = (float)GuiController.Instance.Modifiers["scaleY"];

            if (currentScaleXZ != selectedScaleXZ || currentScaleY != selectedScaleY)
            {
                //Volver a cargar el Heightmap
                currentScaleXZ = selectedScaleXZ;
                currentScaleY  = selectedScaleY;
                terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0));
            }

            //Ver si cambio la textura del terreno
            string selectedTexture = (string)GuiController.Instance.Modifiers["texture"];

            if (currentTexture != selectedTexture)
            {
                //Volver a cargar el DiffuseMap
                currentTexture = selectedTexture;
                terrain.loadTexture(currentTexture);
            }


            //Renderizar terreno
            terrain.render();
        }
Exemple #7
0
        public override void Render()
        {
            ClearTextures();

            var device = D3DDevice.Instance.Device;

            effect.Technique = "DefaultTechnique";

            // guardo el Render target anterior y seteo la textura como render target
            var pOldRT = device.GetRenderTarget(0);
            var pSurf  = g_pRenderTarget.GetSurfaceLevel(0);

            device.SetRenderTarget(0, pSurf);
            // hago lo mismo con el depthbuffer, necesito el que no tiene multisampling
            var pOldDS = device.DepthStencilSurface;

            device.DepthStencilSurface = g_pDepthStencil;

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            device.BeginScene();

            // -------------------------------------
            //Renderizar terreno
            terrain.Effect    = effect;
            terrain.Technique = "DefaultTechnique";
            terrain.render();
            // skybox
            skyBox.render();
            //Renderizar pista
            circuito.render(effect);
            //Renderizar auto
            car.Effect    = effect;
            car.Technique = "DefaultTechnique";
            car.render();
            // -------------------------------------

            device.EndScene();

            pSurf.Dispose();

            // Ultima pasada vertical va sobre la pantalla pp dicha
            device.SetRenderTarget(0, pOldRT);
            device.DepthStencilSurface = g_pDepthStencilOld;
            device.BeginScene();

            effect.Technique    = "FrameMotionBlur";
            device.VertexFormat = CustomVertex.PositionTextured.Format;
            device.SetStreamSource(0, g_pVBV3D, 0);
            effect.SetValue("g_RenderTarget", g_pRenderTarget);
            effect.SetValue("g_RenderTarget2", g_pRenderTarget2);
            effect.SetValue("g_RenderTarget3", g_pRenderTarget3);
            effect.SetValue("g_RenderTarget4", g_pRenderTarget4);
            effect.SetValue("g_RenderTarget5", g_pRenderTarget5);
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();

            //TgcDrawText.Instance.drawText("Pos: " + this.Camara.Position, 0, 0, Color.Yellow);
            //TgcDrawText.Instance.drawText("Look At: " + CamaraManager.Instance.CurrentCamera.getLookAt(), 500, 0, Color.Yellow);

            if (circuito.en_ruta)
            {
                DrawText.drawText("Tramo:" + circuito.pos_en_ruta, 0, 15, Color.Yellow);
            }

            //TgcDrawText.Instance.drawText("dist_cam:" + dist_cam + "defY" + desf.Y, 0, 0, Color.Yellow);
            //TgcDrawText.Instance.drawText("vel:" + vel, 0, 0, Color.Yellow);

            RenderFPS();
            RenderAxis();
            device.EndScene();
            device.Present();

            ftime += ElapsedTime;
            if (ftime > 0.03f)
            {
                ftime = 0;
                var aux = g_pRenderTarget5;
                g_pRenderTarget5 = g_pRenderTarget4;
                g_pRenderTarget4 = g_pRenderTarget3;
                g_pRenderTarget3 = g_pRenderTarget2;
                g_pRenderTarget2 = g_pRenderTarget;
                g_pRenderTarget  = aux;
            }
        }
Exemple #8
0
        public unsafe override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;

            Control panel3d = GuiController.Instance.Panel3d;

            time += elapsedTime;
            TgcD3dInput d3dInput = GuiController.Instance.D3dInput;

            //Obtener variacion XY del mouse
            if (d3dInput.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
            {
                float mouseX = d3dInput.XposRelative;
                float mouseY = d3dInput.YposRelative;
                float an     = mouseX * 0.1f;

                float x = (float)(LookFrom.X * Math.Cos(an) + LookFrom.Z * Math.Sin(an));
                float z = (float)(LookFrom.Z * Math.Cos(an) - LookFrom.X * Math.Sin(an));
                LookFrom.X  = x;
                LookFrom.Z  = z;
                LookFrom.Y += mouseY * 150f;
            }

            //Determinar distancia de la camara o zoom segun el Mouse Wheel
            if (d3dInput.WheelPos != 0)
            {
                Vector3 vdir = LookFrom - LookAt;
                vdir.Normalize();
                LookFrom = LookFrom - vdir * (d3dInput.WheelPos * 500);
            }

            device.Transform.View = Matrix.LookAtLH(LookFrom, LookAt, new Vector3(0, 1, 0));

            Matrix ant_Proj  = device.Transform.Projection;
            Matrix ant_World = device.Transform.World;
            Matrix ant_View  = device.Transform.View;

            device.Transform.Projection = Matrix.Identity;
            device.Transform.World      = Matrix.Identity;
            device.Transform.View       = Matrix.Identity;
            device.SetRenderState(RenderStates.AlphaBlendEnable, false);

            // rt1= velocidad
            Surface pOldRT = device.GetRenderTarget(0);
            Surface pSurf  = g_pVelocidadOut.GetSurfaceLevel(0);

            device.SetRenderTarget(0, pSurf);
            Surface pOldDS = device.DepthStencilSurface;

            device.DepthStencilSurface = g_pDepthStencil;
            // rt2 = posicion
            Surface pSurf2 = g_pPosOut.GetSurfaceLevel(0);

            device.SetRenderTarget(1, pSurf2);

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();

            effect.SetValue("elapsedTime", elapsedTime);
            effect.Technique = "ComputeVel";
            effect.SetValue("g_pVelocidad", g_pVelocidad);
            effect.SetValue("g_pPos", g_pPos);
            device.VertexFormat = CustomVertex.PositionTextured.Format;
            device.SetStreamSource(0, g_pVBV3D, 0);
            effect.Begin(FX.None);
            effect.BeginPass(1);
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();
            device.EndScene();


            // leo los datos de la textura de velocidades
            // ----------------------------------------------------------------------
            Surface pDestSurf = g_pTempVel.GetSurfaceLevel(0);

            device.GetRenderTargetData(pSurf, pDestSurf);
            Surface pDestSurf2 = g_pTempPos.GetSurfaceLevel(0);

            device.GetRenderTargetData(pSurf2, pDestSurf2);

            float *pDataVel = (float *)pDestSurf.LockRectangle(LockFlags.None).InternalData.ToPointer();
            float *pDataPos = (float *)pDestSurf2.LockRectangle(LockFlags.None).InternalData.ToPointer();

            for (int i = 0; i < MAX_DS; i++)
            {
                for (int j = 0; j < MAX_DS; j++)
                {
                    vel_x[i, j] = *pDataVel++;
                    vel_z[i, j] = *pDataVel++;
                    pDataVel++;     // no usado
                    pDataVel++;     // no usado

                    pos_x[i, j] = *pDataPos++;
                    pos_z[i, j] = *pDataPos++;
                    pos_y[i, j] = *pDataPos++;
                    pDataPos++;     // no usado
                }
            }
            pDestSurf.UnlockRectangle();
            pDestSurf2.UnlockRectangle();

            pSurf.Dispose();
            pSurf2.Dispose();

            device.SetRenderTarget(0, pOldRT);
            device.SetRenderTarget(1, null);
            device.DepthStencilSurface = pOldDS;

            // swap de texturas
            Texture aux = g_pVelocidad;

            g_pVelocidad    = g_pVelocidadOut;
            g_pVelocidadOut = aux;
            aux             = g_pPos;
            g_pPos          = g_pPosOut;
            g_pPosOut       = aux;


            // dibujo pp dicho ----------------------------------------------
            device.Transform.Projection = ant_Proj;
            device.Transform.World      = ant_World;
            device.Transform.View       = ant_View;

            device.BeginScene();
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            //Renderizar terreno
            if ((bool)GuiController.Instance.Modifiers["dibujar_terreno"])
            {
                terrain.render();
            }

            // dibujo las particulas como point sprites
            mesh.Effect    = effect;
            mesh.Technique = "DefaultTechnique";
            effect.SetValue("texDiffuseMap", g_pBaseTexture);

            CustomVertex.PositionColored[,] vertices = new CustomVertex.PositionColored[MAX_DS, MAX_DS];
            for (int i = 0; i < MAX_DS; i++)
            {
                for (int j = 0; j < MAX_DS; j++)
                {
                    float x0 = pos_x[i, j];
                    float z0 = pos_z[i, j];
                    float H  = pos_y[i, j];
                    vertices[i, j] = new CustomVertex.PositionColored(x0, H + esfera_radio, z0, Color.Blue.ToArgb());
                }
            }
            g_pVB.SetData(vertices, 0, LockFlags.None);

            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.SetStreamSource(0, g_pVB, 0);
            device.SetTexture(0, null);
            device.SetRenderState(RenderStates.PointSize, 32);
            device.SetRenderState(RenderStates.PointScaleEnable, true);
            device.SetRenderState(RenderStates.PointSpriteEnable, true);
            device.DrawPrimitives(PrimitiveType.PointList, 0, MAX_DS * MAX_DS);
            device.EndScene();
        }
Exemple #9
0
 public void render()
 {
     terrain2.render();
 }