Browse Source

- CompositeSprite picking now correctly using local-space and not world-space.
- Fixed bug in SpriteBatch when removing a sprite but not removing it from the internal hash-table.

MelvMay-GG 12 years ago
parent
commit
fe0ddd5

+ 13 - 4
engine/source/2d/core/SpriteBatch.cc

@@ -1276,16 +1276,25 @@ bool SpriteBatch::destroySprite( const U32 batchId )
     // Debug Profiling.
     PROFILE_SCOPE(SpriteBatch_DestroySprite);
 
-    // Find sprite.    
-    SpriteBatchItem* pSpriteBatchItem = findSpriteId( batchId );
+    // Find sprite.
+    typeSpriteBatchHash::iterator spriteItr = mSprites.find( batchId );
 
-    // Finish if not found.
-    if ( pSpriteBatchItem == NULL )
+    // Finish if sprite not found.
+    if ( spriteItr == mSprites.end() )
         return false;
 
+    // Find sprite.    
+    SpriteBatchItem* pSpriteBatchItem = spriteItr->value;
+
+    // Sanity!
+    AssertFatal( pSpriteBatchItem != NULL, "SpriteBatch::destroySprite() - Found sprite but it was NULL." );
+
     // Cache sprite.
     SpriteBatchItemFactory.cacheObject( pSpriteBatchItem );
 
+    // Remove from sprites.
+    mSprites.erase( batchId );
+
     return true;
 }
 

+ 23 - 0
engine/source/2d/sceneobject/CompositeSprite_ScriptBinding.h

@@ -901,6 +901,12 @@ ConsoleMethod(CompositeSprite, pickPoint, const char*, 3, 4,    "(x / y ) Picks
         return NULL;
     }
 
+    // Fetch the render transform.
+    const b2Transform& renderTransform = object->getRenderTransform();
+
+    // Transform into local space.
+    point = b2MulT( renderTransform, point );
+
     // Perform query.
     pSpriteBatchQuery->renderQueryPoint( point );
 
@@ -1008,6 +1014,13 @@ ConsoleMethod(CompositeSprite, pickArea, const char*, 4, 6, "(startx/y, endx/y )
         return NULL;
     }
 
+    // Fetch the render transform.
+    const b2Transform& renderTransform = object->getRenderTransform();
+    
+    // Translate into local space.
+    v1 -= renderTransform.p;
+    v2 -= renderTransform.p;
+
     // Calculate normalized AABB.
     b2AABB aabb;
     aabb.lowerBound.x = getMin( v1.x, v2.x );
@@ -1015,6 +1028,9 @@ ConsoleMethod(CompositeSprite, pickArea, const char*, 4, 6, "(startx/y, endx/y )
     aabb.upperBound.x = getMax( v1.x, v2.x );
     aabb.upperBound.y = getMax( v1.y, v2.y );
 
+    // Rotate the AABB into local space.
+    CoreMath::mRotateAABB( aabb, -renderTransform.q.GetAngle(), aabb );
+
     // Perform query.
     pSpriteBatchQuery->renderQueryArea( aabb );
 
@@ -1122,6 +1138,13 @@ ConsoleMethod(CompositeSprite, pickRay, const char*, 4, 6,  "(startx/y, endx/y)
         return NULL;
     }
 
+    // Fetch the render transform.
+    const b2Transform& renderTransform = object->getRenderTransform();
+
+    // Transform into local space.
+    v1 = b2MulT( renderTransform, v1 );
+    v2 = b2MulT( renderTransform, v2 );
+
     // Perform query.
     pSpriteBatchQuery->renderQueryRay( v1, v2 );