Check convex quads
This commit is contained in:
parent
19d3c1cbe5
commit
4cb558b85c
4 changed files with 31 additions and 5 deletions
28
renderer.h
28
renderer.h
|
@ -252,6 +252,31 @@ void LCR_rendererDrawText(const char *text, int x, int y, uint16_t color,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Guesses (not 100% accurately) if a quad is convex or not.
|
||||
*/
|
||||
int _LCR_rendererQuadLooksConvex(S3L_Unit quad[8])
|
||||
{
|
||||
S3L_Unit cx = (quad[0] + quad[2] + quad[4] + quad[6]) / 4;
|
||||
S3L_Unit cy = (quad[1] + quad[3] + quad[5] + quad[7]) / 4;
|
||||
|
||||
S3L_Unit r = 0;
|
||||
|
||||
for (int i = 0; i < 8; i += 2)
|
||||
{
|
||||
r += S3L_abs(cx - quad[i]);
|
||||
r += S3L_abs(cy - quad[i + 1]);
|
||||
}
|
||||
|
||||
r = (3 * r) / 32;
|
||||
|
||||
for (int i = 0; i < 8; i += 2)
|
||||
if (S3L_abs(cx - quad[i]) <= r && S3L_abs(cy - quad[i + 1]) <= r)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t _LCR_pixelColor = 0; /**< Holds pixel color for _LCR_pixelFunc3D. This
|
||||
is needed is texture subsampling is on. */
|
||||
|
||||
|
@ -631,7 +656,8 @@ uint8_t _LCR_rendererCheckMapTriCover(const S3L_Index *t1,
|
|||
points2D[13] = (4 * points2D[7] + 3 * points2D[9] + points2D[11]) / 8;
|
||||
|
||||
// first: does the triangle alone cover the other one?
|
||||
if (_LCR_rendererQuadCoversTri(points2D + 6,points2D))
|
||||
if (_LCR_rendererQuadLooksConvex(points2D +6) &&
|
||||
_LCR_rendererQuadCoversTri(points2D + 6,points2D))
|
||||
result |= 1 << j;
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue