Browse Source

- Fixed issue with WorldQuery when picking an area.

MelvMay-GG 12 years ago
parent
commit
be7d63b
2 changed files with 18 additions and 0 deletions
  1. 15 0
      engine/source/2d/scene/WorldQuery.cc
  2. 3 0
      engine/source/2d/scene/WorldQuery.h

+ 15 - 0
engine/source/2d/scene/WorldQuery.cc

@@ -40,6 +40,7 @@ WorldQuery::WorldQuery( Scene* pScene ) :
         mIsRaycastQueryResult(false),
         mMasterQueryKey(0),
         mCheckFixturePoint(false),
+        mCheckFixtureArea(false),
         mFixturePoint(0.0f, 0.0f)
 {
     // Set debug associations.
@@ -141,7 +142,16 @@ U32 WorldQuery::fixtureQueryArea( const b2AABB& aabb )
     mIsRaycastQueryResult = false;
 
     // Query.
+    mCheckFixtureArea = true;
+    b2Vec2 verts[4];
+    verts[0].Set( aabb.lowerBound.x, aabb.lowerBound.y );
+    verts[1].Set( aabb.upperBound.x, aabb.lowerBound.y );
+    verts[2].Set( aabb.upperBound.x, aabb.upperBound.y );
+    verts[3].Set( aabb.lowerBound.x, aabb.upperBound.y );
+    mFixtureAreaShape.Set( verts, 4);
+    mFixtureAreaTransform.SetIdentity();
     mpScene->getWorld()->QueryAABB( this, aabb );
+    mCheckFixtureArea = false;
 
     // Inject always-in-scope.
     injectAlwaysInScope();
@@ -429,6 +439,11 @@ bool WorldQuery::ReportFixture( b2Fixture* fixture )
     if ( mCheckFixturePoint && !fixture->TestPoint( mFixturePoint ) )
         return true;
 
+    // Check fixture area.
+    if ( mCheckFixtureArea )
+        if ( !b2TestOverlap( &mFixtureAreaShape, 0, fixture->GetShape(), 0, mFixtureAreaTransform, fixture->GetBody()->GetTransform() ) )
+        return true;
+
     // Tag with world query key.
     pSceneObject->setWorldQueryKey( mMasterQueryKey );
 

+ 3 - 0
engine/source/2d/scene/WorldQuery.h

@@ -96,7 +96,10 @@ private:
 private:
     Scene*                      mpScene;
     WorldQueryFilter            mQueryFilter;
+    b2PolygonShape              mFixtureAreaShape;
+    b2Transform                 mFixtureAreaTransform;
     bool                        mCheckFixturePoint;
+    bool                        mCheckFixtureArea;
     b2Vec2                      mFixturePoint;
     typeWorldQueryResultVector  mLayeredQueryResults[MAX_LAYERS_SUPPORTED];
     typeWorldQueryResultVector  mQueryResults;