Browse Source

- Changed Buoyancy controller to be area based. It currently still only uses objects you tell it to but that's easy to change. Need to change the BuoyancyControllerToy art to show a region.
- Modified the debug-draw to not use the b2Color. Still need to expose the selected debug-drawing colors to the scripts and try to use stock-colors for the defaults to make it easier.
- Modified how TypeVector2 works.
- Added more string-based utility to Vector2.

MelvMay-GG 12 years ago
parent
commit
bfcbc32

+ 75 - 43
engine/source/2d/controllers/BuoyancyController.cc

@@ -34,14 +34,13 @@ IMPLEMENT_CONOBJECT(BuoyancyController);
 //------------------------------------------------------------------------------
 
 BuoyancyController::BuoyancyController() :
-    mSurfaceNormal( 0.0f, 1.0f ),
-    mSurfaceOffset( 0.0f ),
     mFlowVelocity( 0.0f, 0.0f ),
     mFluidDensity( 2.0f ),
     mLinearDrag( 0.0f ),
     mAngularDrag( 0.0f ),
     mFluidGravity( 0.0f, -9.8f ),
-    mUseShapeDensity( true )
+    mUseShapeDensity( true ),
+    mSurfaceNormal( 0.0f, 1.0f )
 {
 }
 
@@ -59,8 +58,7 @@ void BuoyancyController::initPersistFields()
     // Call parent.
     Parent::initPersistFields();
 
-    addField( "SurfaceNormal", TypeVector2, Offset(mSurfaceNormal, BuoyancyController), "The outer surface normal." );
-    addField( "SurfaceOffset", TypeF32, Offset(mSurfaceOffset, BuoyancyController), "The height of the fluid surface along the normal." );
+    addField( "FluidArea", Typeb2AABB, Offset(mFluidArea, BuoyancyController), "The fluid area." );
     addField( "FluidDensity", TypeF32, Offset(mFluidDensity, BuoyancyController), "The fluid density." );
     addField( "FlowVelocity", TypeVector2, Offset(mFlowVelocity, BuoyancyController), "The fluid flow velocity for drag calculations." );
     addField( "LinearDrag", TypeF32, Offset(mLinearDrag, BuoyancyController), "The linear drag co-efficient for the fluid." );
@@ -111,27 +109,30 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
         // Fetch the scene object.
         SceneObject* pSceneObject = *itr;
 
-        // Ignore sleeping bodies.
+        // Skip if asleep.
         if ( !pSceneObject->getAwake() )
             continue;
 
         // Fetch the shape count.
         const U32 shapeCount = pSceneObject->getCollisionShapeCount();
 
+        // Skip if no collision shapes.
+        if ( shapeCount == 0 )
+            continue;
+
+        // Fetch the body transform.
+        const b2Transform& bodyTransform = pSceneObject->getBody()->GetTransform();;
+
 		Vector2 areaCenter(0.0f, 0.0f);
 		Vector2 massCenter(0.0f, 0.0f);
 		F32 area = 0.0f;
 		F32 mass = 0.0f;
 
-        // Skip if we have no collision shapes.
-        if ( shapeCount == 0 )
-            continue;
-
         // Yes, so iterate them.
         for( U32 i = 0; i < shapeCount; ++i )
         {
             // Fetch the fixture definition.
-            b2FixtureDef fixtureDef = pSceneObject->getCollisionShapeDefinition( i );
+            const b2FixtureDef fixtureDef = pSceneObject->getCollisionShapeDefinition( i );
 
             // Fetch the shape.
             const b2Shape* pShape = fixtureDef.shape;
@@ -140,19 +141,16 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
             
 			F32 shapeArea = 0.0f;
 
+            // Calculate the area for the shape type.
             if ( pShape->GetType() == b2Shape::e_circle )
             {
-                shapeArea = ComputeCircleSubmergedArea( pSceneObject->getBody(), dynamic_cast<const b2CircleShape*>(pShape), shapeCenter );
+                shapeArea = ComputeCircleSubmergedArea( bodyTransform, dynamic_cast<const b2CircleShape*>(pShape), shapeCenter );
             }
             else if ( pShape->GetType() == b2Shape::e_polygon)
             {
-                shapeArea = ComputePolygonSubmergedArea( pSceneObject->getBody(), dynamic_cast<const b2PolygonShape*>(pShape), shapeCenter );
+                shapeArea = ComputePolygonSubmergedArea( bodyTransform, dynamic_cast<const b2PolygonShape*>(pShape), shapeCenter );
             }
-            else if ( pShape->GetType() == b2Shape::e_edge)
-            {
-                shapeArea = 0.0f;
-            }
-            else if ( pShape->GetType() == b2Shape::e_chain)
+            else if ( pShape->GetType() == b2Shape::e_edge || pShape->GetType() == b2Shape::e_chain )
             {
                 shapeArea = 0.0f;
             }
@@ -162,32 +160,34 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
                 continue;
             }
 
+            // Calculate area.
 			area += shapeArea;
 			areaCenter.x += shapeArea * shapeCenter.x;
 			areaCenter.y += shapeArea * shapeCenter.y;
+
+            // Calculate mass.
 			const F32 shapeDensity = mUseShapeDensity ? fixtureDef.density : 1.0f;
 			mass += shapeArea*shapeDensity;
 			massCenter.x += shapeArea * shapeCenter.x * shapeDensity;
 			massCenter.y += shapeArea * shapeCenter.y * shapeDensity;
         }
 
+        // Skip not in water.
+		if( area < b2_epsilon )
+			continue;
+
+        // Calculate area/mass centers.
 		areaCenter.x /= area;
 		areaCenter.y /= area;
-        //const b2Vec2 localCentroid = b2MulT(pSceneObject->getTransform(), areaCenter);
 		massCenter.x /= mass;
 		massCenter.y /= mass;
 
-        // Skip not in water.
-		if( area < b2_epsilon )
-			continue;
-
 		// Buoyancy
-		Vector2 buoyancyForce = -mFluidDensity * area * mFluidGravity;
+		const Vector2 buoyancyForce = -mFluidDensity * area * mFluidGravity;
         pSceneObject->applyForce(buoyancyForce, massCenter);
 
 		// Linear drag
-        Vector2 dragForce = pSceneObject->getLinearVelocityFromWorldPoint(areaCenter) - mFlowVelocity;
-		dragForce *= -mLinearDrag*area;
+        const Vector2 dragForce = (pSceneObject->getLinearVelocityFromWorldPoint(areaCenter) - mFlowVelocity) * (-mLinearDrag * area);
 		pSceneObject->applyForce(dragForce, areaCenter );
 
 		// Angular drag
@@ -197,27 +197,39 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
 
 //------------------------------------------------------------------------------
 
