10
« on: April 22, 2009, 05:23:13 pm »
Hello,
I'm trying to implement a pixel based collision detection,
and what I planned to do was to iterate through the pixels of one
sprite (go from 0,0 to sprite.GetSize().x, sprite.GetSize().y respectively),
use TransformToGlobal to get a global co-ordinate, then use the
opposing sprite's TransformToLocal, to check whether that pixel position
in that opposing sprite's space.
unfortunately, after using TransformToLocal on the opposing sprite, I
get unusual results.
Example
Sprite 1 Position: 265.83, 599.309
Sprite 2 Position: 327.316, 596.533
(Using TransformToGlobal)
Sprite 1 Global Position of 0, 0: 233.83, 567.309
Sprite 2 Global Position of 0, 0: 295.316, 564.533
(Using TransformToLocal of sprite 1's global position of (0, 0) on sprite 2)
-1229.72, 55.5112 -> Unusual
Here's some code to help explain what I'm doing:
sf::Vector2f pos1, pos2;
sf::Color colour;
int i;
for(i=0;i<sprite1.GetSize().x;i++) {
for(j=0;j<sprite1.GetSize().y;j++) {
pos1 = sprite1.TransformToGlobal(sf::Vector2f(i, j));
pos2 = sprite2.TransformToLocal(pos1);
if (<pos2's value is not invalid. eg. >= (0,0) or < sprite2.GetSize()>) {
colour = sprite2.GetPixel(pos2);
if (colour.a > 0) { return true; }
}
}
}
return false;
etc.
now in the cases I have been testing, the rotation and scale and even
center points on each object are the same, and I'm rather stumped as
to why wierd values are coming out. (especially such large negative values, I had values going up to -6000+)
I really hope someone can help.
Regards,
Mashandar
P.S. I apologise for the large posting, I just wanted to make sure there's
plenty of information about my problem.