- floatified FBoundingBox.

This commit is contained in:
Christoph Oelckers 2016-03-31 10:38:54 +02:00
parent 8fd76f0c8a
commit 6b065b8074
7 changed files with 60 additions and 79 deletions

View file

@ -34,32 +34,17 @@
// //
//========================================================================== //==========================================================================
void FBoundingBox::setBox(fixed_t x, fixed_t y, fixed_t radius) void FBoundingBox::AddToBox (const DVector2 &pos)
{ {
m_Box[BOXTOP] = (fixed_t)MIN<SQWORD>((SQWORD)y + radius, FIXED_MAX); if (pos.X < m_Box[BOXLEFT])
m_Box[BOXLEFT] = (fixed_t)MAX<SQWORD>((SQWORD)x - radius, FIXED_MIN); m_Box[BOXLEFT] = pos.X;
m_Box[BOXRIGHT] = (fixed_t)MIN<SQWORD>((SQWORD)x + radius, FIXED_MAX); if (pos.X > m_Box[BOXRIGHT])
m_Box[BOXBOTTOM] = (fixed_t)MAX<SQWORD>((SQWORD)y - radius, FIXED_MIN); m_Box[BOXRIGHT] = pos.X;
}
if (pos.Y < m_Box[BOXBOTTOM])
//========================================================================== m_Box[BOXBOTTOM] = pos.Y;
// if (pos.Y > m_Box[BOXTOP])
// m_Box[BOXTOP] = pos.Y;
//
//==========================================================================
void FBoundingBox::AddToBox (fixed_t x, fixed_t y)
{
if (x < m_Box[BOXLEFT])
m_Box[BOXLEFT] = x;
if (x > m_Box[BOXRIGHT])
m_Box[BOXRIGHT] = x;
if (y < m_Box[BOXBOTTOM])
m_Box[BOXBOTTOM] = y;
if (y > m_Box[BOXTOP])
m_Box[BOXTOP] = y;
} }
//========================================================================== //==========================================================================
@ -78,8 +63,8 @@ int FBoundingBox::BoxOnLineSide (const line_t *ld) const
if (ld->Delta().X == 0) if (ld->Delta().X == 0)
{ // ST_VERTICAL { // ST_VERTICAL
p1 = m_Box[BOXRIGHT] < ld->v1->fixX(); p1 = m_Box[BOXRIGHT] < ld->v1->fX();
p2 = m_Box[BOXLEFT] < ld->v1->fixX(); p2 = m_Box[BOXLEFT] < ld->v1->fX();
if (ld->Delta().Y < 0) if (ld->Delta().Y < 0)
{ {
p1 ^= 1; p1 ^= 1;
@ -88,8 +73,8 @@ int FBoundingBox::BoxOnLineSide (const line_t *ld) const
} }
else if (ld->Delta().Y == 0) else if (ld->Delta().Y == 0)
{ // ST_HORIZONTAL: { // ST_HORIZONTAL:
p1 = m_Box[BOXTOP] > ld->v1->fixY(); p1 = m_Box[BOXTOP] > ld->v1->fY();
p2 = m_Box[BOXBOTTOM] > ld->v1->fixY(); p2 = m_Box[BOXBOTTOM] > ld->v1->fY();
if (ld->Delta().X < 0) if (ld->Delta().X < 0)
{ {
p1 ^= 1; p1 ^= 1;

View file

@ -22,7 +22,8 @@
#ifndef __M_BBOX_H__ #ifndef __M_BBOX_H__
#define __M_BBOX_H__ #define __M_BBOX_H__
#include "doomtype.h" #include <float.h>
#include "vectors.h"
#include "m_fixed.h" #include "m_fixed.h"
struct line_t; struct line_t;
@ -36,7 +37,11 @@ public:
ClearBox(); ClearBox();
} }
FBoundingBox(fixed_t left, fixed_t bottom, fixed_t right, fixed_t top) FBoundingBox(fixed_t left, fixed_t bottom, fixed_t right, fixed_t top) = delete;
FBoundingBox(fixed_t x, fixed_t y, fixed_t radius) = delete;
void Set(int index, fixed_t value) = delete;
FBoundingBox(double left, double bottom, double right, double top)
{ {
m_Box[BOXTOP] = top; m_Box[BOXTOP] = top;
m_Box[BOXLEFT] = left; m_Box[BOXLEFT] = left;
@ -44,35 +49,24 @@ public:
m_Box[BOXBOTTOM] = bottom; m_Box[BOXBOTTOM] = bottom;
} }
FBoundingBox(double left, double bottom, double right, double top)
{
m_Box[BOXTOP] = FLOAT2FIXED(top);
m_Box[BOXLEFT] = FLOAT2FIXED(left);
m_Box[BOXRIGHT] = FLOAT2FIXED(right);
m_Box[BOXBOTTOM] = FLOAT2FIXED(bottom);
}
FBoundingBox(fixed_t x, fixed_t y, fixed_t radius)
{
setBox(x, y, radius);
}
FBoundingBox(double x, double y, double radius) FBoundingBox(double x, double y, double radius)
{ {
setBox(x, y, radius); setBox(x, y, radius);
} }
void setBox(fixed_t x, fixed_t y, fixed_t radius);
void setBox(double x, double y, double radius) void setBox(double x, double y, double radius)
{ {
setBox(FLOAT2FIXED(x), FLOAT2FIXED(y), FLOAT2FIXED(radius)); m_Box[BOXTOP] = y + radius;
m_Box[BOXLEFT] = x - radius;
m_Box[BOXRIGHT] = x + radius;
m_Box[BOXBOTTOM] = y - radius;
} }
void ClearBox () void ClearBox ()
{ {
m_Box[BOXTOP] = m_Box[BOXRIGHT] = FIXED_MIN; m_Box[BOXTOP] = m_Box[BOXRIGHT] = -FLT_MAX;
m_Box[BOXBOTTOM] = m_Box[BOXLEFT] = FIXED_MAX; m_Box[BOXBOTTOM] = m_Box[BOXLEFT] = FLT_MAX;
} }
// Returns a bounding box that encloses both bounding boxes // Returns a bounding box that encloses both bounding boxes
@ -84,21 +78,21 @@ public:
m_Box[BOXTOP] > box2.m_Box[BOXTOP] ? m_Box[BOXTOP] : box2.m_Box[BOXTOP]); m_Box[BOXTOP] > box2.m_Box[BOXTOP] ? m_Box[BOXTOP] : box2.m_Box[BOXTOP]);
} }
void AddToBox (fixed_t x, fixed_t y); void AddToBox(const DVector2 &pos);
inline fixed_t Top () const { return m_Box[BOXTOP]; } inline double Top () const { return m_Box[BOXTOP]; }
inline fixed_t Bottom () const { return m_Box[BOXBOTTOM]; } inline double Bottom () const { return m_Box[BOXBOTTOM]; }
inline fixed_t Left () const { return m_Box[BOXLEFT]; } inline double Left () const { return m_Box[BOXLEFT]; }
inline fixed_t Right () const { return m_Box[BOXRIGHT]; } inline double Right () const { return m_Box[BOXRIGHT]; }
bool inRange(const line_t *ld) const; bool inRange(const line_t *ld) const;
int BoxOnLineSide (const line_t *ld) const; int BoxOnLineSide (const line_t *ld) const;
void Set(int index, fixed_t value) {m_Box[index] = value;} void Set(int index, double value) {m_Box[index] = value;}
protected: protected:
fixed_t m_Box[4]; double m_Box[4];
}; };

