PPC is expensive, so I try to find an optimized solution to perform PPC. What is the best way I should go? Should I read the actual pixel data from pixel buffer and compare those or should I approximate the scaled values against the origin image data?
Actually I use this approximation attempt to check point based collisions,
but this works not realy good with scaled sprites:
bool brSprite::intersect(float x, float y)
{
// first check if bounding rect collides with point positions
bool collision = this->contains(x, y);
// perform pixel perfect collision if required
if(collision && m_usePPC)
{
/* Substract actual rectangle position from point position value to
reduce intersection point to image dimensions in range: [0,width]
and [0,height].
Please take note that we also have to regard the region x,y
position values to determine correct image position in atlas
textures and a scaling of the sprite.
*/
int pos_x = (int)((x - m_x)+m_region.getX()/m_scale.m_fX);
int pos_y = (int)((y - m_y)+m_region.getY()/m_scale.m_fY);
if(pos_x<m_width && pos_y<m_height){
// define alpha compareable
int alpha = 0;
if(m_ppcTolerance>0){
alpha = (255 * m_ppcTolerance)/100;
}
// perform pixel perfect collision check
brColor color = m_region.getImage()->getPixelColor(pos_x,pos_y);
if(color.getAlpha()>alpha){
collision = true;
}
else{
collision = false;
}
}
}
return collision;
}
Any Ideas?












