1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/* bzflag
* Copyright (c) 1993-2025 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __COLLISION_GRID__
#define __COLLISION_GRID__
#include "common.h"
// system headers
#include <vector>
// common headers
#include "Extents.h"
class Ray;
class Obstacle;
class MeshObstacle;
class BoxBuilding;
class PyramidBuilding;
class BaseBuilding;
class Teleporter;
typedef struct
{
int count;
Obstacle** list;
} ObsList;
typedef union
{
ObsList array[6];
struct
{
ObsList boxes;
ObsList bases;
ObsList pyrs;
ObsList teles;
ObsList faces;
ObsList meshes;
} named;
} SplitObsList;
typedef struct
{
int count;
const class ColDetNode** list;
} ColDetNodeList;
// well you know my name is Simon, and I like to do drawings
typedef void (*DrawLinesFunc)
(int pointCount, float (*points)[3], int color);
class CollisionManager
{
public:
CollisionManager();
~CollisionManager();
void load ();
void clear ();
// some basics
bool needReload() const; // octree parameter has changed
int getObstacleCount() const; // total number of obstacles
const Extents& getWorldExtents() const;
// test against an axis aligned bounding box
const ObsList* axisBoxTest (const Extents& extents);
// test against a cylinder
const ObsList* cylinderTest (const float *pos,
float radius, float height) const;
// test against a box
const ObsList* boxTest (const float* pos, float angle,
float dx, float dy, float dz) const;
// test against a moving box
const ObsList* movingBoxTest (const float* oldPos, float oldAngle,
const float* pos, float angle,
float dx, float dy, float dz) const;
// test against a Ray
const ObsList* rayTest (const Ray* ray, float timeLeft) const;
// test against a Ray (and return a list of ColDetNodes)
const ColDetNodeList* rayTestNodes (const Ray* ray, float timeLeft) const;
// test against a box and return a split list
//const SplitObsList *boxTestSplit (const float* pos, float angle,
// float dx, float dy, float dz) const;
// drawing function
void draw (DrawLinesFunc drawLinesFunc);
private:
void setExtents(ObsList* list); // gather the extents
class ColDetNode* root; // the root of the octree
float worldSize;
Extents gridExtents;
Extents worldExtents;
};
extern CollisionManager COLLISIONMGR;
class ColDetNode
{
public:
ColDetNode(unsigned char depth, const Extents& exts, ObsList *fullList);
~ColDetNode();
int getCount() const;
const ObsList* getList() const;
const Extents& getExtents() const;
float getInTime() const;
float getOutTime() const;
// these fill in the FullList return list
void axisBoxTest (const Extents& extents) const;
void boxTest (const float* pos, float angle, float dx, float dy, float dz) const;
void rayTest (const Ray* ray, float timeLeft) const;
void rayTestNodes (const Ray* ray, float timeLeft) const;
// this fills in the SplitList return list
// (FIXME: not yet implemented, boxTestSplit might be useful for radar)
//void boxTestSplit (const float* pos, float angle, float dx, float dy, float dz) const;
void tallyStats();
void draw(DrawLinesFunc drawLinesFunc);
private:
void makeChildren ();
void resizeCell ();
unsigned char depth;
int count;
Extents extents;
unsigned char childCount;
ColDetNode* children[8];
ObsList fullList;
mutable float inTime, outTime;
};
inline int ColDetNode::getCount() const
{
return count;
}
inline const ObsList* ColDetNode::getList() const
{
return &fullList;
}
inline const Extents& ColDetNode::getExtents() const
{
return extents;
}
inline float ColDetNode::getInTime() const
{
return inTime;
}
inline float ColDetNode::getOutTime() const
{
return outTime;
}
inline int CollisionManager::getObstacleCount() const
{
if (root == NULL)
return 0;
else
return root->getCount();
}
inline const Extents& CollisionManager::getWorldExtents() const
{
return worldExtents;
}
#endif /* __COLLISION_GRID__ */
// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
|