CM_TransformedBoxTrace handles offseting and rotation of the end points for moving and rotating entities.
(float[] start, float[] end,
float[] mins, float[] maxs, int headnode, int brushmask,
float[] origin, float[] angles)
| 1480 | * entities. |
| 1481 | */ |
| 1482 | public trace_t TransformedBoxTrace(float[] start, float[] end, |
| 1483 | float[] mins, float[] maxs, int headnode, int brushmask, |
| 1484 | float[] origin, float[] angles) { |
| 1485 | trace_t trace; |
| 1486 | float[] start_l = { 0, 0, 0 }, end_l = { 0, 0, 0 }; |
| 1487 | float[] a = { 0, 0, 0 }; |
| 1488 | float[] forward = { 0, 0, 0 }, right = { 0, 0, 0 }, up = { 0, 0, 0 }; |
| 1489 | float[] temp = { 0, 0, 0 }; |
| 1490 | boolean rotated; |
| 1491 | |
| 1492 | // subtract origin offset |
| 1493 | Math3D.VectorSubtract(start, origin, start_l); |
| 1494 | Math3D.VectorSubtract(end, origin, end_l); |
| 1495 | |
| 1496 | // rotate start and end into the models frame of reference |
| 1497 | if (headnode != box_headnode |
| 1498 | && (angles[0] != 0 || angles[1] != 0 || angles[2] != 0)) |
| 1499 | rotated = true; |
| 1500 | else |
| 1501 | rotated = false; |
| 1502 | |
| 1503 | if (rotated) { |
| 1504 | Math3D.AngleVectors(angles, forward, right, up); |
| 1505 | |
| 1506 | Math3D.VectorCopy(start_l, temp); |
| 1507 | start_l[0] = Math3D.DotProduct(temp, forward); |
| 1508 | start_l[1] = -Math3D.DotProduct(temp, right); |
| 1509 | start_l[2] = Math3D.DotProduct(temp, up); |
| 1510 | |
| 1511 | Math3D.VectorCopy(end_l, temp); |
| 1512 | end_l[0] = Math3D.DotProduct(temp, forward); |
| 1513 | end_l[1] = -Math3D.DotProduct(temp, right); |
| 1514 | end_l[2] = Math3D.DotProduct(temp, up); |
| 1515 | } |
| 1516 | |
| 1517 | // sweep the box through the model |
| 1518 | trace = BoxTrace(start_l, end_l, mins, maxs, headnode, brushmask); |
| 1519 | |
| 1520 | if (rotated && trace.fraction != 1.0) { |
| 1521 | // FIXME: figure out how to do this with existing angles |
| 1522 | Math3D.VectorNegate(angles, a); |
| 1523 | Math3D.AngleVectors(a, forward, right, up); |
| 1524 | |
| 1525 | Math3D.VectorCopy(trace.plane.normal, temp); |
| 1526 | trace.plane.normal[0] = Math3D.DotProduct(temp, forward); |
| 1527 | trace.plane.normal[1] = -Math3D.DotProduct(temp, right); |
| 1528 | trace.plane.normal[2] = Math3D.DotProduct(temp, up); |
| 1529 | } |
| 1530 | |
| 1531 | trace.endpos[0] = start[0] + trace.fraction * (end[0] - start[0]); |
| 1532 | trace.endpos[1] = start[1] + trace.fraction * (end[1] - start[1]); |
| 1533 | trace.endpos[2] = start[2] + trace.fraction * (end[2] - start[2]); |
| 1534 | |
| 1535 | return trace; |
| 1536 | } |
| 1537 | |
| 1538 | /* |
| 1539 | * =============================================================================== |
no test coverage detected