/// <summary>Renders the view.</summary>
        public void Render(Device device)
        {
            device.SetRenderState(RenderState.CullMode, Cull.None);
            device.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
            device.SetRenderState(RenderState.ZWriteEnable, false);

            device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
            device.SetSamplerState(0, SamplerState.MagFilter, _useLinearFiltering ? TextureFilter.Linear : TextureFilter.Point);
            device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Point);

            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);
            device.SetRenderState(RenderState.FillMode, FillMode.Solid);

            device.SetRenderState(RenderState.Lighting, false);
            device.SetTexture(0, _viewTexture);

            device.SetStreamSource(0, _vertexBuffer, 0, Marshal.SizeOf(typeof(DX9TransformedColorTexture)));
            device.VertexDeclaration = _vertexDeclaration;
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
        }
Ejemplo n.º 2
0
 public void Draw(ref Device device, ref Matrix Transformation, ref Matrix View, ref Matrix Proj, ref List<LightClass> Lights, ref float luminosity, ref float percent_negatif)
 {
     if (State != ObjectState.Not_prepared)
     {
         if (State != ObjectState.Disposed)
         {
             for (int i = 0; i < Lights.Count; i++)
             {
                 this.effect.SetValue("LightPosition[" + i.ToString() + "]", new Vector4(Lights[i].Position, 1));
                 this.effect.SetValue("LightDistanceSquared[" + i.ToString() + "]", Lights[i].Range);
                 this.effect.SetValue("LightDiffuseColor[" + i.ToString() + "]", Lights[i].Diffuse.ToVector4());
             }
             this.effect.SetValue("percent_Negatif", percent_negatif);
             this.effect.SetValue("View", View);
             this.effect.SetValue("Projection", Proj);
             this.effect.SetValue("luminosity", luminosity);
             this.effect.Technique = Technique;
             this.effect.Begin();
             this.effect.BeginPass(0);
             this.effect.SetValue("World", SubTransformation * Transformation);
             this.effect.SetValue("WorldInverseTranspose", Matrix.Transpose(Matrix.Invert(SubTransformation * Transformation)));
             device.SetStreamSource(0, VertexBuffer, 0, Utilities.SizeOf<structVertex>());
             device.VertexDeclaration = this.vertexElems3D;
             var aaa = ResManager.getTexture(materialSet.map_Kd, ref device, false);
             device.SetTexture(0, ResManager.ListTextures[ResManager.getTexture(materialSet.map_Kd, ref device, false)].Texture);
             device.SetTexture(1, ResManager.ListTextures[ResManager.getTexture(materialSet.map_Ns, ref device, true)].Texture);
             device.DrawPrimitives(PrimitiveType.TriangleList, 0, Vertices.Length / 3);
             this.effect.EndPass();
             this.effect.End();
         }
         else
         {
             debug.WriteNicely("!", ConsoleColor.DarkRed, "ATTENTION, VOUS TENTEZ D'AFFICHER UN MESH N'EXISTANT PLUS", 0);
         }
     }
     else
     {
         debug.WriteNicely("!", ConsoleColor.DarkRed, "ATTENTION, VOUS TENTEZ D'AFFICHER UN MESH PAS PREPARE", 0);
     }
 }
        public void RenderSur(SharpDX.Direct3D9.Device device, List <ModelViewForm.MeshGroup> meshgroups)
        {
            var colors = new SharpDX.Color[]
            {
                new SharpDX.Color(180, 180, 180, 50),
                new SharpDX.Color(180, 148, 62, 50),
                new SharpDX.Color(114, 124, 206, 50),
                new SharpDX.Color(96, 168, 98, 50),
                new SharpDX.Color(193, 92, 165, 50),
                new SharpDX.Color(203, 90, 76, 50)
            };

            device.SetTexture(0, null);
            device.SetTransform(TransformState.World, SharpDX.Matrix.Identity);

            device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg2);
            device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.TFactor);
            device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.SelectArg2);
            device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.TFactor);

            Dictionary <uint, SharpDX.Matrix> meshgrouptransforms = new Dictionary <uint, SharpDX.Matrix>();

            foreach (var m in meshgroups)
            {
                var k = Utilities.FLModelCRC(m.Name);
                if (meshgrouptransforms.ContainsKey(k))
                {
                    continue;
                }
                else
                {
                    meshgrouptransforms[k] = m.Transform;
                }
            }

            int c = 0;

            foreach (var m in Meshes)
            {
                if (meshgrouptransforms.ContainsKey(m.MeshId))
                {
                    device.SetTransform(TransformState.World, meshgrouptransforms[m.MeshId]);
                }
                else
                {
                    device.SetTransform(TransformState.World, SharpDX.Matrix.Identity);
                }

                List <SharpDX.Vector3> tmpVertices = new List <SharpDX.Vector3>();
                List <int>             tmpTri      = new List <int>();

                foreach (var ss in m.SurfaceSections)
                {
                    foreach (var vert in ss.Vertices)
                    {
                        tmpVertices.Add(new SharpDX.Vector3(vert.X, vert.Y, vert.Z));
                    }

                    foreach (var tg in ss.TriangleGroups)
                    {
                        foreach (var tri in tg.Triangles)
                        {
                            foreach (var i in tri.Indices)
                            {
                                tmpTri.Add(i.VertexId);
                                System.Diagnostics.Debug.Assert(i.VertexId < tmpVertices.Count);
                            }
                        }
                    }
                }

                var color = colors[c % colors.Length];
                device.SetRenderState(RenderState.TextureFactor, color.ToRgba());

                device.DrawIndexedUserPrimitives(SharpDX.Direct3D9.PrimitiveType.TriangleList,
                                                 0, tmpVertices.Count, tmpTri.Count / 3, tmpTri.ToArray(), SharpDX.Direct3D9.Format.Index32, tmpVertices.ToArray());

                c++;
            }
        }