GetWorldHeight() публичный Метод

public GetWorldHeight ( int x, int z ) : Real
x int
z int
Результат Real
Пример #1
0
		public void Init( TerrainOptions options )
		{
			this.options = options;

			this.numMipMaps = options.maxMipmap;
			this.size = options.size;

			this.terrain = new VertexData();
			this.terrain.vertexStart = 0;

			this.terrain.vertexCount = options.size*options.size;

			VertexDeclaration decl = this.terrain.vertexDeclaration;
			VertexBufferBinding binding = this.terrain.vertexBufferBinding;

			int offset = 0;

			// Position/Normal
			decl.AddElement( POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position );
			decl.AddElement( NORMAL, 0, VertexElementType.Float3, VertexElementSemantic.Normal );

			// TexCoords
			decl.AddElement( TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 );
			offset += VertexElement.GetTypeSize( VertexElementType.Float2 );
			decl.AddElement( TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1 );
			offset += VertexElement.GetTypeSize( VertexElementType.Float2 );
			// TODO: Color

			HardwareVertexBuffer buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.Clone( POSITION ),
			                                                                                 this.terrain.vertexCount,
			                                                                                 BufferUsage.StaticWriteOnly, true );

			binding.SetBinding( POSITION, buffer );

			buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.Clone( NORMAL ), this.terrain.vertexCount,
			                                                            BufferUsage.StaticWriteOnly, true );

			binding.SetBinding( NORMAL, buffer );

			buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.Clone( TEXCOORD ), this.terrain.vertexCount,
			                                                            BufferUsage.StaticWriteOnly, true );

			binding.SetBinding( TEXCOORD, buffer );

			this.minLevelDistSqr = new float[this.numMipMaps];

			int endx = options.startx + options.size;
			int endz = options.startz + options.size;

			// TODO: name buffers different so we can unlock
			HardwareVertexBuffer posBuffer = binding.GetBuffer( POSITION );
			var pos = posBuffer.Lock( BufferLocking.Discard );

			HardwareVertexBuffer texBuffer = binding.GetBuffer( TEXCOORD );
			var tex = texBuffer.Lock( BufferLocking.Discard );

			float min = 99999999, max = 0;

#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				var posPtr = pos.ToFloatPointer();
				var texPtr = tex.ToFloatPointer();

				int posCount = 0;
				int texCount = 0;

				for ( int j = options.startz; j < endz; j++ )
				{
					for ( int i = options.startx; i < endx; i++ )
					{
						float height = options.GetWorldHeight( i, j )*options.scaley;

						posPtr[ posCount++ ] = i*options.scalex;
						posPtr[ posCount++ ] = height;
						posPtr[ posCount++ ] = j*options.scalez;

						texPtr[ texCount++ ] = (float)i/options.worldSize;
						texPtr[ texCount++ ] = (float)j/options.worldSize;

						texPtr[ texCount++ ] = ( (float)i/options.size )*options.detailTile;
						texPtr[ texCount++ ] = ( (float)j/options.size )*options.detailTile;

						if ( height < min )
						{
							min = height;
						}

						if ( height > max )
						{
							max = height;
						}
					} // for i
				} // for j
			} // unsafe

			// unlock the buffers
			posBuffer.Unlock();
			texBuffer.Unlock();

			this.box.SetExtents( new Vector3( options.startx*options.scalex, min, options.startz*options.scalez ),
			                     new Vector3( ( endx - 1 )*options.scalex, max, ( endz - 1 )*options.scalez ) );

			this.center = new Vector3( ( options.startx*options.scalex + endx - 1 )/2, ( min + max )/2,
			                           ( options.startz*options.scalez + endz - 1 )/2 );

			float C = CalculateCFactor();

			CalculateMinLevelDist2( C );
		}
