summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2012-12-13 19:11:20 +0400
committerAndrey Nazarov <skuller@skuller.net>2012-12-13 21:22:34 +0400
commit8939ca18b7dfc36be0728a9ddeaa8256fa8f09ca (patch)
tree34bb5b38ffb777cfa89449742ed454c809fc6889
parentb399f50e964dd7920d0f468000004964a2ab6166 (diff)
Simplify transformed box tracing.
Avoid calling AngleVectors twice, transpose rotation matrix instead. Add convenience functions.
-rw-r--r--inc/shared/shared.h27
-rw-r--r--src/common/cmodel.c35
2 files changed, 37 insertions, 25 deletions
diff --git a/inc/shared/shared.h b/inc/shared/shared.h
index 22024e4..761bfb8 100644
--- a/inc/shared/shared.h
+++ b/inc/shared/shared.h
@@ -267,6 +267,33 @@ static inline void AnglesToAxis(vec3_t angles, vec3_t axis[3])
VectorInverse(axis[1]);
}
+static inline void TransposeAxis(vec3_t axis[3])
+{
+ vec_t temp;
+
+ temp = axis[0][1];
+ axis[0][1] = axis[1][0];
+ axis[1][0] = temp;
+
+ temp = axis[0][2];
+ axis[0][2] = axis[2][0];
+ axis[2][0] = temp;
+
+ temp = axis[1][2];
+ axis[1][2] = axis[2][1];
+ axis[2][1] = temp;
+}
+
+static inline void RotatePoint(vec3_t point, vec3_t axis[3])
+{
+ vec3_t temp;
+
+ VectorCopy(point, temp);
+ point[0] = DotProduct(temp, axis[0]);
+ point[1] = DotProduct(temp, axis[1]);
+ point[2] = DotProduct(temp, axis[2]);
+}
+
static inline unsigned npot32(unsigned k)
{
if (k == 0)
diff --git a/src/common/cmodel.c b/src/common/cmodel.c
index 71c836f..5c75708 100644
--- a/src/common/cmodel.c
+++ b/src/common/cmodel.c
@@ -782,9 +782,7 @@ void CM_TransformedBoxTrace(trace_t *trace, vec3_t start, vec3_t end,
vec3_t origin, vec3_t angles)
{
vec3_t start_l, end_l;
- vec3_t a;
- vec3_t forward, right, up;
- vec3_t temp;
+ vec3_t axis[3];
qboolean rotated;
// subtract origin offset
@@ -799,36 +797,23 @@ void CM_TransformedBoxTrace(trace_t *trace, vec3_t start, vec3_t end,
rotated = qfalse;
if (rotated) {
- AngleVectors(angles, forward, right, up);
-
- VectorCopy(start_l, temp);
- start_l[0] = DotProduct(temp, forward);
- start_l[1] = -DotProduct(temp, right);
- start_l[2] = DotProduct(temp, up);
-
- VectorCopy(end_l, temp);
- end_l[0] = DotProduct(temp, forward);
- end_l[1] = -DotProduct(temp, right);
- end_l[2] = DotProduct(temp, up);
+ AnglesToAxis(angles, axis);
+ RotatePoint(start_l, axis);
+ RotatePoint(end_l, axis);
}
// sweep the box through the model
CM_BoxTrace(trace, start_l, end_l, mins, maxs, headnode, brushmask);
+ // rotate plane normal into the worlds frame of reference
if (rotated && trace->fraction != 1.0) {
- // FIXME: figure out how to do this with existing angles
- VectorNegate(angles, a);
- AngleVectors(a, forward, right, up);
-
- VectorCopy(trace->plane.normal, temp);
- trace->plane.normal[0] = DotProduct(temp, forward);
- trace->plane.normal[1] = -DotProduct(temp, right);
- trace->plane.normal[2] = DotProduct(temp, up);
+ TransposeAxis(axis);
+ RotatePoint(trace->plane.normal, axis);
}
- trace->endpos[0] = start[0] + trace->fraction * (end[0] - start[0]);
- trace->endpos[1] = start[1] + trace->fraction * (end[1] - start[1]);
- trace->endpos[2] = start[2] + trace->fraction * (end[2] - start[2]);
+ // FIXME: offset plane distance?
+
+ LerpVector(start, end, trace->fraction, trace->endpos);
}
void CM_ClipEntity(trace_t *dst, const trace_t *src, struct edict_s *ent)