/// <summary> /// Renderiza la malla, si esta habilitada. /// Para que haya animacion se tiene que haber seteado una y haber /// llamado previamente al metodo updateAnimation() /// Sino se renderiza la pose fija de la malla /// </summary> public void render() { if (!enabled) { return; } Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Aplicar transformaciones updateMeshTransform(); //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Activar AlphaBlending si corresponde activateAlphaBlend(); //Renderizar segun el tipo de render de la malla switch (renderType) { case MeshRenderType.VERTEX_COLOR: //Hacer reset de texturas y materiales texturesManager.clear(0); texturesManager.clear(1); device.Material = TgcD3dDevice.DEFAULT_MATERIAL; //Dibujar mesh d3dMesh.DrawSubset(0); break; case MeshRenderType.DIFFUSE_MAP: //Hacer reset de Lightmap texturesManager.clear(1); //Dibujar cada subset con su Material y DiffuseMap correspondiente for (int i = 0; i < materials.Length; i++) { device.Material = materials[i]; texturesManager.set(0, diffuseMaps[i]); d3dMesh.DrawSubset(i); } break; } //Desactivar alphaBlend resetAlphaBlend(); }
/// <summary> /// Renderizar la caja /// </summary> public void render() { if (!enabled) { return; } Device d3dDevice = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //transformacion if (autoTransformEnable) { this.transform = Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation); } d3dDevice.Transform.World = this.transform; //Activar AlphaBlending activateAlphaBlend(); //renderizar if (texture != null) { texturesManager.set(0, texture); } else { texturesManager.clear(0); } texturesManager.clear(1); d3dDevice.Material = TgcD3dDevice.DEFAULT_MATERIAL; d3dDevice.VertexFormat = CustomVertex.PositionColoredTextured.Format; d3dDevice.SetStreamSource(0, vertexBuffer, 0); d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 12); //Desactivar AlphaBlend resetAlphaBlend(); }
/// <summary> /// Renderizar la pared /// </summary> public void render() { if (!enabled) { return; } Device d3dDevice = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; activateAlphaBlend(); texturesManager.set(0, texture); texturesManager.clear(1); d3dDevice.Material = TgcD3dDevice.DEFAULT_MATERIAL; d3dDevice.Transform.World = Matrix.Identity; d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format; d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertices); resetAlphaBlend(); }
/// <summary> /// Dibujar particulas. /// Emite particulas a medida que avanza el tiempo. /// </summary> public void render() { if (!enabled) { return; } //Ver si hay que generar nuevas particulas float elapsedTime = GuiController.Instance.ElapsedTime; tiempoAcumulado += elapsedTime; if (tiempoAcumulado >= this.creationFrecuency && playing) { tiempoAcumulado = 0.0f; //Inicializa y agrega una particula a la lista de particulas vivas. this.createParticle(); } //Dibujar particulas existentes if (this.particlesAlive.Count > 0) { Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Fijo la textura actual de la particula. texturesManager.clear(0); texturesManager.clear(1); texturesManager.set(0, texture); device.Material = TgcD3dDevice.DEFAULT_MATERIAL; device.RenderState.AlphaBlendEnable = true; device.RenderState.ZBufferWriteEnable = false; device.Transform.World = Matrix.Identity; // Va recorriendo la lista de particulas vivas, // actualizando el tiempo de vida restante, y dibujando. Particle p = this.particlesAlive.peek(); while (p != null) { p.TimeToLive -= elapsedTime; if (p.TimeToLive <= 0) { //Saco la particula de la lista de particulas vivas. this.particlesAlive.dequeue(out p); //Inserto la particula en la lista de particulas muertas. this.particlesDead.Push(p); } else { //Actualizo y Dibujo la partícula this.updateExistingParticle(elapsedTime, p); this.renderParticle(p); } p = this.particlesAlive.peekNext(); } //Restaurar valores de RenderState device.RenderState.AlphaBlendEnable = false; device.RenderState.ZBufferWriteEnable = true; } }
/// <summary> /// Se redefine este método para agregar shaders. /// Es el mismo código del executeRender() pero con la sección de "MeshRenderType.DIFFUSE_MAP" ampliada /// para Shaders. /// </summary> public new void executeRender() { Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Aplicar transformacion de malla if (autoTransformEnable) { this.transform = Matrix.Identity * Matrix.Scaling(scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation); } //estas son las matrices comunes q tienen todos los shaders que hicimos, y q tienen que ser actualizadas device.Transform.World = this.transform; effect.SetValue("xWorld", device.Transform.World); effect.SetValue("xWorldViewProj", device.Transform.World * device.Transform.View * device.Transform.Projection); effect.CommitChanges(); //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Renderizar segun el tipo de render de la malla switch (renderType) { case MeshRenderType.VERTEX_COLOR: //Hacer reset de texturas y materiales texturesManager.clear(0); texturesManager.clear(1); device.Material = TgcD3dDevice.DEFAULT_MATERIAL; int numPasses = effect.Begin(0); for (int n = 0; n < numPasses; n++) { //Iniciar pasada de shader effect.BeginPass(n); //Dibujar mesh d3dMesh.DrawSubset(0); effect.EndPass(); } //Finalizar shader effect.End(); break; case MeshRenderType.DIFFUSE_MAP: //Hacer reset de Lightmap texturesManager.clear(1); //Iniciar Shader e iterar sobre sus Render Passes int numPasses2 = effect.Begin(0); for (int n = 0; n < numPasses2; n++) { //Iniciar pasada de shader effect.BeginPass(n); //Dibujar cada subset con su Material y DiffuseMap correspondiente for (int i = 0; i < materials.Length; i++) { device.Material = materials[i]; texturesManager.set(0, diffuseMaps[i]); d3dMesh.DrawSubset(i); } //Finalizar pasada effect.EndPass(); } //Finalizar shader effect.End(); break; case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP: break; } }