View file

@ -638,10 +638,10 @@ FBlockLinesIterator::FBlockLinesIterator(int _minx, int _miny, int _maxx, int _m
void FBlockLinesIterator::init(const FBoundingBox &box) void FBlockLinesIterator::init(const FBoundingBox &box)
{ {
validcount++; validcount++;
maxy = GetBlockY(FIXED2DBL(box.Top())); maxy = GetBlockY(box.Top());
miny = GetBlockY(FIXED2DBL(box.Bottom())); miny = GetBlockY(box.Bottom());
maxx = GetBlockX(FIXED2DBL(box.Right())); maxx = GetBlockX(box.Right());
minx = GetBlockX(FIXED2DBL(box.Left())); minx = GetBlockX(box.Left());
Reset(); Reset();
} }
@ -898,7 +898,7 @@ void FMultiBlockLinesIterator::startIteratorForGroup(int group)
offset.x += checkpoint.x; offset.x += checkpoint.x;
offset.y += checkpoint.y; offset.y += checkpoint.y;
cursector = group == startsector->PortalGroup ? startsector : P_PointInSector(offset.x, offset.y); cursector = group == startsector->PortalGroup ? startsector : P_PointInSector(offset.x, offset.y);
bbox.setBox(offset.x, offset.y, checkpoint.z); bbox.setBox(FIXED2FLOAT(offset.x), FIXED2FLOAT(offset.y), FIXED2FLOAT(checkpoint.z));
blockIterator.init(bbox); blockIterator.init(bbox);
} }
@ -944,10 +944,10 @@ FBlockThingsIterator::FBlockThingsIterator(int _minx, int _miny, int _maxx, int
void FBlockThingsIterator::init(const FBoundingBox &box) void FBlockThingsIterator::init(const FBoundingBox &box)
{ {
maxy = GetBlockY(FIXED2DBL(box.Top())); maxy = GetBlockY(box.Top());
miny = GetBlockY(FIXED2DBL(box.Bottom())); miny = GetBlockY(box.Bottom());
maxx = GetBlockX(FIXED2DBL(box.Right())); maxx = GetBlockX(box.Right());
minx = GetBlockX(FIXED2DBL(box.Left())); minx = GetBlockX(box.Left());
ClearHash(); ClearHash();
Reset(); Reset();
} }
@ -1173,7 +1173,7 @@ void FMultiBlockThingsIterator::startIteratorForGroup(int group)
fixedvec2 offset = Displacements._f_getOffset(basegroup, group); fixedvec2 offset = Displacements._f_getOffset(basegroup, group);
offset.x += checkpoint.x; offset.x += checkpoint.x;
offset.y += checkpoint.y; offset.y += checkpoint.y;
bbox.setBox(offset.x, offset.y, checkpoint.z); bbox.setBox(FIXED2FLOAT(offset.x), FIXED2FLOAT(offset.y), FIXED2FLOAT(checkpoint.z));
blockIterator.init(bbox); blockIterator.init(bbox);
} }

