Skip to content

Commit

Permalink
Fix droid bounding boxes at all resolutions.
Browse files Browse the repository at this point in the history
Not sure why this works, but fixes ticket:4157.
  • Loading branch information
Cyp committed May 15, 2016
1 parent 049db3a commit 07e3336
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/ivis_opengl/piematrix.cpp
Expand Up @@ -344,7 +344,7 @@ void pie_GetMatrix(float *matrix)
*/
int32_t pie_RotateProject(const Vector3i *v3d, Vector2i *v2d)
{
float hackScaleFactor = 3 * 330 / 1024.0; // HACK: This seems to work by experimentation, not sure why.
float hackScaleFactor = 1.0 / (3 * 330); // HACK: This seems to work by experimentation, not sure why.

/*
* v = curMatrix . v3d
Expand All @@ -355,20 +355,20 @@ int32_t pie_RotateProject(const Vector3i *v3d, Vector2i *v2d)
v3d->x * psMatrix->c + v3d->y * psMatrix->f + v3d->z * psMatrix->i + psMatrix->l
);

const int zz = v.z >> STRETCHED_Z_SHIFT;
const float zz = v.z * hackScaleFactor;

if (zz < MIN_STRETCHED_Z)
if (zz < MIN_STRETCHED_Z * hackScaleFactor)
{
v2d->x = LONG_WAY; //just along way off screen
v2d->y = LONG_WAY;
}
else
{
v2d->x = rendSurface.xcentre + (hackScaleFactor / zz * v.x);
v2d->y = rendSurface.ycentre - (hackScaleFactor / zz * v.y);
v2d->x = rendSurface.xcentre + v.x / zz;
v2d->y = rendSurface.ycentre - v.y / zz;
}

return zz;
return zz / (1 << STRETCHED_Z_SHIFT);
}

void pie_PerspectiveBegin(void)
Expand Down
9 changes: 3 additions & 6 deletions src/display3d.cpp
Expand Up @@ -3363,16 +3363,13 @@ void calcScreenCoords(DROID *psDroid)
origin = Vector3i(0, wsRadius, 0); // take the center of the object

/* get the screen coordinates */
// FP12_SHIFT-STRETCHED_Z_SHIFT is the shift of the scaling on the depth returned
const float cZ = pie_RotateProject(&origin, &center) / (float)(1 << (FP12_SHIFT - STRETCHED_Z_SHIFT));
float magic = float(1 << STRETCHED_Z_SHIFT) / 40; // The 40 comes from experimentation, it makes the boxes have approximately the right size.
const float cZ = pie_RotateProject(&origin, &center) * magic;

//Watermelon:added a crash protection hack...
if (cZ >= 0)
{
// 330 is the near plane depth from pie_PerspectiveBegin
// not sure where magic comes from, could be another 1<<FP12_SHIFT-STRETCHED_Z_SHIFT
const int magic = 4;
radius = (wsRadius * 330 * magic) / cZ;
radius = wsRadius / cZ * pie_GetResScalingFactor();
}
else
{
Expand Down

0 comments on commit 07e3336

Please sign in to comment.