| 381 | } |
| 382 | |
| 383 | olc::GFX3D::mat4x4 olc::GFX3D::Math::Mat_PointAt(olc::GFX3D::vec3d &pos, olc::GFX3D::vec3d &target, olc::GFX3D::vec3d &up) |
| 384 | { |
| 385 | // Calculate new forward direction |
| 386 | olc::GFX3D::vec3d newForward = Vec_Sub(target, pos); |
| 387 | newForward = Vec_Normalise(newForward); |
| 388 | |
| 389 | // Calculate new Up direction |
| 390 | olc::GFX3D::vec3d a = Vec_Mul(newForward, Vec_DotProduct(up, newForward)); |
| 391 | olc::GFX3D::vec3d newUp = Vec_Sub(up, a); |
| 392 | newUp = Vec_Normalise(newUp); |
| 393 | |
| 394 | // New Right direction is easy, its just cross product |
| 395 | olc::GFX3D::vec3d newRight = Vec_CrossProduct(newUp, newForward); |
| 396 | |
| 397 | // Construct Dimensioning and Translation Matrix |
| 398 | olc::GFX3D::mat4x4 matrix; |
| 399 | matrix.m[0][0] = newRight.x; matrix.m[0][1] = newRight.y; matrix.m[0][2] = newRight.z; matrix.m[0][3] = 0.0f; |
| 400 | matrix.m[1][0] = newUp.x; matrix.m[1][1] = newUp.y; matrix.m[1][2] = newUp.z; matrix.m[1][3] = 0.0f; |
| 401 | matrix.m[2][0] = newForward.x; matrix.m[2][1] = newForward.y; matrix.m[2][2] = newForward.z; matrix.m[2][3] = 0.0f; |
| 402 | matrix.m[3][0] = pos.x; matrix.m[3][1] = pos.y; matrix.m[3][2] = pos.z; matrix.m[3][3] = 1.0f; |
| 403 | return matrix; |
| 404 | |
| 405 | } |
| 406 | |
| 407 | olc::GFX3D::mat4x4 olc::GFX3D::Math::Mat_QuickInverse(olc::GFX3D::mat4x4 &m) // Only for Rotation/Translation Matrices |
| 408 | { |
nothing calls this directly
no outgoing calls
no test coverage detected