Ejemplo n.º 1
0
        /// <summary>
        /// Initializes mesh with new value.
        /// Unless the heightmap is small, it won't all fit into a single MeshBuffer.
        /// This function chops it into pieces and generates a buffer from each one.
        /// </summary>
        public void Init(VideoDriver driver, HeightMap map, float s, ColorFunc cf)
        {
            width  = map.Width;
            height = map.Height;
            scale  = s;

            if (Mesh.MeshBufferCount > 0)
            {
                Mesh.RemoveMeshBuffer(0, Mesh.MeshBufferCount);
            }

            int sw = 0xffff / (height + 1);             // maximum vertices per meshbuffer

            for (int y0 = 0; y0 < height; y0 += sw)
            {
                int y1 = y0 + sw;
                if (y1 >= height)
                {
                    y1 = height - 1;                     // the last one might be narrower
                }
                addStrip(map, cf, y0, y1);
            }

            Mesh.SetDirty();
            Mesh.RecalculateBoundingBox();
        }
Ejemplo n.º 2
0
        private void ChangeStrokeBrush(object sender, EventArgs e)
        {
            if (this.updateattribute)
            {
                ISvgBrush brush1 = this.graphStroke.Brush;
                if (brush1 is SvgElement)
                {
//					SvgElement element1 = (SvgElement) brush1;
                    string text1 = CodeFunc.CreateString(base.OwnerDocument, ((SvgElement)brush1).Name);
                    if ((this.ParentNode != null) && (((SvgElement)brush1).ParentNode == null))
                    {
                        AttributeFunc.SetAttributeValue((SvgElement)brush1, "id", text1);
                        AttributeFunc.SetAttributeValue(this, "stroke", "url(#" + text1 + ");");
                        base.OwnerDocument.AddDefsElement((SvgElement)brush1);
                    }
                    else
                    {
                        this.svgAttributes["stroke"]     = this.graphStroke;
                        this.svgAnimAttributes["stroke"] = this.graphStroke;
                    }
                }
                else if (brush1 == null)
                {
                    AttributeFunc.SetAttributeValue(this, "stroke", "none");
                }
                else
                {
                    AttributeFunc.SetAttributeValue(this, "stroke", ColorFunc.GetColorString(((SolidColor)brush1).Color));
                    AttributeFunc.SetAttributeValue(this, "stroke-opacity", ((SolidColor)brush1).Opacity.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates a MeshBuffer which represents all the vertices and indices for values of y
        /// between y0 and y1, and add it to the mesh.
        /// </summary>
        void addStrip(HeightMap map, ColorFunc cf, int y0, int y1)
        {
            Vertex3D[] vertices = new Vertex3D[(y1 - y0 + 1) * width];
            ushort[]   indices  = new ushort[(y1 - y0) * (width - 1) * 6];          // "6" is a number of indices in 2 triangles (which forms a quad)

            // calculate vertices

            int i = 0;

            for (int y = y0; y <= y1; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    float z  = map.GetHeight(x, y);
                    float xf = (float)x / (float)width;
                    float yf = (float)y / (float)height;

                    vertices[i++] = new Vertex3D(
                        new Vector3Df(x, scale * z, y),               // position
                        map.GetNormal(x, y, scale),                   // normal
                        calculate(cf, xf, yf, z),                     // color
                        new Vector2Df(xf, yf)                         // tcoords
                        );
                }
            }

            // calculate indices

            i = 0;
            for (int y = y0; y < y1; ++y)
            {
                for (int x = 0; x < width - 1; ++x)
                {
                    int n = (y - y0) * width + x;
                    indices[i++] = (ushort)n;
                    indices[i++] = (ushort)(n + width);
                    indices[i++] = (ushort)(n + width + 1);
                    indices[i++] = (ushort)(n + width + 1);
                    indices[i++] = (ushort)(n + 1);
                    indices[i++] = (ushort)n;
                }
            }

            // append calculated verices and indices to mesh buffer

            MeshBuffer buf = MeshBuffer.Create(VertexType.Standard, IndexType._16Bit);             // create new buffer

            Mesh.AddMeshBuffer(buf);
            buf.Append(vertices, indices);
            buf.RecalculateBoundingBox();
            buf.Drop();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculates single color value for given coordinates.
        /// </summary>
        Color calculate(ColorFunc cf, float x, float y, float z)
        {
            switch (cf)
            {
            case ColorFunc.GreyscaleBasedOnTheHeight:
                int n = (int)(255.0f * z);
                return(new Color(n, n, n));

            case ColorFunc.CoordinateInterpolation:
                return(new Color(128 + (int)(127.0f * x), 128 + (int)(127.0f * y), 255));

            case ColorFunc.PureWhite:
                return(Color.SolidWhite);

            default:
                throw new ArgumentException("Unexpected color function value: " + cf.ToString());
            }
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Calculates single color value for given coordinates.
		/// </summary>
		Color calculate(ColorFunc cf, float x, float y, float z)
		{
			switch (cf)
			{
				case ColorFunc.GreyscaleBasedOnTheHeight:
					int n = (int)(255.0f * z);
					return new Color(n, n, n);

				case ColorFunc.CoordinateInterpolation:
					return new Color(128 + (int)(127.0f * x), 128 + (int)(127.0f * y), 255);

				case ColorFunc.PureWhite:
					return Color.OpaqueWhite;

				default:
					throw new ArgumentException("Unexpected color function value: " + cf.ToString());
			}
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Generates a MeshBuffer which represents all the vertices and indices for values of y
		/// between y0 and y1, and add it to the mesh.
		/// </summary>
		void addStrip(HeightMap map, ColorFunc cf, int y0, int y1)
		{
			Vertex3D[] vertices = new Vertex3D[(y1 - y0 + 1) * width];
			ushort[] indices = new ushort[(y1 - y0) * (width - 1) * 6]; // "6" is a number of indices in 2 triangles (which forms a quad)

			// calculate vertices

			int i = 0;
			for (int y = y0; y <= y1; ++y)
			{
				for (int x = 0; x < width; ++x)
				{
					float z = map.GetHeight(x, y);
					float xf = (float)x / (float)width;
					float yf = (float)y / (float)height;

					vertices[i++] = new Vertex3D(
						new Vector3Df(x, scale * z, y), // position
						map.GetNormal(x, y, scale), // normal
						calculate(cf, xf, yf, z), // color
						new Vector2Df(xf, yf) // tcoords
					);
				}
			}

			// calculate indices

			i = 0;
			for (int y = y0; y < y1; ++y)
			{
				for (int x = 0; x < width - 1; ++x)
				{
					int n = (y - y0) * width + x;
					indices[i++] = (ushort)n;
					indices[i++] = (ushort)(n + width);
					indices[i++] = (ushort)(n + width + 1);
					indices[i++] = (ushort)(n + width + 1);
					indices[i++] = (ushort)(n + 1);
					indices[i++] = (ushort)n;
				}
			}

			// append calculated verices and indices to mesh buffer

			MeshBuffer buf = MeshBuffer.Create(VertexType.Standard, IndexType._16Bit); // create new buffer
			Mesh.AddMeshBuffer(buf);
			buf.Append(vertices, indices);
			buf.RecalculateBoundingBox();
			buf.Drop();
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Initializes mesh with new value.
		/// Unless the heightmap is small, it won't all fit into a single MeshBuffer.
		/// This function chops it into pieces and generates a buffer from each one.
		/// </summary>
		public void Init(VideoDriver driver, HeightMap map, float s, ColorFunc cf)
		{
			width = map.Width;
			height = map.Height;
			scale = s;

			if (Mesh.MeshBufferCount > 0)
				Mesh.RemoveMeshBuffer(0, Mesh.MeshBufferCount);

			int sw = 0xffff / (height + 1); // maximum vertices per meshbuffer

			for (int y0 = 0; y0 < height; y0 += sw)
			{
				int y1 = y0 + sw;
				if (y1 >= height)
					y1 = height - 1; // the last one might be narrower
				addStrip(map, cf, y0, y1);
			}

			Mesh.RecalculateBoundingBox();
		}