fix mouse picking
This commit is contained in:
@@ -114,6 +114,14 @@ struct Mat4 {
|
||||
return reinterpret_cast<T*>(this)[offset];
|
||||
}
|
||||
|
||||
T* data() {
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T* data() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
T at(std::size_t row, std::size_t column) const {
|
||||
return operator[](row * MATRIX_SIZE + column);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,11 @@ namespace maths {
|
||||
// Vectors //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
Vec2<T> operator+(const Vec2<T>& vect, const Vec2<T>& other) {
|
||||
return {vect.x + other.x, vect.y + other.y};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vec3<T> operator- (const Vec3<T>& vect) {
|
||||
return { -vect.x, -vect.y, -vect.z };
|
||||
@@ -32,6 +37,13 @@ Vec3<T> Normalize(const Vec3<T>& vect) {
|
||||
return { vect.x / length, vect.y / length, vect.z / length };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vec4<T> Normalize(const Vec4<T>& vect) {
|
||||
T length = std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z + vect.w * vect.w);
|
||||
|
||||
return { vect.x / length, vect.y / length, vect.z / length, vect.w / length };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Dot(const Vec3<T>& vect, const Vec3<T>& other) {
|
||||
return vect.x * other.x + vect.y * other.y + vect.z * other.z;
|
||||
@@ -59,9 +71,9 @@ template<typename T>
|
||||
Vec4<T> Dot(const Mat4<T>& mat, const Vec4<T>& vect) {
|
||||
return {
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(&mat), vect),
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(&mat[Mat4<T>::MATRIX_SIZE]), vect),
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(&mat[2 * Mat4<T>::MATRIX_SIZE]), vect),
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(&mat[3 * Mat4<T>::MATRIX_SIZE]), vect),
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(mat.data() + Mat4<T>::MATRIX_SIZE), vect),
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(mat.data() + 2 * Mat4<T>::MATRIX_SIZE), vect),
|
||||
Dot(*reinterpret_cast<const Vec4<T>*>(mat.data() + 3 * Mat4<T>::MATRIX_SIZE), vect),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,15 @@
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
struct Camera {
|
||||
Mat4f viewMatrix;
|
||||
Mat4f projectionMatrix;
|
||||
Mat4f InvViewMatrix;
|
||||
Mat4f InvProjectionMatrix;
|
||||
|
||||
Vec3f CamPos;
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
static constexpr float m_AnimationSpeed = 2.0f;
|
||||
@@ -24,9 +33,7 @@ private:
|
||||
|
||||
Vec3f m_BackgroundColor;
|
||||
|
||||
bool m_IsometricView = true;
|
||||
float m_IsometricShade = m_IsometricView;
|
||||
Vec2f m_CamPos{};
|
||||
Camera m_Camera {};
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
@@ -41,15 +48,12 @@ public:
|
||||
|
||||
void SetZoom(float zoom);
|
||||
void SetCamMovement(const Vec2f& mov);
|
||||
void SetCamPos(const Vec2f& newPos);
|
||||
void SetIsometricView(bool isometric); // false = 2D true = Isometric
|
||||
void SetCamPos(const Vec3f& newPos);
|
||||
|
||||
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
||||
|
||||
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
|
||||
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight);
|
||||
private:
|
||||
void UpdateIsometricView();
|
||||
void UpdateIsometricFade();
|
||||
void InitShaders();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user