29 #include "../../idlib/precompiled.h"
47 offset = ( boxBounds[0] + boxBounds[1] ) * 0.5
f;
49 for ( i = 0; i < 8; i++ ) {
50 verts[
i][0] = boxBounds[(i^(i>>1))&1][0];
51 verts[
i][1] = boxBounds[(i>>1)&1][1];
52 verts[
i][2] = boxBounds[(i>>2)&1][2];
62 for ( i = 0; i < 6; i++ ) {
86 halfSize = size * 0.5f;
87 boxBounds[0].Set( -halfSize, -halfSize, -halfSize );
88 boxBounds[1].Set( halfSize, halfSize, halfSize );
108 for ( i = 0; i < 4; i++ ) {
110 edges[ i + 1 ].
v[1] = (i + 1) & 3;
112 edges[ i + 5 ].
v[1] = 4 + ((i + 1) & 3);
179 offset = ( octBounds[0] + octBounds[1] ) * 0.5
f;
180 v[0] = octBounds[1][0] -
offset[0];
181 v[1] = octBounds[1][1] - offset[1];
182 v[2] = octBounds[1][2] - offset[2];
185 verts[0].
Set( offset.x + v[0], offset.
y, offset.z );
186 verts[1].
Set( offset.x - v[0], offset.
y, offset.z );
187 verts[2].
Set( offset.x, offset.y + v[1], offset.
z );
188 verts[3].
Set( offset.x, offset.y - v[1], offset.
z );
189 verts[4].
Set( offset.x, offset.y, offset.z + v[2] );
190 verts[5].
Set( offset.x, offset.y, offset.z - v[2] );
226 halfSize = size * 0.5f;
227 octBounds[0].Set( -halfSize, -halfSize, -halfSize );
228 octBounds[1].Set( halfSize, halfSize, halfSize );
311 int i, e0, e1, e2, e3,
v0,
v1,
v2,
v3, v4;
319 a[0] = a[1] = a[2] = 0.5773502691896257f;
320 b[0] = b[1] = b[2] = 0.3568220897730899f;
321 c[0] = c[1] = c[2] = 0.9341723589627156f;
323 s = ( dodBounds[1][0] - dodBounds[0][0] ) * d;
327 s = ( dodBounds[1][1] - dodBounds[0][1] ) * d;
331 s = ( dodBounds[1][2] - dodBounds[0][2] ) * d;
336 offset = ( dodBounds[0] + dodBounds[1] ) * 0.5
f;
400 halfSize = size * 0.5f;
401 dodBounds[0].Set( -halfSize, -halfSize, -halfSize );
402 dodBounds[1].Set( halfSize, halfSize, halfSize );
572 offset = ( cylBounds[0] + cylBounds[1] ) * 0.5
f;
573 halfSize = cylBounds[1] -
offset;
574 for ( i = 0; i <
n; i++ ) {
577 verts[
i].
x = cos( angle ) * halfSize.
x + offset.x;
578 verts[
i].
y = sin( angle ) * halfSize.
y + offset.y;
579 verts[
i].
z = -halfSize.
z + offset.z;
582 verts[n+
i].
z = halfSize.
z + offset.z;
606 for ( i = 0; i <
n; i++ ) {
645 float halfHeight, halfWidth;
647 halfHeight = height * 0.5f;
648 halfWidth = width * 0.5f;
649 cylBounds[0].Set( -halfWidth, -halfWidth, -halfHeight );
650 cylBounds[1].Set( halfWidth, halfWidth, halfHeight );
685 offset = ( coneBounds[0] + coneBounds[1] ) * 0.5
f;
686 halfSize = coneBounds[1] -
offset;
688 for ( i = 0; i <
n; i++ ) {
691 verts[
i].
x = cos( angle ) * halfSize.
x + offset.x;
692 verts[
i].
y = sin( angle ) * halfSize.
y + offset.y;
693 verts[
i].
z = -halfSize.
z + offset.z;
712 for ( i = 0; i <
n; i++ ) {
748 halfWidth = width * 0.5f;
749 coneBounds[0].Set( -halfWidth, -halfWidth, -height );
750 coneBounds[1].Set( halfWidth, halfWidth, 0.0
f );
763 float halfLength = length * 0.5f;
773 verts[2].
Set( width * 0.5
f, width * 0.25f, 0.0f );
774 verts[3].
Set( width * -0.5f, width * 0.25f, 0.0f );
775 verts[4].
Set( 0.0f, 0.0f, halfLength );
777 bounds[0].Set( width * -0.5f, width * -0.5f, -halfLength );
778 bounds[1].Set( width * 0.5f, width * 0.25f, halfLength );
789 for ( i = 0; i < 6; i++ ) {
792 for ( j = 0; j < 3; j++ ) {
817 for ( i = 0; i < 3; i++ ) {
819 edges[ i + 1 ].
v[1] = i + 1;
821 edges[ i + 4 ].
v[1] = 1 + ((i + 1) % 3);
822 edges[ i + 7 ].
v[0] = i + 1;
882 polys[0].
normal = ( v[1] - v[0] ).Cross( v[2] - v[0] );
891 for ( i = 0, j = 1; i <
numVerts; i++, j++ ) {
892 if ( j >= numVerts ) {
925 verts[
i] = w[
i].ToVec3();
947 trm.
edges[ numEdges * 2 + i + 1 ].
v[0] =
i;
954 trm.
polys[2+
i].
edges[3] = -(numEdges*2 + (i+1) % numEdges + 1);
969 #define SHARP_EDGE_DOT -0.7f
972 int i,
j, edgeNum, numSharpEdges;
985 for ( j = 0; j < poly->
numEdges; j++ ) {
987 edge =
edges + abs( edgeNum );
988 if ( edge->
normal[0] == 0.0f && edge->
normal[1] == 0.0f && edge->
normal[2] == 0.0f ) {
996 dir =
verts[ edge->
v[edgeNum > 0]] -
verts[ edge->
v[edgeNum < 0]];
1007 return numSharpEdges;
1027 bounds[0] += translation;
1028 bounds[1] += translation;
1072 edge = &
edges[abs(edgeNum)];
1078 verts[ edge->
v[ 0 ] ] -= dir;
1079 verts[ edge->
v[ 1 ] ] += dir;
1089 edge = &
edges[abs(edgeNum)];
1123 for ( i = 0; i < trm.
numVerts; i++ ) {
1144 if ( polyNum < 0 || polyNum >=
numPolys ) {
1147 poly = &
polys[polyNum];
1150 for ( i = 0; i < poly->
numEdges; i++ ) {
1153 cross = v1.
Cross( v2 );
1156 return total * 0.5f;
1165 int i,
j, edgeNum, numSilEdges, nextSilVert;
1169 for ( i = 1; i <=
numEdges; i++ ) {
1170 if ( edgeIsSilEdge[i] ) {
1171 unsortedSilEdges[numSilEdges++] =
i;
1175 silEdges[0] = unsortedSilEdges[0];
1176 unsortedSilEdges[0] = -1;
1177 nextSilVert =
edges[silEdges[0]].
v[0];
1178 for ( i = 1; i < numSilEdges; i++ ) {
1179 for ( j = 1; j < numSilEdges; j++ ) {
1180 edgeNum = unsortedSilEdges[
j];
1181 if ( edgeNum >= 0 ) {
1182 if (
edges[edgeNum].
v[0] == nextSilVert ) {
1183 nextSilVert =
edges[edgeNum].
v[1];
1184 silEdges[
i] = edgeNum;
1187 if (
edges[edgeNum].
v[1] == nextSilVert ) {
1188 nextSilVert =
edges[edgeNum].
v[0];
1189 silEdges[
i] = -edgeNum;
1194 if ( j >= numSilEdges ) {
1197 unsortedSilEdges[
j] = -1;
1209 int edgeIsSilEdge[MAX_TRACEMODEL_EDGES+1];
1213 memset( edgeIsSilEdge, 0,
sizeof( edgeIsSilEdge ) );
1217 edgeNum = poly->
edges[0];
1219 if ( dir * poly->
normal < 0.0f ) {
1220 for ( j = 0; j < poly->
numEdges; j++ ) {
1221 edgeNum = poly->
edges[
j];
1222 edgeIsSilEdge[abs(edgeNum)] ^= 1;
1237 int edgeIsSilEdge[MAX_TRACEMODEL_EDGES+1];
1240 memset( edgeIsSilEdge, 0,
sizeof( edgeIsSilEdge ) );
1244 if ( projectionDir * poly->
normal < 0.0f ) {
1245 for ( j = 0; j < poly->
numEdges; j++ ) {
1246 edgeNum = poly->
edges[
j];
1247 edgeIsSilEdge[abs(edgeNum)] ^= 1;
1280 float a0_2, a0_3, a0_4, b0_2, b0_3, b0_4;
1281 float a1_2, a1_3, b1_2, b1_3;
1282 float C1, Ca, Caa, Caaa, Cb, Cbb, Cbbb;
1283 float Cab, Kab, Caab, Kaab, Cabb, Kabb;
1286 poly = &
polys[polyNum];
1287 for ( i = 0; i < poly->
numEdges; i++ ) {
1288 edgeNum = poly->
edges[
i];
1289 v1 =
verts[
edges[ abs(edgeNum) ].
v[ edgeNum < 0 ] ];
1290 v2 =
verts[
edges[ abs(edgeNum) ].
v[ edgeNum > 0 ] ];
1309 Ca = a1 * C1 + a0_2;
1310 Caa = a1 * Ca + a0_3;
1311 Caaa = a1 * Caa + a0_4;
1312 Cb = b1 * (b1 + b0) + b0_2;
1313 Cbb = b1 * Cb + b0_3;
1314 Cbbb = b1 * Cbb + b0_4;
1315 Cab = 3 * a1_2 + 2 * a1 * a0 + a0_2;
1316 Kab = a1_2 + 2 * a1 * a0 + 3 * a0_2;
1317 Caab = a0 * Cab + 4 * a1_3;
1318 Kaab = a1 * Kab + 4 * a0_3;
1319 Cabb = 4 * b1_3 + 3 * b1_2 * b0 + 2 * b1 * b0_2 + b0_3;
1320 Kabb = b1_3 + 2 * b1_2 * b0 + 3 * b1 * b0_2 + 4 * b0_3;
1322 integrals.
P1 += db * C1;
1323 integrals.
Pa += db * Ca;
1324 integrals.
Paa += db * Caa;
1325 integrals.
Paaa += db * Caaa;
1326 integrals.
Pb += da * Cb;
1327 integrals.
Pbb += da * Cbb;
1328 integrals.
Pbbb += da * Cbbb;
1329 integrals.
Pab += db * (b1 * Cab + b0 * Kab);
1330 integrals.
Paab += db * (b1 * Caab + b0 * Kaab);
1331 integrals.
Pabb += da * (a1 * Cabb + a0 * Kabb);
1334 integrals.
P1 *= (1.0f / 2.0f);
1335 integrals.
Pa *= (1.0f / 6.0f);
1336 integrals.
Paa *= (1.0f / 12.0f);
1337 integrals.
Paaa *= (1.0f / 20.0f);
1338 integrals.
Pb *= (1.0f / -6.0f);
1339 integrals.
Pbb *= (1.0f / -12.0f);
1340 integrals.
Pbbb *= (1.0f / -20.0f);
1341 integrals.
Pab *= (1.0f / 24.0f);
1342 integrals.
Paab *= (1.0f / 60.0f);
1343 integrals.
Pabb *= (1.0f / -60.0f);
1362 float k1, k2, k3, k4;
1373 integrals.
Fa = k1 * pi.
Pa;
1374 integrals.
Fb = k1 * pi.
Pb;
1375 integrals.
Fc = -k2 * (n[
a] * pi.
Pa + n[
b] * pi.
Pb + w * pi.
P1);
1377 integrals.
Faa = k1 * pi.
Paa;
1378 integrals.
Fbb = k1 * pi.
Pbb;
1380 + w * (2 * (n[
a] * pi.
Pa + n[
b] * pi.
Pb) + w * pi.
P1));
1387 + w * w * (3 * (n[a] * pi.
Pa + n[b] * pi.
Pb) + w * pi.
P1));
1392 + w * (2 * (n[
a] * pi.
Paa + n[
b] * pi.
Pab) + w * pi.
Pa));
1420 if ( nx > ny && nx > nz ) {
1424 c = (ny >
nz) ? 1 : 2;
1431 integrals.
T0 += poly->
normal[0] * ((a == 0) ? pi.
Fa : ((b == 0) ? pi.
Fb : pi.
Fc));
1444 integrals.
T1 *= 0.5f;
1445 integrals.
T2 *= (1.0f / 3.0f);
1446 integrals.
TP *= 0.5f;
1469 if ( integrals.
T0 == 0.0f ) {
1471 centerOfMass.
Zero();
1477 mass = density * integrals.
T0;
1479 centerOfMass = integrals.
T1 / integrals.
T0;
1481 inertiaTensor[0][0] = density * (integrals.
T2[1] + integrals.
T2[2]);
1482 inertiaTensor[1][1] = density * (integrals.
T2[2] + integrals.
T2[0]);
1483 inertiaTensor[2][2] = density * (integrals.
T2[0] + integrals.
T2[1]);
1484 inertiaTensor[0][1] = inertiaTensor[1][0] = - density * integrals.
TP[0];
1485 inertiaTensor[1][2] = inertiaTensor[2][1] = - density * integrals.
TP[1];
1486 inertiaTensor[2][0] = inertiaTensor[0][2] = - density * integrals.
TP[2];
1488 inertiaTensor[0][0] -= mass * (centerOfMass[1]*centerOfMass[1] + centerOfMass[2]*centerOfMass[2]);
1489 inertiaTensor[1][1] -= mass * (centerOfMass[2]*centerOfMass[2] + centerOfMass[0]*centerOfMass[0]);
1490 inertiaTensor[2][2] -= mass * (centerOfMass[0]*centerOfMass[0] + centerOfMass[1]*centerOfMass[1]);
1491 inertiaTensor[0][1] = inertiaTensor[1][0] += mass * centerOfMass[0] * centerOfMass[1];
1492 inertiaTensor[1][2] = inertiaTensor[2][1] += mass * centerOfMass[1] * centerOfMass[2];
1493 inertiaTensor[2][0] = inertiaTensor[0][2] += mass * centerOfMass[2] * centerOfMass[0];
void SetupPolygon(const idVec3 *v, const int count)
void cross(float a[], float b[], float c[])
void Rotate(const idMat3 &rotation)
int GetProjectionSilhouetteEdges(const idVec3 &projectionOrigin, int silEdges[MAX_TRACEMODEL_EDGES]) const
struct volumeIntegrals_s volumeIntegrals_t
void SetupBox(const idBounds &boxBounds)
traceModelVert_t verts[MAX_TRACEMODEL_VERTS]
void Set(const float x, const float y, const float z)
void SetupCylinder(const idBounds &cylBounds, const int numSides)
struct polygonIntegrals_s polygonIntegrals_t
GLuint GLuint GLsizei GLenum type
traceModelEdge_t edges[MAX_TRACEMODEL_EDGES+1]
idVec3 Cross(const idVec3 &a) const
void GetMassProperties(const float density, float &mass, idVec3 ¢erOfMass, idMat3 &inertiaTensor) const
int GetOrderedSilhouetteEdges(const int edgeIsSilEdge[MAX_TRACEMODEL_EDGES+1], int silEdges[MAX_TRACEMODEL_EDGES]) const
bool Compare(const idTraceModel &trm) const
void InitOctahedron(void)
#define MAX_TRACEMODEL_POLYS
struct projectionIntegrals_s projectionIntegrals_t
void Translate(const idVec3 &translation)
bool AddPoint(const idVec3 &v)
GLfloat GLfloat GLfloat v2
GLuint GLuint GLsizei count
void VolumeFromPolygon(idTraceModel &trm, float thickness) const
void SetupBone(const float length, const float width)
int GetNumPoints(void) const
GLubyte GLubyte GLubyte GLubyte w
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
static float Fabs(float f)
#define INTSIGNBITNOTSET(i)
void SetupOctahedron(const idBounds &octBounds)
int edges[MAX_TRACEMODEL_POLYEDGES]
void SetupCone(const idBounds &coneBounds, const int numSides)
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
GLenum GLsizei GLsizei height
void ProjectionIntegrals(int polyNum, int a, int b, struct projectionIntegrals_s &integrals) const
int GetParallelProjectionSilhouetteEdges(const idVec3 &projectionDir, int silEdges[MAX_TRACEMODEL_EDGES]) const
void Shrink(const float m)
GLfloat GLfloat GLfloat GLfloat nx
static const float TWO_PI
#define MAX_TRACEMODEL_EDGES
GLfloat GLfloat GLfloat GLfloat v3
GLsizei const GLcharARB const GLint * length
float GetPolygonArea(int polyNum) const
void PolygonIntegrals(int polyNum, int a, int b, int c, struct polygonIntegrals_s &integrals) const
void VolumeIntegrals(struct volumeIntegrals_s &integrals) const
traceModelPoly_t polys[MAX_TRACEMODEL_POLYS]
int GenerateEdgeNormals(void)
#define MAX_TRACEMODEL_VERTS
void SetupDodecahedron(const idBounds &dodBounds)
float dot(float a[], float b[])
void InitDodecahedron(void)
static class idCommon * common