-F32 BuoyancyController::ComputeCircleSubmergedArea( const b2Body* pBody, const b2CircleShape* pShape, Vector2& center )
+F32 BuoyancyController::ComputeCircleSubmergedArea( const b2Transform& bodyTransform, const b2CircleShape* pShape, Vector2& center )
 {
     // Sanity!
-    AssertFatal( pBody != NULL, "BuoyancyController::ComputeCircleSubmergedArea() - Invalid body." );
     AssertFatal( pShape != NULL, "BuoyancyController::ComputeCircleSubmergedArea() - Invalid shape." );
 
+    // Calculate the shape AABB.
+    b2AABB shapeAABB;
+    pShape->ComputeAABB( &shapeAABB, bodyTransform, 0 );
+
+    // If no overlap then the object cannot be submerged at all so return zero area submerged.
+    if ( !b2TestOverlap( mFluidArea, shapeAABB ) )
+        return 0.0f;
+
+    // Calculate the world shape center.
+    const b2Vec2 worldShapeCenter = b2Mul( bodyTransform, pShape->m_p );
+
+    const F32 l = -(b2Dot( mSurfaceNormal, worldShapeCenter ) - mFluidArea.upperBound.y);
+
     // Fetch the circle radius.
     const F32 radius = pShape->m_radius;
 
-    const b2Vec2 p = b2Mul( pBody->GetTransform(), pShape->m_p );
-    const F32 l = -(b2Dot( mSurfaceNormal, p ) - mSurfaceOffset);
-		
+    // Submerged?
     if (l < - radius + FLT_MIN)
 	{
-		// Completely dry
+        // No, so return zero area submerged.
 		return 0.0f;
 	}
+
+	// Completely wet?
 	if (l > pShape->m_radius)
 	{
-		// Completely wet
-		center = p;
+        // Yes!
+		center = worldShapeCenter;
 		return  b2_pi * radius * radius;
 	}
 		
@@ -227,23 +239,31 @@ F32 BuoyancyController::ComputeCircleSubmergedArea( const b2Body* pBody, const b
     const F32 area = r2 *( mAsin(l / radius) + b2_pi / 2.0f) + l * mSqrt( r2 - l2 );
     const F32 com = -2.0f / 3.0f * mPow(r2 - l2, 1.5f) / area;
 	
-	center.x = p.x + mSurfaceNormal.x * com;
-	center.y = p.y + mSurfaceNormal.y * com;
+    // Calculate center.
+	center.x = worldShapeCenter.x + mSurfaceNormal.x * com;
+	center.y = worldShapeCenter.y + mSurfaceNormal.y * com;
 		
 	return area;
 }
 
 //------------------------------------------------------------------------------
 
-F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Body* pBody, const b2PolygonShape* pShape, Vector2& center )
+F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Transform& bodyTransform, const b2PolygonShape* pShape, Vector2& center )
 {
     // Sanity!
-    AssertFatal( pBody != NULL, "BuoyancyController::ComputePolygonSubmergedArea() - Invalid body." );
     AssertFatal( pShape != NULL, "BuoyancyController::ComputePolygonSubmergedArea() - Invalid shape." );
 
-    //Transform plane into shape co-ordinates
-    b2Vec2 normalL = b2MulT( pBody->GetTransform().q, mSurfaceNormal);
-    F32 offsetL = mSurfaceOffset - b2Dot(mSurfaceNormal, pBody->GetTransform().p);
+    // Calculate the shape AABB.
+    b2AABB shapeAABB;
+    pShape->ComputeAABB( &shapeAABB, bodyTransform, 0 );
+
+    // If no overlap then the object cannot be submerged at all so return zero area submerged.
+    if ( !b2TestOverlap( mFluidArea, shapeAABB ) )
+        return 0.0f;
+
+    // Transform plane into shape co-ordinates
+    b2Vec2 normalL = b2MulT( bodyTransform.q, mSurfaceNormal);
+    F32 offsetL = mFluidArea.upperBound.y - b2Dot(mSurfaceNormal, bodyTransform.p);
         
     F32 depths[b2_maxPolygonVertices];
     S32 diveCount = 0;
@@ -289,7 +309,7 @@ F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Body* pBody, const
                 // Completely submerged
                 b2MassData md;
                 pShape->ComputeMass(&md, 1.0f);
-                center = b2Mul(pBody->GetTransform(), md.center);
+                center = b2Mul(bodyTransform, md.center);
                 return md.mass;
             }
             else
@@ -355,7 +375,19 @@ F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Body* pBody, const
         
     // Normalize and transform centroid
     center *= 1.0f / area;        
-    center = b2Mul(pBody->GetTransform(), center);
+    center = b2Mul(bodyTransform, center);
         
     return area;
 }
+
+
+//------------------------------------------------------------------------------
+
+void BuoyancyController::renderOverlay( Scene* pScene, const SceneRenderState* pSceneRenderState, BatchRender* pBatchRenderer )
+{
+    // Call parent.
+    Parent::renderOverlay( pScene, pSceneRenderState, pBatchRenderer );
+
+    // Draw fluid area.
+    pScene->mDebugDraw.DrawAABB( mFluidArea, ColorF(0.7f, 0.7f, 0.9f) );
+}

+ 10 - 7
engine/source/2d/controllers/BuoyancyController.h

@@ -38,11 +38,8 @@ class BuoyancyController : public SceneController
 private:
     typedef SceneController Parent;
 
-	/// The outer fluid surface normal.
-	Vector2 mSurfaceNormal;
-
-	/// The height of the fluid surface along the normal.
-	F32 mSurfaceOffset;
+    /// The fluid area.
+    b2AABB mFluidArea;
 
 	/// The fluid density.
 	F32 mFluidDensity;
@@ -62,9 +59,12 @@ private:
 	/// Whether to use the collision shape densities or assume a uniform density.
 	bool mUseShapeDensity;
 
+	/// The outer fluid surface normal.
+	Vector2 mSurfaceNormal;
+
 protected:
-    F32 ComputeCircleSubmergedArea( const b2Body* pBody, const b2CircleShape* pShape, Vector2& center );
-    F32 ComputePolygonSubmergedArea( const b2Body* pBody, const b2PolygonShape* pShape, Vector2& center );
+    F32 ComputeCircleSubmergedArea( const b2Transform& bodyTransform, const b2CircleShape* pShape, Vector2& center );
+    F32 ComputePolygonSubmergedArea( const b2Transform& bodyTransform, const b2PolygonShape* pShape, Vector2& center );
 
 public:
     BuoyancyController();
@@ -76,6 +76,9 @@ public:
     /// Integration.
     virtual void integrate( Scene* pScene, const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
 
+    // Scene render.
+    virtual void renderOverlay( Scene* pScene, const SceneRenderState* pSceneRenderState, BatchRender* pBatchRenderer );
+
     /// Declare Console Object.
     DECLARE_CONOBJECT( BuoyancyController );
 };

+ 2 - 2
engine/source/2d/controllers/PointForceController.cc

@@ -136,6 +136,6 @@ void PointForceController::renderOverlay( Scene* pScene, const SceneRenderState*
     // Call parent.
     Parent::renderOverlay( pScene, pSceneRenderState, pBatchRenderer );
 
-    // Draw camera pause distance.
-    pScene->mDebugDraw.DrawCircle( mPosition, mRadius, b2Color(1.0f, 1.0f, 0.0f ) );
+    // Draw force radius.
+    pScene->mDebugDraw.DrawCircle( mPosition, mRadius, ColorF(1.0f, 1.0f, 0.0f ) );
 }

+ 43 - 0
engine/source/2d/core/Utility.cc

@@ -30,6 +30,49 @@
 
 //-----------------------------------------------------------------------------
 
+ConsoleType( b2AABB, Typeb2AABB, sizeof(b2AABB), "" )
+
+ConsoleGetType( Typeb2AABB )
+{
+    // Fetch AABB.
+    const b2AABB* pAABB = (b2AABB*)dptr;
+
+    // Format AABB.
+    char* pBuffer = Con::getReturnBuffer(64);
+    dSprintf(pBuffer, 64, "%.5g %.5g", pAABB->lowerBound.x, pAABB->lowerBound.y, pAABB->upperBound.x, pAABB->upperBound.y );
+    return pBuffer;
+}
+
+ConsoleSetType( Typeb2AABB )
+{
+    // Fetch AABB.
+    b2AABB* pAABB = (b2AABB*)dptr;
+
+    // "lowerX lowerY upperX upperY".
+    if( argc == 1 )
+    {
+        if ( dSscanf(argv[0], "%g %g %g %g", &(pAABB->lowerBound.x), &(pAABB->lowerBound.y), &(pAABB->upperBound.x), &(pAABB->upperBound.y) ) == 4 )
+            return;
+    }
+    
+    // "lowerX,lowerY,upperX,upperY".
+    else if( argc == 4 )
+    {
+        pAABB->lowerBound.Set( dAtof(argv[0]), dAtof(argv[1] ) );
+        pAABB->upperBound.Set( dAtof(argv[2]), dAtof(argv[3] ) );
+        return;
+    }
+
+    // Reset the AABB.
+    pAABB->lowerBound.SetZero();
+    pAABB->upperBound.SetZero();
+
+    // Warn.
+    Con::printf("Typeb2AABB must be set as { lowerX, lowerY, upperX, upperY } or \"lowerX lowerY upperX upperY\"");
+}
+
+//-----------------------------------------------------------------------------
+
 namespace Utility
 {
 

+ 4 - 0
engine/source/2d/core/Utility.h

@@ -58,6 +58,10 @@ struct Vector2;
 typedef Vector<SceneObject*> typeSceneObjectVector;
 typedef const Vector<SceneObject*>& typeSceneObjectVectorConstRef;
 
+///-----------------------------------------------------------------------------
+
+DefineConsoleType( Typeb2AABB )
+
 //-----------------------------------------------------------------------------
 
 namespace Utility

+ 3 - 5
engine/source/2d/core/Vector2.cc

@@ -38,20 +38,18 @@ ConsoleSetType( TypeVector2 )
 {
     // Fetch vector.
     Vector2* pVector = (Vector2*)dptr;
+
     // "x y".
     if( argc == 1 )
     {
-        if ( dSscanf(argv[0], "%g %g", &(pVector->x), &(pVector->y)) == 2 )
-            return;
-
-        pVector->y = pVector->x;
+        pVector->setString( argv[0] );
         return;
     }
 
     // "x,y".
     if( argc == 2 )
     {
-        *((Vector2*)dptr) = Vector2(dAtof(argv[0]), dAtof(argv[1]));
+        pVector->Set(dAtof(argv[0]), dAtof(argv[1]));
         return;
     }
 

+ 20 - 19
engine/source/2d/core/Vector2.h

@@ -59,25 +59,7 @@ struct Vector2 : b2Vec2
     inline Vector2( const Point2I& point ) : b2Vec2( F32(point.x), F32(point.y) ) {}
     inline Vector2( const Point2F& point ) : b2Vec2( point.x, point.y ) {}
     inline Vector2( const Point2D& point ) : b2Vec2( F32(point.x), F32(point.y) ) {}
-    inline Vector2( const char* pString )
-    {
-        const U32 elementCount = Utility::mGetStringElementCount(pString);
-
-        if ( elementCount == 0 )
-        {
-            SetZero();
-            return;
-        }
-
-        if ( elementCount == 1 )
-        {
-            x = y = dAtof(Utility::mGetStringElement(pString,0));
-            return;
-        }
-
-        x = dAtof(Utility::mGetStringElement(pString,0));
-        y = dAtof(Utility::mGetStringElement(pString,1));
-    }
+    inline Vector2( const char* pString ) { setString( pString ); }
 
     /// Operators.
     inline Vector2& operator /= (const F32 s)                           { x /= s; y /= s; return *this; }
@@ -106,6 +88,25 @@ struct Vector2 : b2Vec2
     /// Utility.
     inline void setAngle(const F32 radians)                             { x = mSin(radians); y = mCos(radians); }
     inline void setPolar(const F32 radians,F32 length)                  { x = mSin(radians)*length; y = mCos(radians)*length; }
+    inline void setString(const char* pString )
+    {
+        const U32 elementCount = Utility::mGetStringElementCount(pString);
+
+        if ( elementCount == 0 )
+        {
+            SetZero();
+            return;
+        }
+
+        if ( elementCount == 1 )
+        {
+            x = y = dAtof(Utility::mGetStringElement(pString,0));
+            return;
+        }
+
+        x = dAtof(Utility::mGetStringElement(pString,0));
+        y = dAtof(Utility::mGetStringElement(pString,1));
+    }
     inline const Vector2& setZero()                                     { (*this) = getZero(); return *this; }
     inline const Vector2& setOne()                                      { (*this) = getOne(); return *this; }
     inline static const Vector2& getZero()                              { static const Vector2 v(0.0f, 0.0f); return v; }

+ 31 - 31
engine/source/2d/scene/DebugDraw.cc

@@ -28,7 +28,7 @@
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawAABB( const b2AABB& aabb )
+void DebugDraw::DrawAABB( const b2AABB& aabb, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawAABB);
@@ -40,28 +40,28 @@ void DebugDraw::DrawAABB( const b2AABB& aabb )
     aabbVertex[2].Set(aabb.upperBound.x, aabb.upperBound.y);
     aabbVertex[3].Set(aabb.lowerBound.x, aabb.upperBound.y);
 
-    DrawPolygon( aabbVertex, 4, b2Color(0.7f, 0.7f, 0.9f) );
+    DrawPolygon( aabbVertex, 4, color );
 }
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawOOBB( const b2Vec2* pOOBB )
+void DebugDraw::DrawOOBB( const b2Vec2* pOOBB, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawOOBB);
 
-    DrawPolygon( pOOBB, 4, b2Color(0.9f, 0.9f, 1.0f) );
+    DrawPolygon( pOOBB, 4, color );
 }
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawAsleep( const b2Vec2* pOOBB )
+void DebugDraw::DrawAsleep( const b2Vec2* pOOBB, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawAsleep);
 
-    DrawSegment( pOOBB[0], pOOBB[2], b2Color( 0.0f, 1.0f, 0.0f ) );
-    DrawSegment( pOOBB[1], pOOBB[3], b2Color( 0.0f, 1.0f, 0.0f ) );
+    DrawSegment( pOOBB[0], pOOBB[2], color );
+    DrawSegment( pOOBB[1], pOOBB[3], color );
 }
 
 //-----------------------------------------------------------------------------
@@ -77,27 +77,27 @@ void DebugDraw::DrawCollisionShapes( const b2Transform& xf, b2Body* pBody )
         // Inactive fixture.
         if ( pBody->IsActive() == false )
         {
-            DrawShape(pFixture, xf, b2Color(0.5f, 0.5f, 0.5f));
+            DrawShape(pFixture, xf, ColorF(0.5f, 0.5f, 0.5f));
         }
         // Active static fixture.
         else if ( pBody->GetType() == b2_staticBody )
         {
-            DrawShape(pFixture, xf, b2Color(0.5f, 0.9f, 0.5f));
+            DrawShape(pFixture, xf, ColorF(0.5f, 0.9f, 0.5f));
         }
         // Active kinematic fixture.
         else if ( pBody->GetType() == b2_kinematicBody )
         {
-            DrawShape(pFixture, xf, b2Color(0.5f, 0.5f, 0.9f));
+            DrawShape(pFixture, xf, ColorF(0.5f, 0.5f, 0.9f));
         }
         // Active, asleep dynamic fixture.
         else if ( pBody->IsAwake() == false )
         {
-            DrawShape(pFixture, xf, b2Color(0.6f, 0.6f, 0.2f));
+            DrawShape(pFixture, xf, ColorF(0.6f, 0.6f, 0.2f));
         }
         // Active, awake dynamic fixture.
         else
         {
-            DrawShape(pFixture, xf, b2Color(0.9f, 0.9f, 0.2f));
+            DrawShape(pFixture, xf, ColorF(0.9f, 0.9f, 0.2f));
         }
     }
 }
@@ -124,13 +124,13 @@ void DebugDraw::DrawSortPoint( const b2Vec2& worldPosition, const b2Vec2& size,
     worldSortPoint[2].Set( worldPoint.x - markerSize, worldPoint.y + markerSize );
     worldSortPoint[3].Set( worldPoint.x + markerSize, worldPoint.y - markerSize );
 
-    DrawSegment( worldSortPoint[0], worldSortPoint[1], b2Color( 0.0f, 1.0f, 0.8f ) );
-    DrawSegment( worldSortPoint[2], worldSortPoint[3], b2Color( 0.0f, 1.0f, 0.8f ) );
+    DrawSegment( worldSortPoint[0], worldSortPoint[1], ColorF( 0.0f, 1.0f, 0.8f ) );
+    DrawSegment( worldSortPoint[2], worldSortPoint[3], ColorF( 0.0f, 1.0f, 0.8f ) );
 }
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawShape( b2Fixture* fixture, const b2Transform& xf, const b2Color& color )
+void DebugDraw::DrawShape( b2Fixture* fixture, const b2Transform& xf, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawShape);
@@ -216,7 +216,7 @@ void DebugDraw::DrawJoints( b2World* pWorld )
         b2Vec2 p1 = pJoint->GetAnchorA();
         b2Vec2 p2 = pJoint->GetAnchorB();
 
-        b2Color color( 0.5f, 0.8f, 0.8f );
+        ColorF color( 0.5f, 0.8f, 0.8f );
 
         switch ( pJoint->GetType() )
         {
@@ -259,12 +259,12 @@ void DebugDraw::DrawJoints( b2World* pWorld )
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
+void DebugDraw::DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawPolygon);
 
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < vertexCount; ++i)
     {
@@ -275,14 +275,14 @@ void DebugDraw::DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const b2
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
+void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawSolidPolygon);
 
     glEnable(GL_BLEND);
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.15f);
+    glColor4f(0.5f * color.red, 0.5f * color.green, 0.5f * color.blue, 0.15f);
     glBegin(GL_TRIANGLE_FAN);
     for (int32 i = 0; i < vertexCount; ++i)
     {
@@ -291,7 +291,7 @@ void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, con
     glEnd();
     glDisable(GL_BLEND);
 
-    glColor4f(color.r, color.g, color.b, 1.0f);
+    glColor4f(color.red, color.green, color.blue, 1.0f);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < vertexCount; ++i)
     {
@@ -302,7 +302,7 @@ void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, con
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const b2Color& color)
+void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawCircle);
@@ -310,7 +310,7 @@ void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const b2Color&
     const float32 k_segments = 16.0f;
     const float32 k_increment = 2.0f * b2_pi / k_segments;
     float32 theta = 0.0f;
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < k_segments; ++i)
     {
@@ -323,7 +323,7 @@ void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const b2Color&
     
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
+void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawSolidCircle);
@@ -333,7 +333,7 @@ void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2V
     float32 theta = 0.0f;
     glEnable(GL_BLEND);
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.15f);
+    glColor4f(0.5f * color.red, 0.5f * color.green, 0.5f * color.blue, 0.15f);
     glBegin(GL_TRIANGLE_FAN);
     for (int32 i = 0; i < k_segments; ++i)
     {
@@ -345,7 +345,7 @@ void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2V
     glDisable(GL_BLEND);
 
     theta = 0.0f;
-    glColor4f(color.r, color.g, color.b, 1.0f);
+    glColor4f(color.red, color.green, color.blue, 1.0f);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < k_segments; ++i)
     {
@@ -364,9 +364,9 @@ void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2V
     
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
+void DebugDraw::DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const ColorF& color )
 {
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glBegin(GL_LINES);
     glVertex2f(p1.x, p1.y);
     glVertex2f(p2.x, p2.y);
@@ -375,7 +375,7 @@ void DebugDraw::DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const b2Color&
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawTransform(const b2Transform& xf)
+void DebugDraw::DrawTransform( const b2Transform& xf )
 {
     b2Vec2 p1 = xf.p, p2;
     const float32 k_axisScale = 0.4f;
@@ -396,11 +396,11 @@ void DebugDraw::DrawTransform(const b2Transform& xf)
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
+void DebugDraw::DrawPoint( const b2Vec2& p, float32 size, const ColorF& color )
 {
     glPointSize(size);
     glBegin(GL_POINTS);
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glVertex2f(p.x, p.y);
     glEnd();
     glPointSize(1.0f);

+ 14 - 10
engine/source/2d/scene/DebugDraw.h

@@ -31,6 +31,10 @@
 #include "math/mMath.h"
 #endif
 
+#ifndef _COLOR_H_
+#include "graphics/color.h"
+#endif
+
 //-----------------------------------------------------------------------------
 
 class DebugDraw
@@ -39,22 +43,22 @@ public:
     DebugDraw() {}
     virtual ~DebugDraw() {}
 
-    void DrawAABB( const b2AABB& aabb );
-    void DrawOOBB( const b2Vec2* pOOBB );
-    void DrawAsleep( const b2Vec2* pOOBB );
+    void DrawAABB( const b2AABB& aabb, const ColorF& color );
+    void DrawOOBB( const b2Vec2* pOOBB, const ColorF& color );
+    void DrawAsleep( const b2Vec2* pOOBB, const ColorF& color );
     void DrawCollisionShapes( const b2Transform& xf, b2Body* pBody );
     void DrawSortPoint( const b2Vec2& worldPosition, const b2Vec2& size, const b2Vec2& localSortPoint );
 
     void DrawJoints( b2World* pWorld );
 
-    void DrawShape( b2Fixture* fixture, const b2Transform& xf, const b2Color& color );
-    void DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
-    void DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
-    void DrawCircle( const b2Vec2& center, float32 radius, const b2Color& color);
-    void DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
-    void DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
+    void DrawShape( b2Fixture* fixture, const b2Transform& xf, const ColorF& color );
+    void DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color);
+    void DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color);
+    void DrawCircle( const b2Vec2& center, float32 radius, const ColorF& color);
+    void DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const ColorF& color);
+    void DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const ColorF& color);
     void DrawTransform(const b2Transform& xf);
