fix mouse picking
This commit is contained in:
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user