Normalize a vector. Returns: the magnitude before normalization
| 272 | // Normalize a vector. |
| 273 | // Returns: the magnitude before normalization |
| 274 | float vm_NormalizeVector(vector *a) { |
| 275 | float mag; |
| 276 | |
| 277 | mag = vm_GetMagnitude(a); |
| 278 | |
| 279 | if (mag > 0) |
| 280 | *a /= mag; |
| 281 | else { |
| 282 | *a = Zero_vector; |
| 283 | a->x = 1.0; |
| 284 | mag = 0.0f; |
| 285 | } |
| 286 | |
| 287 | return mag; |
| 288 | } |
| 289 | |
| 290 | float vm_GetMagnitude(vector *a) { |
| 291 | float f; |
no test coverage detected