1
0
Fork 0

Spectre/Math: Adding Vector2UnProject()

This commit is contained in:
Henrik Hautakoski 2023-08-21 07:05:34 +02:00
parent 813c0dab17
commit 416a71f744
2 changed files with 16 additions and 0 deletions

View file

@ -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);