예제 #1
0
        protected void CreateMesh(IEnumerable <double> x, IEnumerable <double> y, IEnumerable <double> z, int xLength, int yLength)
        {
            lengthU = xLength;
            lengthV = yLength;
            bounds  = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max());
            Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10));

            UpdateModelVertices(x, y, z, xLength, yLength);
            CreateVertsAndInds();
            colourMap        = new ColourMap(ColourMapType.HSV, 256);
            colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256);
            SetColorFromIndices();
            colourMapUpdateTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(0.2)
            };
            colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick);

            lights = new List <SharpDX.Direct3D9.Light>();
            SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light()
            {
                Type = LightType.Directional
            };
            light.Diffuse   = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(0.3f, 0.3f, -0.7f);
            light.Specular  = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            light = new SharpDX.Direct3D9.Light()
            {
                Type = LightType.Directional
            };
            light.Diffuse   = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(-0.3f, -0.3f, -0.7f);
            light.Specular  = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            material          = new SharpDX.Direct3D9.Material();
            material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Diffuse  = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Ambient  = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Power    = 10;
        }
예제 #2
0
        protected void CreateMesh(IEnumerable<double> x, IEnumerable<double> y, IEnumerable<double> z, int xLength, int yLength)
        {
            lengthU = xLength;
            lengthV = yLength;
            bounds = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max());
            Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10));
            UpdateModelVertices(x, y, z, xLength, yLength);
            CreateVertsAndInds();
            colourMap = new ColourMap(ColourMapType.HSV, 256);
            colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256);
            SetColorFromIndices();
            colourMapUpdateTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) };
            colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick);

            lights = new List<SharpDX.Direct3D9.Light>();
            SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional };
            light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(0.3f, 0.3f, -0.7f);
            light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional };
            light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(-0.3f, -0.3f, -0.7f);
            light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            material = new SharpDX.Direct3D9.Material();
            material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Diffuse = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Ambient = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Power = 10;
        }
예제 #3
0
        /// <summary>
        /// Draws the primitive model, using the specified effect. Unlike the other
        /// Draw overload where you just specify the world/view/projection matrices
        /// and color, this method does not set any renderstates, so you must make
        /// sure all states are set to sensible values before you call it.
        /// </summary>
        public override void Draw()
        {
            base.Draw();

            if (vertexBuffer == null || indexBuffer == null)
            {
                return;
            }

            graphicsDevice.SetRenderState(RenderState.SpecularEnable, true);

            graphicsDevice.Material = material;
            graphicsDevice.SetRenderState(RenderState.Ambient, Color.DarkGray.ToArgb());
            graphicsDevice.SetRenderState(RenderState.SpecularEnable, true);

            graphicsDevice.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer);
            graphicsDevice.SetRenderState(RenderState.ZWriteEnable, true);
            graphicsDevice.SetRenderState(RenderState.ZFunc, Compare.LessEqual);
            graphicsDevice.SetRenderState(RenderState.NormalizeNormals, true);

            for (int i = 0; i < lights.Count; ++i)
            {
                SharpDX.Direct3D9.Light light = lights[i];
                graphicsDevice.SetLight(i, ref light);
                graphicsDevice.EnableLight(i, true);
            }

            graphicsDevice.VertexFormat = VertexFormat.Position | VertexFormat.Normal | VertexFormat.Diffuse;
            graphicsDevice.SetStreamSource(0, vertexBuffer, 0, Marshal.SizeOf(typeof(VertexPositionNormalColor)));
            graphicsDevice.Indices = indexBuffer;

            graphicsDevice.SetRenderState(RenderState.AlphaBlendEnable, true);
            graphicsDevice.SetRenderState(RenderState.BlendOperationAlpha, BlendOperation.Add);
            graphicsDevice.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            graphicsDevice.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
            graphicsDevice.SetRenderState(RenderState.SeparateAlphaBlendEnable, false);
            graphicsDevice.SetRenderState(RenderState.CullMode, Cull.Counterclockwise);
            int primitiveCount = indices.Length / 3;

            graphicsDevice.SetRenderState(RenderState.Lighting, true);

            if (MeshLines != MeshLines.None)
            {
                graphicsDevice.SetRenderState(RenderState.DepthBias, -0.0001f);
                graphicsDevice.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Material);
                graphicsDevice.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Material);
                graphicsDevice.SetRenderState(RenderState.SpecularMaterialSource, ColorSource.Material);
                graphicsDevice.SetRenderState(RenderState.FillMode, FillMode.Wireframe);
                if (MeshLines == MeshLines.Triangles)
                {
                    graphicsDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, primitiveCount);
                }
                //else graphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineStrip, 0, 0, vertices.Length, 0, 1);
            }
            if (SurfaceShading != SurfaceShading.None)
            {
                graphicsDevice.SetRenderState(RenderState.DepthBias, 0);
                graphicsDevice.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Color1);
                graphicsDevice.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Color1);
                graphicsDevice.SetRenderState(RenderState.SpecularMaterialSource, ColorSource.Color1);
                graphicsDevice.SetRenderState(RenderState.FillMode, FillMode.Solid);
                graphicsDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, primitiveCount);
            }
        }