Пример #1
0
        protected override void OnRender( Camera camera )
        {
            base.OnRender( camera );

            if( attachedMesh != null )
            {
                bool visible = camera.IsIntersectsFast( MapBounds );
                attachedMesh.Visible = visible;
                if( visible )
                {
                    //update mesh if needed
                    if( needUpdateVertices )
                    {
                        UpdateMeshVertices();
                        needUpdateVertices = false;
                    }
                    if( needUpdateIndices )
                    {
                        UpdateMeshIndices();
                        needUpdateIndices = false;
                    }
                }
            }
        }
Пример #2
0
		public void DrawGrid( Camera camera )
		{
			//Update renderVertices buffer
			if( renderVertices.Count == 0 )
			{
				renderVertices.Capacity = ( mapSize.X + 1 ) * ( mapSize.Y + 1 );

				if( renderFreeIndices.Capacity < renderVertices.Capacity * 6 )
					renderFreeIndices.Capacity = renderVertices.Capacity * 6;
				if( renderBusyIndices.Capacity < renderVertices.Capacity * 6 )
					renderBusyIndices.Capacity = renderVertices.Capacity * 6;

				for( int y = 0; y < mapSize.Y + 1; y++ )
				{
					for( int x = 0; x < mapSize.X + 1; x++ )
					{
						Vec2 p = mapMotionPosition + new Vec2( x, y ) * GridCellSize;
						renderVertices.Add( new Vec3( p.X, p.Y, GetMotionMapHeight( p ) ) );
					}
				}
			}

			renderFreeIndices.Clear();
			renderBusyIndices.Clear();

			{
				const int tileSize = 10;

				//set color for lines
				camera.DebugGeometry.Color = new ColorValue( 1, 1, 0, .7f );

				//tiles loop
				for( int tileY = 0; tileY < mapSize.Y; tileY += tileSize )
				{
					for( int tileX = 0; tileX < mapSize.X; tileX += tileSize )
					{
						//get tile bounds
						Rect bounds2 = mapMotionPosition + new Rect(
							new Vec2( tileX * GridCellSize, tileY * GridCellSize ),
							new Vec2( ( tileX + tileSize ) * GridCellSize, ( tileY + tileSize ) * GridCellSize ) );

						Bounds worldBounds = Map.Instance.SceneGraph.GetOctreeBoundsWithBoundsOfObjectsOutsideOctree();
						Bounds bounds = new Bounds(
							bounds2.Minimum.X, bounds2.Minimum.Y, worldBounds.Minimum.Z,
							bounds2.Maximum.X, bounds2.Maximum.Y, worldBounds.Maximum.Z );

						//check tile visibility
						if( !camera.IsIntersectsFast( bounds ) )
							continue;

						//check by distance
						{
							float distance = bounds.GetPointDistance( camera.Position );
							if( distance > drawGridDistance )
								continue;
						}

						//loop in tile
						for( int y = tileY; y < tileY + tileSize && y < mapSize.Y; y++ )
						{
							for( int x = tileX; x < tileX + tileSize && x < mapSize.X; x++ )
							{
								int p0 = ( mapSize.X + 1 ) * y + x;
								int p1 = p0 + 1;
								int p2 = p0 + mapSize.X + 1;
								int p3 = p2 + 1;

								//draw lines
								Vec3 offset = new Vec3( 0, 0, .4f );

								//camera.DebugGeometry.Color = new ColorValue( 1, 1, 0 );
								camera.DebugGeometry.AddLine( renderVertices[ p0 ] + offset, renderVertices[ p1 ] + offset );
								camera.DebugGeometry.AddLine( renderVertices[ p0 ] + offset, renderVertices[ p2 ] + offset );

								//add grid buffers
								List<int> list = IsFreeInMapMotion( new Vec2I( x, y ) ) ? renderFreeIndices : renderBusyIndices;
								list.Add( p0 );
								list.Add( p1 );
								list.Add( p2 );

								list.Add( p2 );
								list.Add( p1 );
								list.Add( p3 );
							}
						}
					}
				}
			}

			//draw grids
			camera.DebugGeometry.Color = new ColorValue( 0, 1, 0, .3f );
			camera.DebugGeometry.AddVertexIndexBuffer( renderVertices, renderFreeIndices,
				Mat4.FromTranslate( new Vec3( 0, 0, .2f ) ), false, true );

			camera.DebugGeometry.Color = new ColorValue( 1, 0, 0, .3f );
			camera.DebugGeometry.AddVertexIndexBuffer( renderVertices, renderBusyIndices,
				Mat4.FromTranslate( new Vec3( 0, 0, .2f ) ), false, true );
		}