Spectre/Math: Adding Vector2UnProject()
This commit is contained in:
parent
813c0dab17
commit
416a71f744
2 changed files with 16 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <Spectre/Math/Transform.h>
|
||||
#include <Spectre/Math/Math.h>
|
||||
|
||||
namespace sp { namespace math
|
||||
|
|
@ -47,6 +48,16 @@ namespace sp { namespace math
|
|||
);
|
||||
}
|
||||
|
||||
Vector2f Vector2UnProject(Vector2f point, Transform InverseMVP, Vector4u screen) {
|
||||
|
||||
// Convert to NDC from pixel cordinates first using screen size
|
||||
point.x = -1.f + 2.f * (point.x - screen.x) / screen.z;
|
||||
point.y = 1.f - 2.f * (point.y - screen.y) / screen.w;
|
||||
|
||||
// Then transform the point using the inverse MVP matrix.
|
||||
return InverseMVP.transformPoint(point);
|
||||
}
|
||||
|
||||
Matrix4f rotation(float theta) {
|
||||
|
||||
float r = deg2rad(theta);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue