|
@@ -86,6 +86,14 @@ void PointForceController::copyTo(SimObject* object)
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
+void PointForceController::setTrackedObject( SceneObject* pSceneObject )
|
|
|
|
+{
|
|
|
|
+ // Set tracked object.
|
|
|
|
+ mTrackedObject = pSceneObject;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//------------------------------------------------------------------------------
|
|
|
|
+
|
|
void PointForceController::integrate( Scene* pScene, const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats )
|
|
void PointForceController::integrate( Scene* pScene, const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats )
|
|
{
|
|
{
|
|
// Finish if the attractor would have no effect.
|
|
// Finish if the attractor would have no effect.
|
|
@@ -95,10 +103,13 @@ void PointForceController::integrate( Scene* pScene, const F32 totalTime, const
|
|
// Prepare query filter.
|
|
// Prepare query filter.
|
|
WorldQuery* pWorldQuery = prepareQueryFilter( pScene );
|
|
WorldQuery* pWorldQuery = prepareQueryFilter( pScene );
|
|
|
|
|
|
|
|
+ // Fetch the current position.
|
|
|
|
+ const Vector2 currentPosition = getCurrentPosition();
|
|
|
|
+
|
|
// Calculate the AABB of the attractor.
|
|
// Calculate the AABB of the attractor.
|
|
b2AABB aabb;
|
|
b2AABB aabb;
|
|
- aabb.lowerBound.Set( mPosition.x - mRadius, mPosition.y - mRadius );
|
|
|
|
- aabb.upperBound.Set( mPosition.x + mRadius, mPosition.y + mRadius );
|
|
|
|
|
|
+ aabb.lowerBound.Set( currentPosition.x - mRadius, currentPosition.y - mRadius );
|
|
|
|
+ aabb.upperBound.Set( currentPosition.x + mRadius, currentPosition.y + mRadius );
|
|
|
|
|
|
// Query for candidate objects.
|
|
// Query for candidate objects.
|
|
pWorldQuery->anyQueryArea( aabb );
|
|
pWorldQuery->anyQueryArea( aabb );
|
|
@@ -123,18 +134,25 @@ void PointForceController::integrate( Scene* pScene, const F32 totalTime, const
|
|
const F32 linearDrag = mClampF( mLinearDrag, 0.0f, 1.0f ) * elapsedTime;
|
|
const F32 linearDrag = mClampF( mLinearDrag, 0.0f, 1.0f ) * elapsedTime;
|
|
const F32 angularDrag = mClampF( mAngularDrag, 0.0f, 1.0f ) * elapsedTime;
|
|
const F32 angularDrag = mClampF( mAngularDrag, 0.0f, 1.0f ) * elapsedTime;
|
|
|
|
|
|
|
|
+ // Fetch the tracked object.
|
|
|
|
+ const SceneObject* pTrackedObject = mTrackedObject;
|
|
|
|
+
|
|
// Iterate the results.
|
|
// Iterate the results.
|
|
for ( U32 n = 0; n < resultCount; n++ )
|
|
for ( U32 n = 0; n < resultCount; n++ )
|
|
{
|
|
{
|
|
// Fetch the scene object.
|
|
// Fetch the scene object.
|
|
SceneObject* pSceneObject = queryResults[n].mpSceneObject;
|
|
SceneObject* pSceneObject = queryResults[n].mpSceneObject;
|
|
|
|
|
|
|
|
+ // Ignore if it's the tracked object.
|
|
|
|
+ if ( pSceneObject == pTrackedObject )
|
|
|
|
+ continue;
|
|
|
|
+
|
|
// Ignore if it's a static body.
|
|
// Ignore if it's a static body.
|
|
if ( pSceneObject->getBodyType() == b2_staticBody )
|
|
if ( pSceneObject->getBodyType() == b2_staticBody )
|
|
continue;
|
|
continue;
|
|
|
|
|
|
- // Calculate the force distance to the controllers position.
|
|
|
|
- Vector2 distanceForce = mPosition - pSceneObject->getPosition();
|
|
|
|
|
|
+ // Calculate the force distance to the controllers current position.
|
|
|
|
+ Vector2 distanceForce = currentPosition - pSceneObject->getPosition();
|
|
|
|
|
|
// Skip if the position is outside the radius.
|
|
// Skip if the position is outside the radius.
|
|
if ( distanceForce.LengthSquared() > radiusSqr )
|
|
if ( distanceForce.LengthSquared() > radiusSqr )
|
|
@@ -191,5 +209,5 @@ void PointForceController::renderOverlay( Scene* pScene, const SceneRenderState*
|
|
Parent::renderOverlay( pScene, pSceneRenderState, pBatchRenderer );
|
|
Parent::renderOverlay( pScene, pSceneRenderState, pBatchRenderer );
|
|
|
|
|
|
// Draw force radius.
|
|
// Draw force radius.
|
|
- pScene->mDebugDraw.DrawCircle( mPosition, mRadius, ColorF(1.0f, 1.0f, 0.0f ) );
|
|
|
|
|
|
+ pScene->mDebugDraw.DrawCircle( getCurrentPosition(), mRadius, ColorF(1.0f, 1.0f, 0.0f ) );
|
|
}
|
|
}
|