View file

@ -3208,14 +3208,14 @@ static void P_GroupLines (bool buildmap)
for (j = 0; j < sector->linecount; ++j) for (j = 0; j < sector->linecount; ++j)
{ {
li = sector->lines[j]; li = sector->lines[j];
bbox.AddToBox (li->v1->fixX(), li->v1->fixY()); bbox.AddToBox (li->v1->fPos());
bbox.AddToBox (li->v2->fixX(), li->v2->fixY()); bbox.AddToBox (li->v2->fPos());
} }
} }
// set the center to the middle of the bounding box // set the center to the middle of the bounding box
sector->centerspot.X = FIXED2DBL(bbox.Right()/2 + bbox.Left()/2); sector->centerspot.X = (bbox.Right() + bbox.Left()/2);
sector->centerspot.Y = FIXED2DBL(bbox.Top()/2 + bbox.Bottom()/2); sector->centerspot.Y = (bbox.Top() + bbox.Bottom()/2);
// For triangular sectors the above does not calculate good points unless the longest of the triangle's lines is perfectly horizontal and vertical // For triangular sectors the above does not calculate good points unless the longest of the triangle's lines is perfectly horizontal and vertical
if (sector->linecount == 3) if (sector->linecount == 3)

View file

@ -1216,14 +1216,14 @@ void FPolyObj::LinkPolyobj ()
vertex_t *vt; vertex_t *vt;
vt = Sidedefs[i]->linedef->v1; vt = Sidedefs[i]->linedef->v1;
Bounds.AddToBox(vt->fixX(), vt->fixY()); Bounds.AddToBox(vt->fPos());
vt = Sidedefs[i]->linedef->v2; vt = Sidedefs[i]->linedef->v2;
Bounds.AddToBox(vt->fixX(), vt->fixY()); Bounds.AddToBox(vt->fPos());
} }
bbox[BOXRIGHT] = GetBlockX(FIXED2DBL(Bounds.Right())); bbox[BOXRIGHT] = GetBlockX(Bounds.Right());
bbox[BOXLEFT] = GetBlockX(FIXED2DBL(Bounds.Left())); bbox[BOXLEFT] = GetBlockX(Bounds.Left());
bbox[BOXTOP] = GetBlockY(FIXED2DBL(Bounds.Top())); bbox[BOXTOP] = GetBlockY(Bounds.Top());
bbox[BOXBOTTOM] = GetBlockY(FIXED2DBL(Bounds.Bottom())); bbox[BOXBOTTOM] = GetBlockY(Bounds.Bottom());
// add the polyobj to each blockmap section // add the polyobj to each blockmap section
for(int j = bbox[BOXBOTTOM]*bmapwidth; j <= bbox[BOXTOP]*bmapwidth; for(int j = bbox[BOXBOTTOM]*bmapwidth; j <= bbox[BOXTOP]*bmapwidth;
j += bmapwidth) j += bmapwidth)

