MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ComputeRoomBoundingSphere

Function ComputeRoomBoundingSphere

Descent3/room.cpp:1096–1183  ·  view source on GitHub ↗

Computes a bounding sphere for the current room Parameters: center - filled in with the center point of the sphere rp - the room we�re bounding Returns: the radius of the bounding sphere

Source from the content-addressed store, hash-verified

1094// rp - the room we�re bounding
1095// Returns: the radius of the bounding sphere
1096float ComputeRoomBoundingSphere(vector *center, room *rp) {
1097 // This algorithm is from Graphics Gems I. There's a better algorithm in Graphics Gems III that
1098 // we should probably implement sometime.
1099
1100 vector *min_x, *max_x, *min_y, *max_y, *min_z, *max_z, *vp;
1101 float dx, dy, dz;
1102 float rad, rad2;
1103 int i;
1104
1105#ifdef NEWEDITOR
1106 if (!rp->num_verts) {
1107 center->x = 0.0f;
1108 center->y = 0.0f;
1109 center->z = 0.0f;
1110 return 0.0f;
1111 }
1112#endif
1113
1114 // Initialize min, max vars
1115 min_x = max_x = min_y = max_y = min_z = max_z = &rp->verts[0];
1116
1117 // First, find the points with the min & max x,y, & z coordinates
1118 for (i = 0, vp = rp->verts; i < rp->num_verts; i++, vp++) {
1119
1120 if (vp->x < min_x->x)
1121 min_x = vp;
1122
1123 if (vp->x > max_x->x)
1124 max_x = vp;
1125
1126 if (vp->y < min_y->y)
1127 min_y = vp;
1128
1129 if (vp->y > max_y->y)
1130 max_y = vp;
1131
1132 if (vp->z < min_z->z)
1133 min_z = vp;
1134
1135 if (vp->z > max_z->z)
1136 max_z = vp;
1137 }
1138
1139 // Calculate initial sphere
1140
1141 dx = vm_VectorDistance(min_x, max_x);
1142 dy = vm_VectorDistance(min_y, max_y);
1143 dz = vm_VectorDistance(min_z, max_z);
1144
1145 if (dx > dy)
1146 if (dx > dz) {
1147 *center = (*min_x + *max_x) / 2;
1148 rad = dx / 2;
1149 } else {
1150 *center = (*min_z + *max_z) / 2;
1151 rad = dz / 2;
1152 }
1153 else if (dy > dz) {

Callers 5

AllocLoadRoomFunction · 0.85
SetViewerFromRoomFaceFunction · 0.85
DropRoomFunction · 0.85
CreateRoomObjectsFunction · 0.85
LGSObjectsFunction · 0.85

Calls 1

vm_VectorDistanceFunction · 0.50

Tested by

no test coverage detected