void PolygonF_QuadForPlane(float *outpoints, float planenormalx, float planenormaly, float planenormalz, float planedist, float quadsize)
{
float d, quadright[3], quadup[3];
- if (planenormalz > planenormalx && planenormalz > planenormaly)
+ if (fabs(planenormalz) > fabs(planenormalx) && fabs(planenormalz) > fabs(planenormaly))
{
quadup[0] = 1;
quadup[1] = 0;
d = -(quadup[0] * planenormalx + quadup[1] * planenormaly + quadup[2] * planenormalz);
// VectorMA(quadup, d, planenormal, quadup);
quadup[0] += d * planenormalx;
- quadup[1] += d * planenormalx;
- quadup[2] += d * planenormalx;
+ quadup[1] += d * planenormaly;
+ quadup[2] += d * planenormalz;
// VectorNormalize(quadup);
d = 1.0 / sqrt(quadup[0] * quadup[0] + quadup[1] * quadup[1] + quadup[2] * quadup[2]);
quadup[0] *= d;
void PolygonD_QuadForPlane(double *outpoints, double planenormalx, double planenormaly, double planenormalz, double planedist, double quadsize)
{
double d, quadright[3], quadup[3];
- if (planenormalz > planenormalx && planenormalz > planenormaly)
+ if (fabs(planenormalz) > fabs(planenormalx) && fabs(planenormalz) > fabs(planenormaly))
{
quadup[0] = 1;
quadup[1] = 0;
d = -(quadup[0] * planenormalx + quadup[1] * planenormaly + quadup[2] * planenormalz);
// VectorMA(quadup, d, planenormal, quadup);
quadup[0] += d * planenormalx;
- quadup[1] += d * planenormalx;
- quadup[2] += d * planenormalx;
+ quadup[1] += d * planenormaly;
+ quadup[2] += d * planenormalz;
// VectorNormalize(quadup);
d = 1.0 / sqrt(quadup[0] * quadup[0] + quadup[1] * quadup[1] + quadup[2] * quadup[2]);
quadup[0] *= d;
float frac, pdist, ndist;
frontcount = 0;
backcount = 0;
- p = inpoints + (innumpoints - 1) * 3;
- n = inpoints;
- pdist = p[0] * planenormalx + p[1] * planenormaly + p[2] * planenormalz - planedist;
for (i = 0;i < innumpoints;i++)
{
+ p = inpoints + i * 3;
+ n = inpoints + ((i + 1) < innumpoints ? (i + 1) : 0) * 3;
+ pdist = p[0] * planenormalx + p[1] * planenormaly + p[2] * planenormalz - planedist;
ndist = n[0] * planenormalx + n[1] * planenormaly + n[2] * planenormalz - planedist;
if (pdist >= -epsilon)
{
}
backcount++;
}
- p = n;
- n += 3;
- pdist = ndist;
}
if (neededfrontpoints)
*neededfrontpoints = frontcount;
double frac, pdist, ndist;
frontcount = 0;
backcount = 0;
- p = inpoints + (innumpoints - 1) * 3;
- n = inpoints;
- pdist = p[0] * planenormalx + p[1] * planenormaly + p[2] * planenormalz - planedist;
for (i = 0;i < innumpoints;i++)
{
+ p = inpoints + i * 3;
+ n = inpoints + ((i + 1) < innumpoints ? (i + 1) : 0) * 3;
+ pdist = p[0] * planenormalx + p[1] * planenormaly + p[2] * planenormalz - planedist;
ndist = n[0] * planenormalx + n[1] * planenormaly + n[2] * planenormalz - planedist;
if (pdist >= -epsilon)
{
}
backcount++;
}
- p = n;
- n += 3;
- pdist = ndist;
}
if (neededfrontpoints)
*neededfrontpoints = frontcount;