[3107] | 1 | #include "SimpleVec.h"
|
---|
| 2 | #include <float.h>
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | // Given min a vector to minimize and a candidate vector, replace
|
---|
| 7 | // elements of min whose corresponding elements in Candidate are
|
---|
| 8 | // smaller. This function is used for finding objects' bounds,
|
---|
| 9 | // among other things.
|
---|
| 10 | void Minimize(SimpleVec &min, const SimpleVec &Candidate)
|
---|
| 11 | {
|
---|
| 12 | if (Candidate.x < min.x)
|
---|
| 13 | min.x = Candidate.x;
|
---|
| 14 | if (Candidate.y < min.y)
|
---|
| 15 | min.y = Candidate.y;
|
---|
| 16 | if (Candidate.z < min.z)
|
---|
| 17 | min.z = Candidate.z;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | // Given min a vector to minimize and a candidate vector, replace
|
---|
| 21 | // elements of min whose corresponding elements in Candidate are
|
---|
| 22 | // larger. This function is used for finding objects' bounds,
|
---|
| 23 | // among other things.
|
---|
| 24 | void Maximize(SimpleVec &max, const SimpleVec &Candidate)
|
---|
| 25 | {
|
---|
| 26 | if (Candidate.x > max.x)
|
---|
| 27 | max.x = Candidate.x;
|
---|
| 28 | if (Candidate.y > max.y)
|
---|
| 29 | max.y = Candidate.y;
|
---|
| 30 | if (Candidate.z > max.z)
|
---|
| 31 | max.z = Candidate.z;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | // Project the vector onto the YZ, XZ, or XY plane depending on which.
|
---|
| 35 | // which Coordinate plane to project onto
|
---|
| 36 | // 0 YZ
|
---|
| 37 | // 1 XZ
|
---|
| 38 | // 2 XY
|
---|
| 39 | // This function is used by the polygon intersection code.
|
---|
| 40 |
|
---|
| 41 | void SimpleVec::ExtractVerts(float *px, float *py, int which) const
|
---|
| 42 | {
|
---|
| 43 | switch (which) {
|
---|
| 44 | case 0:
|
---|
| 45 | *px = y;
|
---|
| 46 | *py = z;
|
---|
| 47 | break;
|
---|
| 48 | case 1:
|
---|
| 49 | *px = x;
|
---|
| 50 | *py = z;
|
---|
| 51 | break;
|
---|
| 52 | case 2:
|
---|
| 53 | *px = x;
|
---|
| 54 | *py = y;
|
---|
| 55 | break;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | // returns the axis, where the vector has the largest value
|
---|
| 60 | int
|
---|
| 61 | SimpleVec::DrivingAxis(void) const
|
---|
| 62 | {
|
---|
| 63 | int axis = 0;
|
---|
| 64 | float val = fabs(x);
|
---|
| 65 |
|
---|
| 66 | if (fabs(y) > val) {
|
---|
| 67 | val = fabs(y);
|
---|
| 68 | axis = 1;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | if (fabs(z) > val)
|
---|
| 72 | axis = 2;
|
---|
| 73 |
|
---|
| 74 | return axis;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | // returns the axis, where the vector has the smallest value
|
---|
| 79 | int SimpleVec::TinyAxis(void) const
|
---|
| 80 | {
|
---|
| 81 | int axis = 0;
|
---|
| 82 | float val = fabs(x);
|
---|
| 83 |
|
---|
| 84 | if (fabs(y) < val) {
|
---|
| 85 | val = fabs(y);
|
---|
| 86 | axis = 1;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | if (fabs(z) < val)
|
---|
| 90 | axis = 2;
|
---|
| 91 |
|
---|
| 92 | return axis;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | bool SimpleVec::CheckValidity() const
|
---|
| 97 | {
|
---|
| 98 | #ifdef _WIN32
|
---|
| 99 | return !(_isnan(x) || _isnan(y) || _isnan(z));
|
---|
| 100 | #else
|
---|
| 101 | return !(isnan(x) || isnan(y) || isnan(z));
|
---|
| 102 | #endif
|
---|
| 103 | }
|
---|