Пример #2
0
        public void Init(TerrainOptions options)
        {
            this.options = options;

            this.numMipMaps = options.maxMipmap;
            this.size       = options.size;

            this.terrain             = new VertexData();
            this.terrain.vertexStart = 0;

            this.terrain.vertexCount = options.size * options.size;

            VertexDeclaration   decl    = this.terrain.vertexDeclaration;
            VertexBufferBinding binding = this.terrain.vertexBufferBinding;

            int offset = 0;

            // Position/Normal
            decl.AddElement(POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position);
            decl.AddElement(NORMAL, 0, VertexElementType.Float3, VertexElementSemantic.Normal);

            // TexCoords
            decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0);
            offset += VertexElement.GetTypeSize(VertexElementType.Float2);
            decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1);
            offset += VertexElement.GetTypeSize(VertexElementType.Float2);
            // TODO: Color

            HardwareVertexBuffer buffer = HardwareBufferManager.Instance.CreateVertexBuffer(decl.Clone(POSITION),
                                                                                            this.terrain.vertexCount,
                                                                                            BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(POSITION, buffer);

            buffer = HardwareBufferManager.Instance.CreateVertexBuffer(decl.Clone(NORMAL), this.terrain.vertexCount,
                                                                       BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(NORMAL, buffer);

            buffer = HardwareBufferManager.Instance.CreateVertexBuffer(decl.Clone(TEXCOORD), this.terrain.vertexCount,
                                                                       BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(TEXCOORD, buffer);

            this.minLevelDistSqr = new float[this.numMipMaps];

            int endx = options.startx + options.size;
            int endz = options.startz + options.size;

            // TODO: name buffers different so we can unlock
            HardwareVertexBuffer posBuffer = binding.GetBuffer(POSITION);
            var pos = posBuffer.Lock(BufferLocking.Discard);

            HardwareVertexBuffer texBuffer = binding.GetBuffer(TEXCOORD);
            var tex = texBuffer.Lock(BufferLocking.Discard);

            float min = 99999999, max = 0;

#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                var posPtr = pos.ToFloatPointer();
                var texPtr = tex.ToFloatPointer();

                int posCount = 0;
                int texCount = 0;

                for (int j = options.startz; j < endz; j++)
                {
                    for (int i = options.startx; i < endx; i++)
                    {
                        float height = options.GetWorldHeight(i, j) * options.scaley;

                        posPtr[posCount++] = i * options.scalex;
                        posPtr[posCount++] = height;
                        posPtr[posCount++] = j * options.scalez;

                        texPtr[texCount++] = (float)i / options.worldSize;
                        texPtr[texCount++] = (float)j / options.worldSize;

                        texPtr[texCount++] = ((float)i / options.size) * options.detailTile;
                        texPtr[texCount++] = ((float)j / options.size) * options.detailTile;

                        if (height < min)
                        {
                            min = height;
                        }

                        if (height > max)
                        {
                            max = height;
                        }
                    }     // for i
                }         // for j
            }             // unsafe

            // unlock the buffers
            posBuffer.Unlock();
            texBuffer.Unlock();

            this.box.SetExtents(new Vector3(options.startx * options.scalex, min, options.startz * options.scalez),
                                new Vector3((endx - 1) * options.scalex, max, (endz - 1) * options.scalez));

            this.center = new Vector3((options.startx * options.scalex + endx - 1) / 2, (min + max) / 2,
                                      (options.startz * options.scalez + endz - 1) / 2);

            float C = CalculateCFactor();

            CalculateMinLevelDist2(C);
        }
        public void Init(TerrainOptions options)
        {
            this.options = options;

            numMipMaps = options.maxMipmap;
            size       = options.size;

            terrain             = new VertexData();
            terrain.vertexStart = 0;
            // Turbo: appended factor 3
            //        Not sure about that, but without that the terrain manager seems
            //        to mess up memory because of buffer overruns
            //terrain.vertexCount = options.size * options.size;
            terrain.vertexCount = options.size * options.size * 3;

            VertexDeclaration   decl    = terrain.vertexDeclaration;
            VertexBufferBinding binding = terrain.vertexBufferBinding;

            int offset = 0;

            // Position/Normal
            decl.AddElement(POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position);
            decl.AddElement(NORMAL, 0, VertexElementType.Float3, VertexElementSemantic.Normal);

            // TexCoords
            decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0);
            offset += VertexElement.GetTypeSize(VertexElementType.Float2);
            decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1);
            offset += VertexElement.GetTypeSize(VertexElementType.Float2);
            // TODO: Color

            HardwareVertexBuffer buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                    decl.GetVertexSize(POSITION),
                    terrain.vertexCount,
                    BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(POSITION, buffer);


            buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                    decl.GetVertexSize(NORMAL),
                    terrain.vertexCount,
                    BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(NORMAL, buffer);

            buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                    offset,
                    terrain.vertexCount,
                    BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(TEXCOORD, buffer);

            minLevelDistSqr = new float[numMipMaps];

            int endx = options.startx + options.size;
            int endz = options.startz + options.size;

            // TODO: name buffers different so we can unlock
            HardwareVertexBuffer posBuffer = binding.GetBuffer(POSITION);
            IntPtr pos = posBuffer.Lock(BufferLocking.Discard);

            HardwareVertexBuffer texBuffer = binding.GetBuffer(TEXCOORD);
            IntPtr tex = texBuffer.Lock(BufferLocking.Discard);

            float min = 99999999, max = 0;

            unsafe {
                float *posPtr = (float *)pos.ToPointer();
                float *texPtr = (float *)tex.ToPointer();

                int posCount = 0;
                int texCount = 0;

                for (int j = options.startz; j < endz; j++)
                {
                    for (int i = options.startx; i < endx; i++)
                    {
                        float height = options.GetWorldHeight(i, j) * options.scaley;

                        posPtr[posCount++] = (float)i * options.scalex;
                        posPtr[posCount++] = height;
                        posPtr[posCount++] = (float)j * options.scalez;

                        texPtr[texCount++] = (float)i / (float)options.worldSize;
                        texPtr[texCount++] = (float)j / (float)options.worldSize;

                        texPtr[texCount++] = ((float)i / (float)options.size) * (float)options.detailTile;
                        texPtr[texCount++] = ((float)j / (float)options.size) * (float)options.detailTile;

                        if (height < min)
                        {
                            min = height;
                        }

                        if (height > max)
                        {
                            max = height;
                        }
                    } // for i
                }     // for j
            }         // unsafe

            // unlock the buffers
            posBuffer.Unlock();
            texBuffer.Unlock();

            box.SetExtents(
                new Vector3((float)options.startx * options.scalex, min, (float)options.startz * options.scalez),
                new Vector3((float)(endx - 1) * options.scalex, max, (float)(endz - 1) * options.scalez));


            center = new Vector3((options.startx * options.scalex + endx - 1) / 2,
                                 (min + max) / 2,
                                 (options.startz * options.scalez + endz - 1) / 2);

            float C = CalculateCFactor();

            CalculateMinLevelDist2(C);
        }
        public void Init(TerrainOptions options)
        {
            this.options = options;

            numMipMaps = options.maxMipmap;
            size = options.size;

            terrain = new VertexData();
            terrain.vertexStart = 0;
            // Turbo: appended factor 3
            //        Not sure about that, but without that the terrain manager seems
            //        to mess up memory because of buffer overruns
            //terrain.vertexCount = options.size * options.size;
            terrain.vertexCount = options.size * options.size * 3;

            VertexDeclaration decl = terrain.vertexDeclaration;
            VertexBufferBinding binding = terrain.vertexBufferBinding;

            int offset = 0;

            // Position/Normal
            decl.AddElement(POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position);
            decl.AddElement(NORMAL, 0, VertexElementType.Float3, VertexElementSemantic.Normal);

            // TexCoords
            decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0);
            offset += VertexElement.GetTypeSize(VertexElementType.Float2);
            decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1);
            offset += VertexElement.GetTypeSize(VertexElementType.Float2);
            // TODO: Color

            HardwareVertexBuffer buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                decl.GetVertexSize(POSITION),
                terrain.vertexCount,
                BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(POSITION, buffer);

            buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                decl.GetVertexSize(NORMAL),
                terrain.vertexCount,
                BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(NORMAL, buffer);

            buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                offset,
                terrain.vertexCount,
                BufferUsage.StaticWriteOnly, true);

            binding.SetBinding(TEXCOORD, buffer);

            minLevelDistSqr = new float[numMipMaps];

            int endx = options.startx + options.size;
            int endz = options.startz + options.size;

            // TODO: name buffers different so we can unlock
            HardwareVertexBuffer posBuffer = binding.GetBuffer(POSITION);
            IntPtr pos = posBuffer.Lock(BufferLocking.Discard);

            HardwareVertexBuffer texBuffer = binding.GetBuffer(TEXCOORD);
            IntPtr tex = texBuffer.Lock(BufferLocking.Discard);

            float min = 99999999, max = 0;

            unsafe {
                float* posPtr = (float*)pos.ToPointer();
                float* texPtr = (float*)tex.ToPointer();

                int posCount = 0;
                int texCount = 0;

                for(int j = options.startz; j < endz; j++) {
                    for(int i = options.startx; i < endx; i++) {
                        float height = options.GetWorldHeight(i, j) * options.scaley;

                        posPtr[posCount++] = (float)i * options.scalex;
                        posPtr[posCount++] = height;
                        posPtr[posCount++] = (float)j * options.scalez;

                        texPtr[texCount++] = (float)i / (float)options.worldSize;
                        texPtr[texCount++] = (float)j / (float)options.worldSize;

                        texPtr[texCount++] = ((float)i / (float)options.size) * (float)options.detailTile;
                        texPtr[texCount++] = ((float)j / (float)options.size) * (float)options.detailTile;

                        if(height < min) {
                            min = height;
                        }

                        if(height > max) {
                            max = height;
                        }
                    } // for i
                } // for j
            } // unsafe

            // unlock the buffers
            posBuffer.Unlock();
            texBuffer.Unlock();

            box.SetExtents(
                new Vector3((float) options.startx * options.scalex, min, (float)options.startz * options.scalez),
                new Vector3((float)(endx - 1) * options.scalex, max, (float)(endz - 1) * options.scalez));

            center = new Vector3((options.startx * options.scalex + endx - 1) / 2,
                (min + max) / 2,
                (options.startz * options.scalez + endz - 1) / 2);

            float C = CalculateCFactor();

            CalculateMinLevelDist2(C);
        }