@ -7,6 +7,9 @@
# include <components/debug/debuglog.hpp>
# include <components/debug/debuglog.hpp>
# include <components/misc/convert.hpp>
# include <components/misc/convert.hpp>
# include <osg/PolygonMode>
# include <osg/ShapeDrawable>
# include <osg/StateSet>
# include "bulletdebugdraw.hpp"
# include "bulletdebugdraw.hpp"
# include "vismask.hpp"
# include "vismask.hpp"
@ -41,6 +44,14 @@ void DebugDrawer::createGeometry()
mGeometry - > addPrimitiveSet ( mDrawArrays ) ;
mGeometry - > addPrimitiveSet ( mDrawArrays ) ;
mParentNode - > addChild ( mGeometry ) ;
mParentNode - > addChild ( mGeometry ) ;
auto * stateSet = new osg : : StateSet ;
stateSet - > setAttributeAndModes ( new osg : : PolygonMode ( osg : : PolygonMode : : FRONT_AND_BACK , osg : : PolygonMode : : LINE ) , osg : : StateAttribute : : ON ) ;
mShapesRoot = new osg : : Group ;
mShapesRoot - > setStateSet ( stateSet ) ;
mShapesRoot - > setDataVariance ( osg : : Object : : DYNAMIC ) ;
mShapesRoot - > setNodeMask ( Mask_Debug ) ;
mParentNode - > addChild ( mShapesRoot ) ;
}
}
}
}
@ -49,6 +60,7 @@ void DebugDrawer::destroyGeometry()
if ( mGeometry )
if ( mGeometry )
{
{
mParentNode - > removeChild ( mGeometry ) ;
mParentNode - > removeChild ( mGeometry ) ;
mParentNode - > removeChild ( mShapesRoot ) ;
mGeometry = nullptr ;
mGeometry = nullptr ;
mVertices = nullptr ;
mVertices = nullptr ;
mDrawArrays = nullptr ;
mDrawArrays = nullptr ;
@ -66,6 +78,7 @@ void DebugDrawer::step()
{
{
mVertices - > clear ( ) ;
mVertices - > clear ( ) ;
mColors - > clear ( ) ;
mColors - > clear ( ) ;
mShapesRoot - > removeChildren ( 0 , mShapesRoot - > getNumChildren ( ) ) ;
mWorld - > debugDrawWorld ( ) ;
mWorld - > debugDrawWorld ( ) ;
showCollisions ( ) ;
showCollisions ( ) ;
mDrawArrays - > setCount ( mVertices - > size ( ) ) ;
mDrawArrays - > setCount ( mVertices - > size ( ) ) ;
@ -106,12 +119,11 @@ void DebugDrawer::showCollisions()
mCollisionViews . end ( ) ) ;
mCollisionViews . end ( ) ) ;
}
}
void DebugDrawer : : draw ContactPoint( const btVector3 & PointOnB , const btVector3 & normalOnB , btScalar distance , int lifeTime , const btVector3 & color )
void DebugDrawer : : draw Sphere( btScalar radius , const btTransform & transform , const btVector3 & color )
{
{
mVertices - > push_back ( Misc : : Convert : : toOsg ( PointOnB ) ) ;
auto * geom = new osg : : ShapeDrawable ( new osg : : Sphere ( Misc : : Convert : : toOsg ( transform . getOrigin ( ) ) , radius ) ) ;
mVertices - > push_back ( Misc : : Convert : : toOsg ( PointOnB ) + ( Misc : : Convert : : toOsg ( normalOnB ) * distance * 20 ) ) ;
geom - > setColor ( osg : : Vec4 ( 1 , 1 , 1 , 1 ) ) ;
mColors - > push_back ( { 1 , 1 , 1 , 1 } ) ;
mShapesRoot - > addChild ( geom ) ;
mColors - > push_back ( { 1 , 1 , 1 , 1 } ) ;
}
}
void DebugDrawer : : reportErrorWarning ( const char * warningString )
void DebugDrawer : : reportErrorWarning ( const char * warningString )