Game Development Community

CompositeSprite AABB

by Jonathan Arsenault · in Torque 2D Beginner · 08/05/2013 (10:21 pm) · 5 replies

I was using CompositeSprite as container for collision shapes (the object is made out of a bunch of layered CompositeSprite all attached to this one composite holding all the collision shapes, but containing no sprite) and it made me notice that the Composite bounds are determined by it's sprite contain alone with no regard for the contained collision shape, this does not work well with picking, not sure if i will change my code design or the CompositeSprite bounding code yet... Any input? Simply going through all composite and combining the AABB of each then setting the size of the collision composite will probably do for now...

About the author

Made a small foray in the gaming industry working at Citeremis, worked and offered consultation in many other sector since, passing through casino management, the wood transformation industry and the transportation sector. Eat code for breakfast.


#1
08/06/2013 (4:48 am)
Out of curiosity, why do you house the collision shapes in a separate object from your sprites?

The picking methods have a parameter to specify the pickMode - any, aabb, oobb, or collision. Would that help at all?
#2
08/06/2013 (10:52 am)
You are right, Jon, The CompositeSprite's bounds will reflect the Sprite Sizes within it, not its collision shapes.

My guess is that it would require a rewrite of the CompositeSprite's bounding algorithms.
#3
08/06/2013 (2:02 pm)
@Mike I am attaching them to a common composite per-object so I can do a *normalization* pass on the collision shapes and pack them into bigger shape as needed to reduce the total number of collision shape required. When i want to do modification on them or select a specific sprite i do a 2 phase picking first picking an area or point on the scene on AABB only then given the wanted layer I can do a pick or sprite selection only on the wanted and relevant composite from the object (i have encapsulated all this in a SimComposite object that hold layering information and all the CompositeSprite).

@Simon Right, it would, I tried to simply hack the underlying SceneObject size manually and override the CompositeSprite bounds calculation when a manual bound is specified (just a combine of all the SimComposite AABB), the debug overlay show the correct bounds but the picking then return wrong value (even worst than base behavior returning object that are half way across the world) haven't traced it properly yet, but the SpriteBatch bounds are probably still used for the picking somehow.
#4
08/07/2013 (2:17 am)
I looked through the Box2D manual a bit to brush up on all this. If I understood it correctly, this is a bug then?

Currently the AABB reflects the body size, but really we want the AABB to be the fixture size, yes? I had noticed working with other scene objects that collision shapes could be larger than the AABB but didn't think much of it at the time.
#5
08/07/2013 (6:12 pm)
Well it's multifaceted, the CompositeSprite does not support collision picking, this is more or less or a problem, but it also mean that at an higher level when doing a SceneQuery that they will not behave as expected as the collision information is not considered at all. One is rarely going to go do a sprite pick on a composite directly, they will first do a pick on the scene itself to get the composite in question this more or less work as is, i am good at discovering corner case no one taught or bothered about before.

From my point of view the AABB should really be a combine of body/sprite and physical fixture in the object (ie contain/bound everything in it). When it comes down to SceneObject the OOBB from which the AABB is derived is calculated from it's size property alone and nothing else.