-    void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color);
+    void DrawPoint(const b2Vec2& p, float32 size, const ColorF& color);
 };
 
 #endif // _DEBUG_DRAW_H_

+ 1 - 1
engine/source/2d/sceneobject/ParticlePlayer.cc

@@ -705,7 +705,7 @@ void ParticlePlayer::sceneRenderOverlay( const SceneRenderState* sceneRenderStat
         return;
 
     // Draw camera pause distance.
-    pScene->mDebugDraw.DrawCircle( getRenderPosition(), mCameraIdleDistance, b2Color(1.0f, 1.0f, 0.0f ) );
+    pScene->mDebugDraw.DrawCircle( getRenderPosition(), mCameraIdleDistance, ColorF(1.0f, 1.0f, 0.0f ) );
 }
 
 //-----------------------------------------------------------------------------

+ 5 - 5
engine/source/2d/sceneobject/SceneObject.cc

@@ -806,19 +806,19 @@ void SceneObject::sceneRenderOverlay( const SceneRenderState* sceneRenderState )
     // AABB debug draw.
     if ( debugMask & Scene::SCENE_DEBUG_AABB )
     {
-        pScene->mDebugDraw.DrawAABB( mCurrentAABB );
+        pScene->mDebugDraw.DrawAABB( mCurrentAABB, ColorF(0.7f, 0.7f, 0.9f) );
     }
 
     // OOBB debug draw.
     if ( debugMask & Scene::SCENE_DEBUG_OOBB )
     {
-        pScene->mDebugDraw.DrawOOBB( mRenderOOBB );
+        pScene->mDebugDraw.DrawOOBB( mRenderOOBB, ColorF(0.9f, 0.9f, 1.0f) );
     }
 
     // Asleep debug draw.
     if ( !getAwake() && debugMask & Scene::SCENE_DEBUG_SLEEP )
     {
-        pScene->mDebugDraw.DrawAsleep( mRenderOOBB );
+        pScene->mDebugDraw.DrawAsleep( mRenderOOBB, ColorF( 0.0f, 1.0f, 0.0f ) );
     }
 
     // Collision Shapes.
@@ -832,8 +832,8 @@ void SceneObject::sceneRenderOverlay( const SceneRenderState* sceneRenderState )
     {
         const b2Vec2 renderPosition = getRenderPosition();
 
-        pScene->mDebugDraw.DrawPoint( renderPosition + getLocalCenter(), 6, b2Color( 0.0f, 1.0f, 0.4f ) );
-        pScene->mDebugDraw.DrawPoint( renderPosition, 4, b2Color( 0.0f, 0.4f, 1.0f ) );
+        pScene->mDebugDraw.DrawPoint( renderPosition + getLocalCenter(), 6, ColorF( 0.0f, 1.0f, 0.4f ) );
+        pScene->mDebugDraw.DrawPoint( renderPosition, 4, ColorF( 0.0f, 0.4f, 1.0f ) );
     }
 
     // Sort Points.

+ 2 - 0
modules/BuoyancyControllerToy/1/main.cs

@@ -33,6 +33,7 @@ function BuoyancyControllerToy::create( %this )
     SandboxScene.setGravity( 0, -29.8 );
     
     // Configure settings.
+    BuoyancyControllerToy.FluidArea = "-30 -30 30 0";
     BuoyancyControllerToy.SurfaceNormal = "0 1";
     BuoyancyControllerToy.SurfaceOffset = 0;
     BuoyancyControllerToy.FluidDensity = 2.5;
@@ -402,6 +403,7 @@ function BuoyancyControllerToy::updateBuoyancyController( %this )
     %controller = BuoyancyControllerToy.SceneController;
     
     // Update the controller.
+    %controller.FluidArea = BuoyancyControllerToy.FluidArea;
     %controller.SurfaceNormal = BuoyancyControllerToy.SurfaceNormal;
     %controller.SurfaceOffset = BuoyancyControllerToy.SurfaceOffset;
     %controller.FluidDensity = BuoyancyControllerToy.FluidDensity;