View file

@ -1172,10 +1172,12 @@ bool P_CollectConnectedGroups(int startgroup, const fixedvec3 &position, fixed_t
FDisplacement &disp = Displacements(thisgroup, othergroup); FDisplacement &disp = Displacements(thisgroup, othergroup);
if (!disp.isSet) continue; // no connection. if (!disp.isSet) continue; // no connection.
/*
FBoundingBox box(position.x + disp.pos.x, position.y + disp.pos.y, checkradius); FBoundingBox box(position.x + disp.pos.x, position.y + disp.pos.y, checkradius);
if (!box.inRange(ld) || box.BoxOnLineSide(linkedPortals[i]->mOrigin) != -1) continue; // not touched if (!box.inRange(ld) || box.BoxOnLineSide(linkedPortals[i]->mOrigin) != -1) continue; // not touched
foundPortals.Push(linkedPortals[i]); foundPortals.Push(linkedPortals[i]);
*/
} }
bool foundone = true; bool foundone = true;
while (foundone) while (foundone)
@ -1230,7 +1232,7 @@ bool P_CollectConnectedGroups(int startgroup, const fixedvec3 &position, fixed_t
for (unsigned i = 0; i < groupsToCheck.Size();i++) for (unsigned i = 0; i < groupsToCheck.Size();i++)
{ {
fixedvec2 disp = Displacements._f_getOffset(startgroup, thisgroup & ~FPortalGroupArray::FLAT); fixedvec2 disp = Displacements._f_getOffset(startgroup, thisgroup & ~FPortalGroupArray::FLAT);
FBoundingBox box(position.x + disp.x, position.y + disp.y, checkradius); FBoundingBox box(0., 0., 0.);// position.x + disp.x, position.y + disp.y, checkradius);
FBlockLinesIterator it(box); FBlockLinesIterator it(box);
line_t *ld; line_t *ld;
while ((ld = it.Next())) while ((ld = it.Next()))

View file

@ -1646,10 +1646,10 @@ inline void AActor::ClearInterpolation()
inline bool FBoundingBox::inRange(const line_t *ld) const inline bool FBoundingBox::inRange(const line_t *ld) const
{ {
return FIXED2DBL(Left()) < ld->bbox[BOXRIGHT] && return Left() < ld->bbox[BOXRIGHT] &&
FIXED2DBL(Right()) > ld->bbox[BOXLEFT] && Right() > ld->bbox[BOXLEFT] &&
FIXED2DBL(Top()) > ld->bbox[BOXBOTTOM] && Top() > ld->bbox[BOXBOTTOM] &&
FIXED2DBL(Bottom()) < ld->bbox[BOXTOP]; Bottom() < ld->bbox[BOXTOP];
} }