views:

295

answers:

2

When detecting collision between sprites using color alpha component, should I carry out in world space or in view (local) space, which one is more preferred? Any link or suggested book to this kind of topic is highly appreciated.

Thank :)

A: 

How would the coordinate space you use affect your actual result? I think you should just select whatever is faster.

Noufal Ibrahim
I think that to detect sprite collision in world space, we have to transform sprites from local matrix to world matrix to get it fit in world space, and for detecting in local space we have to transform world matrix of one sprite into the other sprite's local matrix, it somehow may affect, personally, I think detect in local space is better but not so sure. Any help?
I'm not totally sure of your nomenclature but I personally have just used simple bounding rectangles to do this (or rather, the library I used did) and it worked fine. The action was fast enough to not notice the occasional error. There are some details http://www.gamedev.net/reference/articles/article735.asp that might help you.
Noufal Ibrahim
thank for your response, actually, I have read this article before and in this article, I think they must assume that two sprites are already in the same space (either local or world) and the point here is I dont know which space they used. I intend to write a function for detecting collision, it's ok to choose either local or world space, but I want to know which space most of the time we select.
A: 

There are a couple of things to consider here.

If your sprites are very small relative to the size of your world, or if you are doing tricks with fixed point math, you could get inaccurate results by doing the operations in world space. Local space is likely to have much smaller values, granting you more accuracy.

On the other hand, it is likely that both object's world space matrices are either known, or are calculated every frame anyway so that they can be rendered. The major exception is if those objects are culled, in which case I would question your desire to simulate complex physics on those objects. If the world space matrices are available, there is no reason to do an extra matrix multiply to switch one into the local space of the other. Additionally, if multiple collisions happen simultaneously, you will have to transform into local space twice, as opposed to simply doing the calculations in world space.

That being said, It Probably doesn't matter. Sprite collision isn't rocket science. A typical user will NEVER be able to tell the difference in the floating point calculations as long as your values are reasonable, and on modern processors, a handful of multiplies every frame won't make a difference. I am assuming you aren't trying to do a sprite based MMORPG with ragdolls, so really, choose whichever one you like more.

Andres