37 #include "../idlib/precompiled.h"
110 if ( token ==
"," ) {
133 contentsString[0] =
'\0';
138 length +=
idStr::snPrintf( contentsString + length,
sizeof( contentsString ) - length,
"," );
144 return contentsString;
160 edge = model->
edges + abs(edgeNum);
185 mid = (start +
end) * 0.5
f;
187 end = mid + 5 * (axis * edge->
normal);
189 end = mid + 5 * edge->
normal;
206 edgeNum = p->
edges[0];
207 edge = model->
edges + abs(edgeNum);
216 for ( i = 0; i < p->
numEdges; i++ ) {
218 edge = model->
edges + abs(edgeNum);
223 center = center * axis + origin;
234 for ( i = p->
numEdges - 1; i >= 0; i-- ) {
236 edge = model->
edges + abs(edgeNum);
241 for ( i = 0; i < p->
numEdges; i++ ) {
243 edge = model->
edges + abs(edgeNum);
248 DrawEdge( model, edgeNum, origin, axis );
260 const idVec3 &viewOrigin,
const float radius ) {
266 for ( pref = node->
polygons; pref; pref = pref->
next ) {
270 for ( i = 0; i < 3; i++ ) {
271 if ( p->
bounds[0][i] > viewOrigin[i] + radius ) {
274 if ( p->
bounds[1][i] < viewOrigin[i] - radius ) {
312 const idVec3 &viewOrigin,
const float radius ) {
317 if ( handle < 0 && handle >=
numModels ) {
327 viewPos = (viewOrigin - modelOrigin) * modelAxis.
Transpose();
345 static idCVar cm_testOrigin(
"cm_testOrigin",
"0 0 0",
CVAR_GAME,
"" );
347 static idCVar cm_testBox(
"cm_testBox",
"-16 -16 0 16 16 64",
CVAR_GAME,
"" );
348 static idCVar cm_testBoxRotation(
"cm_testBoxRotation",
"0 0 0",
CVAR_GAME,
"" );
354 static int total_translation;
355 static int min_translation = 999999;
356 static int max_translation = -999999;
357 static int num_translation = 0;
358 static int total_rotation;
359 static int min_rotation = 999999;
360 static int max_rotation = -999999;
361 static int num_rotation = 0;
365 #include "../sys/sys_public.h"
372 idMat3 modelAxis, boxAxis;
376 if ( !cm_testCollision.
GetBool() ) {
383 total_translation = total_rotation = 0;
384 min_translation = min_rotation = 999999;
385 max_translation = max_rotation = -999999;
386 num_translation = num_rotation = 0;
392 cm_testOrigin.
SetString(
va(
"%1.2f %1.2f %1.2f", start[0], start[1], start[2] ) );
394 sscanf( cm_testOrigin.
GetString(),
"%f %f %f", &start[0], &start[1], &start[2] );
397 sscanf( cm_testBox.
GetString(),
"%f %f %f %f %f %f", &bounds[0][0], &bounds[0][1], &bounds[0][2],
398 &bounds[1][0], &bounds[1][1], &bounds[1][2] );
399 sscanf( cm_testBoxRotation.
GetString(),
"%f %f %f", &boxAngles[0], &boxAngles[1], &boxAngles[2] );
400 boxAxis = boxAngles.ToMat3();
407 if ( cm_testRandomMany.
GetBool() ) {
409 for ( i = 0; i < 3; i++ ) {
412 for ( k = 1; k < cm_testTimes.
GetInteger(); k++ ) {
413 testend[k] = testend[0];
417 for ( k = 0; k < cm_testTimes.
GetInteger(); k++ ) {
418 for ( i = 0; i < 3; i++ ) {
427 for ( i = 0; i < cm_testTimes.
GetInteger(); i++ ) {
432 if ( t < min_translation ) min_translation =
t;
433 if ( t > max_translation ) max_translation =
t;
435 total_translation +=
t;
441 common->
Printf(
"%s translations: %4d milliseconds, (min = %d, max = %d, av = %1.1f)\n", buf, t, min_translation, max_translation, (
float) total_translation / num_translation );
443 if ( cm_testRandomMany.
GetBool() ) {
445 for ( i = 0; i < 3; i++ ) {
448 for ( k = 1; k < cm_testTimes.
GetInteger(); k++ ) {
449 testend[k] = testend[0];
453 for ( k = 0; k < cm_testTimes.
GetInteger(); k++ ) {
454 for ( i = 0; i < 3; i++ ) {
460 if ( cm_testRotation.
GetBool() ) {
468 for ( i = 0; i < cm_testTimes.
GetInteger(); i++ ) {
469 rotation.SetOrigin( testend[i] );
474 if ( t < min_rotation ) min_rotation =
t;
475 if ( t > max_rotation ) max_rotation =
t;
483 common->
Printf(
"%s rotation: %4d milliseconds, (min = %d, max = %d, av = %1.1f)\n", buf, t, min_rotation, max_rotation, (
float) total_rotation / num_rotation );
struct cm_node_s * children[2]
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
bool Compare(const idVec3 &a) const
idCVar cm_drawFilled("cm_drawFilled","0", CVAR_GAME|CVAR_BOOL,"draw filled polygons")
const idVec3 & Normal(void) const
virtual void DebugArrow(const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime=0)=0
float GetFloat(void) const
idCVar cm_drawNormals("cm_drawNormals","0", CVAR_GAME|CVAR_BOOL,"draw polygon and edge normals")
idMat3 Transpose(void) const
void Translation(trace_t *results, const idVec3 &start, const idVec3 &end, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
const char * StringFromContents(const int contents) const
idCVar cm_debugCollision("cm_debugCollision","0", CVAR_GAME|CVAR_BOOL,"debug the collision detection")
struct cm_polygonRef_s * next
idCVar cm_drawColor("cm_drawColor","1 0 0 .5", CVAR_GAME,"color used to draw the collision models")
double Milliseconds(void) const
void DrawEdge(cm_model_t *model, int edgeNum, const idVec3 &origin, const idMat3 &axis)
bool IsRotated(void) const
int Icmp(const char *text) const
int cm_contentsFlagByIndex[]
const char * cm_contentsNameByIndex[]
void SetString(const char *value)
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
void Rotation(trace_t *results, const idVec3 &start, const idRotation &rotation, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
int GetInteger(void) const
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void DebugOutput(const idVec3 &origin)
void DrawPolygon(cm_model_t *model, cm_polygon_t *p, const idVec3 &origin, const idMat3 &axis, const idVec3 &viewOrigin)
const char * GetString(void) const
int ContentsFromString(const char *string) const
void DrawNodePolygons(cm_model_t *model, cm_node_t *node, const idVec3 &origin, const idMat3 &axis, const idVec3 &viewOrigin, const float radius)
idCVar cm_drawInternal("cm_drawInternal","1", CVAR_GAME|CVAR_BOOL,"draw internal edges green")
bool IsModified(void) const
GLsizei const GLcharARB const GLint * length
idCVar cm_backFaceCull("cm_backFaceCull","0", CVAR_GAME|CVAR_BOOL,"cull back facing polygons")
virtual void DebugPolygon(const idVec4 &color, const idWinding &winding, const int lifeTime=0, const bool depthTest=false)=0
void SetBool(const bool value)
void * Mem_Alloc(const int size)
void DrawModel(cmHandle_t model, const idVec3 &origin, const idMat3 &axis, const idVec3 &viewOrigin, const float radius)
char * va(const char *fmt,...)
cm_polygonRef_t * polygons
idCVar cm_drawMask("cm_drawMask","none", CVAR_GAME,"collision mask", cm_contentsNameByIndex, idCmdSystem::ArgCompletion_String< cm_contentsNameByIndex >)
int ReadToken(idToken *token)
int sprintf(idStr &string, const char *fmt,...)