37 #include "../idlib/precompiled.h"
160 d = l2[4] * cross[0] + l2[5] * cross[1] + l2[2] * cross[2];
204 if ( !(v->
sideSet & (1<<bitNum)) ) {
220 if ( !(edge->
sideSet & (1<<bitNum)) ) {
224 edge->
sideSet |= (1 << bitNum);
235 float f1, f2, dist, d1, d2;
242 for ( i = 0; i < poly->
numEdges; i++) {
287 if ( f2 > 1.0
f || f1 < f2 ) {
295 if ( f2 < tw->trace.fraction ) {
315 normal[0] = trmEdge->
cross[2];
316 normal[1] = -trmEdge->
cross[1];
317 normal[2] = trmEdge->
cross[0];
318 dist = normal * trmEdge->
start;
319 d1 = normal * start - dist;
320 d2 = normal * end - dist;
321 f1 = d1 / ( d1 - d2 );
386 return (d1-CM_CLIP_EPSILON) / d2;
402 if ( f < tw->trace.fraction ) {
404 for ( i = 0; i < poly->
numEdges; i++ ) {
446 if ( f < tw->trace.fraction ) {
448 for ( i = 0; i < poly->
numEdges; i++ ) {
498 if ( f < tw->trace.fraction ) {
500 for ( i = 0; i < trmpoly->
numEdges; i++ ) {
501 edgeNum = trmpoly->
edges[
i];
502 edge = tw->
edges + abs(edgeNum);
537 int i,
j, k, edgeNum;
601 for ( i = 0; i < p->
numEdges; i++ ) {
624 for ( i = 0; i < tw->
numVerts; i++ ) {
632 for ( i = 1; i <= tw->
numEdges; i++ ) {
640 for ( i = 0; i < p->
numEdges; i++ ) {
654 for ( k = 0; k < 2; k++ ) {
670 endp = v->
p - tw->
dir;
674 for ( j = 0; j < tw->
numPolys; j++ ) {
687 endp = tw->
start + fraction * tw->
dir;
689 for ( i = 0; i < 3; i++ ) {
690 if ( tw->
start[i] < endp[i] ) {
714 for ( i = 0; i < trm->
numVerts; i++ ) {
720 for ( i = 1; i <= trm->
numEdges; i++ ) {
727 for ( i = 0; i < trm->
numPolys; i++ ) {
745 idVec3 dir, normal1, normal2;
763 static int entered = 0;
772 bool model_rotated, trm_rotated;
774 idMat3 invModelAxis, tmpAxis;
784 memset( results, 0,
sizeof( *results ) );
787 common->
Printf(
"idCollisionModelManagerLocal::Translation: invalid model handle\n");
791 common->
Printf(
"idCollisionModelManagerLocal::Translation: invalid model\n");
796 if ( start[0] == end[0] && start[1] == end[1] && start[2] == end[2] ) {
802 bool startsolid =
false;
831 tw.
start = start - modelOrigin;
832 tw.
end = end - modelOrigin;
836 if ( model_rotated ) {
841 if ( !trm || ( trm->
bounds[1][0] - trm->
bounds[0][0] <= 0.0f &&
845 if ( model_rotated ) {
847 tw.
start *= invModelAxis;
848 tw.
end *= invModelAxis;
849 tw.
dir *= invModelAxis;
853 for ( i = 0; i < 3; i++ ) {
886 if ( model_rotated ) {
887 results->
c.
normal *= modelAxis;
888 results->
c.
point *= modelAxis;
890 results->
c.
point += modelOrigin;
908 common->
Printf(
"idCollisionModelManagerLocal::Translation: huge translation\n" );
922 for ( i = 0; i < tw.
numVerts; i++ ) {
927 for ( i = 0; i < tw.
numVerts; i++ ) {
931 if ( model_rotated ) {
932 for ( i = 0; i < tw.
numVerts; i++ ) {
940 dir = trm->
offset * trmAxis;
947 if ( model_rotated ) {
949 tw.
start *= invModelAxis;
950 tw.
end *= invModelAxis;
951 tw.
dir *= invModelAxis;
955 if ( trm_rotated & model_rotated ) {
956 tmpAxis = trmAxis * invModelAxis;
957 for ( poly = tw.
polys, i = 0; i < tw.
numPolys; i++, poly++ ) {
958 poly->
plane *= tmpAxis;
960 }
else if ( trm_rotated ) {
961 for ( poly = tw.
polys, i = 0; i < tw.
numPolys; i++, poly++ ) {
962 poly->
plane *= trmAxis;
964 }
else if ( model_rotated ) {
965 for ( poly = tw.
polys, i = 0; i < tw.
numPolys; i++, poly++ ) {
966 poly->
plane *= invModelAxis;
971 for ( poly = tw.
polys, i = 0; i < tw.
numPolys; i++, poly++ ) {
974 if ( dist > 0.0
f || ( !trm->
isConvex && dist == 0.0f ) ) {
977 for ( j = 0; j < poly->
numEdges; j++ ) {
1000 for ( edge = tw.
edges + 1, i = 1; i <= tw.
numEdges; i++, edge++ ) {
1001 if ( !edge->
used ) {
1010 edge->
cross[0] = dir[0] * tw.
dir[1] - dir[1] * tw.
dir[0];
1011 edge->
cross[1] = dir[0] * tw.
dir[2] - dir[2] * tw.
dir[0];
1012 edge->
cross[2] = dir[1] * tw.
dir[2] - dir[2] * tw.
dir[1];
1018 for ( poly = tw.
polys, i = 0; i < tw.
numPolys; i++, poly++ ) {
1025 for ( i = 0; i < 3; i++ ) {
1046 if ( !vert->
used ) {
1068 if ( model_rotated ) {
1083 *results = tw.
trace;
1093 if ( model_rotated ) {
1094 results->
c.
normal *= modelAxis;
1095 results->
c.
point *= modelAxis;
1097 results->
c.
point += modelOrigin;
float CM_TranslationPlaneFraction(idPlane &plane, idVec3 &start, idVec3 &end)
void SetupTrm(cm_traceWork_t *tw, const idTraceModel *trm)
bool Compare(const idVec3 &a) const
void cross(float a[], float b[], float c[])
assert(prefInfo.fullscreenBtn)
const idVec3 & Normal(void) const
idMat3 mat3_identity(idVec3(1, 0, 0), idVec3(0, 1, 0), idVec3(0, 0, 1))
virtual void DebugArrow(const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime=0)=0
void TranslateVertexThroughTrmPolygon(cm_traceWork_t *tw, cm_trmPolygon_t *trmpoly, cm_polygon_t *poly, cm_vertex_t *v, idVec3 &endp, idPluecker &pl)
void TranslateTrmEdgeThroughPolygon(cm_traceWork_t *tw, cm_polygon_t *poly, cm_trmEdge_t *trmEdge)
traceModelVert_t verts[MAX_TRACEMODEL_VERTS]
idMat3 Transpose(void) const
float Distance(const idVec3 &v) 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)
idPluecker polygonEdgePlueckerCache[CM_MAX_POLYGON_EDGES]
idCVar cm_debugCollision("cm_debugCollision","0", CVAR_GAME|CVAR_BOOL,"debug the collision detection")
#define CM_MAX_TRACE_DIST
const idMaterial * material
int ContentsTrm(trace_t *results, const idVec3 &start, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
traceModelEdge_t edges[MAX_TRACEMODEL_EDGES+1]
void SetNormal(const idVec3 &normal)
bool IsRotated(void) const
void FromLine(const idVec3 &start, const idVec3 &end)
void TranslatePointThroughPolygon(cm_traceWork_t *tw, cm_polygon_t *poly, cm_trmVertex_t *v)
ID_INLINE void CM_AddContact(cm_traceWork_t *tw)
bool AddPoint(const idVec3 &v)
GLfloat GLfloat GLfloat v2
void SetupTranslationHeartPlanes(cm_traceWork_t *tw)
#define FLOATSIGNBITSET(f)
int TranslateEdgeThroughEdge(idVec3 &cross, idPluecker &l1, idPluecker &l2, float *fraction)
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
ID_INLINE void CM_SetEdgeSidedness(cm_edge_t *edge, const idPluecker &vpl, const idPluecker &epl, const int bitNum)
cm_trmEdge_t edges[MAX_TRACEMODEL_EDGES+1]
static float Fabs(float f)
#define INTSIGNBITNOTSET(i)
float PlaneDistance(const idPlane &plane) const
void TraceThroughModel(cm_traceWork_t *tw)
int edges[MAX_TRACEMODEL_POLYEDGES]
float PermutedInnerProduct(const idPluecker &a) const
ID_INLINE void CM_SetVertexSidedness(cm_vertex_t *v, const idPluecker &vpl, const idPluecker &epl, const int bitNum)
float LengthSqr(void) const
void FromRay(const idVec3 &start, const idVec3 &dir)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void TranslateTrmVertexThroughPolygon(cm_traceWork_t *tw, cm_polygon_t *poly, cm_trmVertex_t *v, int bitNum)
#define FLOATSIGNBITNOTSET(f)
bool IntersectsBounds(const idBounds &a) const
traceModelPoly_t polys[MAX_TRACEMODEL_POLYS]
int Contents(const idVec3 &start, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
int edges[MAX_TRACEMODEL_POLYEDGES]
idPluecker polygonVertexPlueckerCache[CM_MAX_POLYGON_EDGES]
cm_trmPolygon_t polys[MAX_TRACEMODEL_POLYS]
int PlaneSide(const idPlane &plane, const float epsilon=ON_EPSILON) const
bool ContainsPoint(const idVec3 &p) const
void NormalVectors(idVec3 &left, idVec3 &down) const
float maxDistFromHeartPlane2
bool TranslateTrmThroughPolygon(cm_traceWork_t *tw, cm_polygon_t *p)
cm_trmVertex_t vertices[MAX_TRACEMODEL_VERTS]
float maxDistFromHeartPlane1
void FitThroughPoint(const idVec3 &p)