- add dynamic lights to softpoly and software renderer models

This commit is contained in:
Magnus Norddahl 2018-06-05 22:43:11 +02:00
commit 5464d2a577
13 changed files with 283 additions and 65 deletions

View file

@ -499,4 +499,49 @@ public:
extern DeletingModelArray Models;
// Check if circle potentially intersects with node AABB
inline bool CheckBBoxCircle(float *bbox, float x, float y, float radiusSquared)
{
float centerX = (bbox[BOXRIGHT] + bbox[BOXLEFT]) * 0.5f;
float centerY = (bbox[BOXBOTTOM] + bbox[BOXTOP]) * 0.5f;
float extentX = (bbox[BOXRIGHT] - bbox[BOXLEFT]) * 0.5f;
float extentY = (bbox[BOXBOTTOM] - bbox[BOXTOP]) * 0.5f;
float aabbRadiusSquared = extentX * extentX + extentY * extentY;
x -= centerX;
y -= centerY;
float dist = x * x + y * y;
return dist <= radiusSquared + aabbRadiusSquared;
}
// Helper function for BSPWalkCircle
template<typename Callback>
void BSPNodeWalkCircle(void *node, float x, float y, float radiusSquared, const Callback &callback)
{
while (!((size_t)node & 1))
{
node_t *bsp = (node_t *)node;
if (CheckBBoxCircle(bsp->bbox[0], x, y, radiusSquared))
BSPNodeWalkCircle(bsp->children[0], x, y, radiusSquared, callback);
if (!CheckBBoxCircle(bsp->bbox[1], x, y, radiusSquared))
return;
node = bsp->children[1];
}
subsector_t *sub = (subsector_t *)((uint8_t *)node - 1);
callback(sub);
}
// Search BSP for subsectors within the given radius and call callback(subsector) for each found
template<typename Callback>
void BSPWalkCircle(float x, float y, float radiusSquared, const Callback &callback)
{
if (level.nodes.Size() == 0)
callback(&level.subsectors[0]);
else
BSPNodeWalkCircle(level.HeadNode(), x, y, radiusSquared, callback);
}
#endif