Beispiel #1
0
void DebugDrawer::drawPolyhedron( const AnyPolyhedron& polyhedron, const ColorF& color )
{
   const PolyhedronData::Edge* edges = polyhedron.getEdges();
   const Point3F* points = polyhedron.getPoints();
   const U32 numEdges = polyhedron.getNumEdges();

   for( U32 i = 0; i < numEdges; ++ i )
   {
      const PolyhedronData::Edge& edge = edges[ i ];
      drawLine( points[ edge.vertex[ 0 ] ], points[ edge.vertex[ 1 ] ], color );
   }
}
Beispiel #2
0
void GFXDrawUtil::_drawWirePolyhedron( const GFXStateBlockDesc &desc, const AnyPolyhedron &poly, const ColorI &color, const MatrixF *xfm )
{
   GFXDEBUGEVENT_SCOPE( GFXDrawUtil_DrawWirePolyhedron, ColorI::GREEN );

   const U32 numEdges = poly.getNumEdges();
   const Point3F* points = poly.getPoints();
   const Polyhedron::Edge* edges = poly.getEdges();

   // Allocate a temporary vertex buffer.

   GFXVertexBufferHandle< GFXVertexPC > verts( mDevice, numEdges * 2, GFXBufferTypeVolatile);

   // Fill it with the vertices for the edges.
   
   verts.lock();
   for( U32 i = 0; i < numEdges; ++ i )
   {
      const U32 nvert = i * 2;
      verts[ nvert + 0 ].point = points[ edges[ i ].vertex[ 0 ] ];
      verts[ nvert + 0 ].color = color;

      verts[ nvert + 1 ].point = points[ edges[ i ].vertex[ 1 ] ];
      verts[ nvert + 1 ].color = color;
   }

   if( xfm )
   {
      for( U32 i = 0; i < numEdges; ++ i )
      {
         xfm->mulP( verts[ i + 0 ].point );
         xfm->mulP( verts[ i + 1 ].point );
      }
   }
   verts.unlock();

   // Render the line list.

   mDevice->setStateBlockByDesc( desc );

   mDevice->setVertexBuffer( verts );
   mDevice->setupGenericShaders();

   mDevice->drawPrimitive( GFXLineList, 0, numEdges );
}
bool SceneCullingState::addCullingVolumeToZone( U32 zoneId, SceneCullingVolume::Type type, const AnyPolyhedron& polyhedron )
{
   // Allocate space on our chunker.

   const U32 numPlanes = polyhedron.getNumPlanes();
   PlaneF* planes = allocateData< PlaneF >( numPlanes );

   // Copy the planes over.

   dMemcpy( planes, polyhedron.getPlanes(), numPlanes * sizeof( planes[ 0 ] ) );
   
   // Create a culling volume.

   SceneCullingVolume volume(
      type,
      PlaneSetF( planes, numPlanes )
   );

   // And add it.

   return addCullingVolumeToZone( zoneId, volume );
}
Beispiel #4
0
void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const AnyPolyhedron &poly, const ColorI &color, const MatrixF *xfm )
{
   GFXDEBUGEVENT_SCOPE( GFXDrawUtil_DrawSolidPolyhedron, ColorI::GREEN );

   const U32 numPoints = poly.getNumPoints();
   const Point3F* points = poly.getPoints();
   const PlaneF* planes = poly.getPlanes();
   const Point3F viewDir = GFX->getViewMatrix().getForwardVector();

   // Create a temp buffer for the vertices and
   // put all the polyhedron's points in there.

   GFXVertexBufferHandle< GFXVertexPC > verts( mDevice, numPoints, GFXBufferTypeVolatile );
   
   verts.lock();
   for( U32 i = 0; i < numPoints; ++ i )
   {
      verts[ i ].point = points[ i ];
      verts[ i ].color = color;
   }

   if( xfm )
   {
      for( U32 i = 0; i < numPoints; ++ i )
         xfm->mulP( verts[ i ].point );
   }
   verts.unlock();

   // Allocate a temp buffer for the face indices.

   const U32 numIndices = poly.getNumEdges() * 2;
   const U32 numPlanes = poly.getNumPlanes();

   GFXPrimitiveBufferHandle prims( mDevice, numIndices, 0, GFXBufferTypeVolatile );

   // Unfortunately, since polygons may have varying numbers of
   // vertices, we also need to retain that information.

   FrameTemp< U32 > numIndicesForPoly( numPlanes );
   U32 numPolys = 0;

   // Create all the polygon indices.

   U16* indices;
   prims.lock( &indices );
   U32 idx = 0;
   for( U32 i = 0; i < numPlanes; ++ i )
   {
      // Since face extraction is somewhat costly, don't bother doing it for
      // backfacing polygons if culling is enabled.

      if( !desc.cullDefined || desc.cullMode != GFXCullNone )
      {
         F32 dot = mDot( planes[ i ], viewDir );

         // See if it faces *the same way* as the view direction.  This would
         // normally mean that the face is *not* backfacing but since we expect
         // planes on the polyhedron to be facing *inwards*, we need to reverse
         // the logic here.

         if( dot > 0.f )
            continue;
      }

      U32 numPoints = poly.extractFace( i, &indices[ idx ], numIndices - idx );
      numIndicesForPoly[ numPolys ] = numPoints;
      idx += numPoints;

      numPolys ++;
   }
   prims.unlock();

   // Set up state.

   mDevice->setStateBlockByDesc( desc );
   mDevice->setupGenericShaders();

   mDevice->setVertexBuffer( verts );
   mDevice->setPrimitiveBuffer( prims );

   // Render one triangle fan for each polygon.

   U32 startIndex = 0;
   for( U32 i = 0; i < numPolys; ++ i )
   {
      U32 numVerts = numIndicesForPoly[ i ];
      mDevice->drawIndexedPrimitive( GFXTriangleFan, 0, 0, numPoints, startIndex, numVerts - 2 );
      startIndex += numVerts;
   }
}
Beispiel #5
0
void DebugDrawer::drawPolyhedronDebugInfo( const AnyPolyhedron& polyhedron, const MatrixF& transform, const Point3F& scale )
{
   Point3F center = polyhedron.getCenterPoint();
   center.convolve( scale );
   transform.mulP( center );

   // Render plane indices and normals.

   const U32 numPlanes = polyhedron.getNumPlanes();
   for( U32 i = 0; i < numPlanes; ++ i )
   {
      const AnyPolyhedron::PlaneType& plane = polyhedron.getPlanes()[ i ];

      Point3F planePos = plane.getPosition();
      planePos.convolve( scale );
      transform.mulP( planePos );

      Point3F normal = plane.getNormal();
      transform.mulV( normal );

      drawText( planePos, String::ToString( i ), ColorI::BLACK );
      drawLine( planePos, planePos + normal, ColorI::GREEN );
   }

   // Render edge indices and direction indicators.

   const U32 numEdges = polyhedron.getNumEdges();
   for( U32 i = 0; i < numEdges; ++ i )
   {
      const AnyPolyhedron::EdgeType& edge = polyhedron.getEdges()[ i ];

      Point3F v1 = polyhedron.getPoints()[ edge.vertex[ 0 ] ];
      Point3F v2 = polyhedron.getPoints()[ edge.vertex[ 1 ] ];

      v1.convolve( scale );
      v2.convolve( scale );
      transform.mulP( v1 );
      transform.mulP( v2 );

      const Point3F midPoint = v1 + ( v2 - v1 ) / 2.f;

      drawText( midPoint, String::ToString( "%i (%i, %i)", i, edge.face[ 0 ], edge.face[ 1 ] ), ColorI::WHITE );

      // Push out the midpoint away from the center to place the direction indicator.

      Point3F pushDir = midPoint - center;
      pushDir.normalize();
      const Point3F dirPoint = midPoint + pushDir;
      const Point3F lineDir = ( v2 - v1 ) / 2.f;

      drawLine( dirPoint, dirPoint + lineDir, ColorI::RED );
   }

   // Render point indices and coordinates.

   const U32 numPoints = polyhedron.getNumPoints();
   for( U32 i = 0; i < numPoints; ++ i )
   {
      Point3F p = polyhedron.getPoints()[ i ];

      p.convolve( scale );
      transform.mulP( p );

      drawText( p, String::ToString( "%i: (%.2f, %.2f, %.2f)", i, p.x, p.y, p.z ), ColorF::WHITE );
   }
}