Spectre/Math: Adding Vector2UnProject()
This commit is contained in:
parent
813c0dab17
commit
416a71f744
2 changed files with 16 additions and 0 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
#ifndef SPECTRE_MATH_MATH_H
|
#ifndef SPECTRE_MATH_MATH_H
|
||||||
#define SPECTRE_MATH_MATH_H
|
#define SPECTRE_MATH_MATH_H
|
||||||
|
|
||||||
|
#include "Transform.h"
|
||||||
|
#include "Vector4.h"
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
#include "Vector2.h"
|
#include "Vector2.h"
|
||||||
#include "Matrix4.h"
|
#include "Matrix4.h"
|
||||||
|
|
@ -32,6 +34,9 @@ namespace sp { namespace math
|
||||||
float bottom, float top,
|
float bottom, float top,
|
||||||
float zNear = -1.0f, float zFar = 1.0f);
|
float zNear = -1.0f, float zFar = 1.0f);
|
||||||
|
|
||||||
|
//
|
||||||
|
Vector2f Vector2UnProject(Vector2f point, Transform InverseMVP, Vector4u screen);
|
||||||
|
|
||||||
// Create a 2D rotation matrix. (rotation around Z-axis)
|
// Create a 2D rotation matrix. (rotation around Z-axis)
|
||||||
Matrix4f rotation(float theta);
|
Matrix4f rotation(float theta);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <Spectre/Math/Transform.h>
|
||||||
#include <Spectre/Math/Math.h>
|
#include <Spectre/Math/Math.h>
|
||||||
|
|
||||||
namespace sp { namespace math
|
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) {
|
Matrix4f rotation(float theta) {
|
||||||
|
|
||||||
float r = deg2rad(theta);
|
float r = deg2rad(theta);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue