| 1173 | } |
| 1174 | |
| 1175 | void GenerateMatrixUsingVector(EERIEMATRIX * matrix, const EERIE_3D * vect, const float rollDegrees) |
| 1176 | { |
| 1177 | // Get our direction vector (the Z vector component of the matrix) |
| 1178 | // and make sure it's normalized into a unit vector |
| 1179 | EERIE_3D zAxis; |
| 1180 | memcpy(&zAxis, vect, sizeof(EERIE_3D)); |
| 1181 | TRUEVector_Normalize(&zAxis); |
| 1182 | |
| 1183 | // Build the Y vector of the matrix (handle the degenerate case |
| 1184 | // in the way that 3DS does) -- This is not the TRUE vector, only |
| 1185 | // a reference vector. |
| 1186 | EERIE_3D yAxis; |
| 1187 | |
| 1188 | if (!zAxis.x && !zAxis.z) |
| 1189 | Vinit(&yAxis, -zAxis.y, 0.f, 0.f); |
| 1190 | else |
| 1191 | Vinit(&yAxis, 0.f, 1.f, 0.f); |
| 1192 | |
| 1193 | // Build the X axis vector based on the two existing vectors |
| 1194 | EERIE_3D xAxis; |
| 1195 | Vcross(&xAxis, &yAxis, &zAxis); |
| 1196 | TRUEVector_Normalize(&xAxis); |
| 1197 | |
| 1198 | // Correct the Y reference vector |
| 1199 | Vcross(&yAxis, &xAxis, &zAxis); |
| 1200 | TRUEVector_Normalize(&yAxis); |
| 1201 | yAxis.x = -yAxis.x; |
| 1202 | yAxis.y = -yAxis.y; |
| 1203 | yAxis.z = -yAxis.z; |
| 1204 | |
| 1205 | // Generate rotation matrix without roll included |
| 1206 | EERIEMATRIX rot, roll; |
| 1207 | MatrixReset(&rot); |
| 1208 | MatrixReset(&roll); |
| 1209 | rot._11 = yAxis.x; |
| 1210 | rot._12 = yAxis.y; |
| 1211 | rot._13 = yAxis.z; |
| 1212 | rot._21 = zAxis.x; |
| 1213 | rot._22 = zAxis.y; |
| 1214 | rot._23 = zAxis.z; |
| 1215 | rot._31 = xAxis.x; |
| 1216 | rot._32 = xAxis.y; |
| 1217 | rot._33 = xAxis.z; |
| 1218 | |
| 1219 | // Generate the Z rotation matrix for roll |
| 1220 | roll._33 = 1.f; |
| 1221 | roll._44 = 1.f; |
| 1222 | roll._11 = EEcos(DEG2RAD(rollDegrees)); |
| 1223 | roll._12 = -EEsin(DEG2RAD(rollDegrees)); |
| 1224 | roll._21 = EEsin(DEG2RAD(rollDegrees)); |
| 1225 | roll._22 = EEcos(DEG2RAD(rollDegrees)); |
| 1226 | |
| 1227 | // Concatinate them for a complete rotation matrix that includes |
| 1228 | // all rotations |
| 1229 | MatrixMultiply(matrix, &rot, &roll); |
| 1230 | } |
| 1231 | |
| 1232 |
no test coverage detected