| 101 | } |
| 102 | |
| 103 | void pvDecompress(Fvector& vec, u16 mVec) |
| 104 | { |
| 105 | // if we do a straightforward backward transform |
| 106 | // we will get points on the plane X0,Y0,Z0 |
| 107 | // however we need points on a sphere that goes through these points. |
| 108 | // therefore we need to adjust x,y,z so that x^2+y^2+z^2=1 |
| 109 | |
| 110 | // by normalizing the vector3. We have already precalculated the amount |
| 111 | // by which we need to scale, so all we do is a table lookup and a |
| 112 | // multiplication |
| 113 | |
| 114 | // get the x and y bits |
| 115 | int xbits = ((mVec & pvTOP_MASK) >> 7); |
| 116 | int ybits = (mVec & pvBOTTOM_MASK); |
| 117 | |
| 118 | // map the numbers back to the triangle (0,0)-(0,126)-(126,0) |
| 119 | if ((xbits + ybits) >= 127) |
| 120 | { |
| 121 | xbits = 127 - xbits; |
| 122 | ybits = 127 - ybits; |
| 123 | } |
| 124 | |
| 125 | // do the inverse transform and normalization |
| 126 | // costs 3 extra multiplies and 2 subtracts. No big deal. |
| 127 | float uvadj = pvUVAdjustment[mVec & ~pvSIGN_MASK]; |
| 128 | vec.x = uvadj * float(xbits); |
| 129 | vec.y = uvadj * float(ybits); |
| 130 | vec.z = uvadj * float(126 - xbits - ybits); |
| 131 | |
| 132 | // set all the sign bits |
| 133 | if (mVec & pvXSIGN_MASK) |
| 134 | set_negative(vec.x); |
| 135 | if (mVec & pvYSIGN_MASK) |
| 136 | set_negative(vec.y); |
| 137 | if (mVec & pvZSIGN_MASK) |
| 138 | set_negative(vec.z); |
| 139 | } |
no test coverage detected