summaryrefslogtreecommitdiff
path: root/maths.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'maths.cpp')
-rw-r--r--maths.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/maths.cpp b/maths.cpp
index 39a1163..bdda15b 100644
--- a/maths.cpp
+++ b/maths.cpp
@@ -2,6 +2,15 @@
#include <algorithm>
+void AABB::encompass(const AABB& other) {
+ min.x = std::min(min.x, other.min.x);
+ min.y = std::min(min.y, other.min.y);
+ min.z = std::min(min.z, other.min.z);
+ max.x = std::max(max.x, other.max.x);
+ max.y = std::max(max.y, other.max.y);
+ max.z = std::max(max.z, other.max.z);
+}
+
namespace quat {
v4f identity() {
return v4f(0.0f, 0.0f, 0.0f, 1.0f);
@@ -285,19 +294,12 @@ m4f m4f::pers(float fov, float asp, float n, float f) {
m4f m4f::orth(float l, float r, float b, float t, float n, float f) {
m4f res(1.0f);
- float* data = (float*)res.m;
-
- float lr = 1.0f / (l - r);
- float bt = 1.0f / (b - t);
- float nf = 1.0f / (n - f);
-
- data[0] = -2.0f * lr;
- data[5] = -2.0f * bt;
- data[10] = 2.0f * nf;
-
- data[12] = (l + r) * lr;
- data[13] = (t + b) * bt;
- data[14] = (f + n) * nf;
+ res.m[0][0] = 2.0f / (r - l);
+ res.m[1][1] = 2.0f / (b - t);
+ res.m[2][2] = 1.0f / (n - f);
+ res.m[3][0] = -(l + r) / (r - l);
+ res.m[3][1] = -(b + t) / (b - t);
+ res.m[3][2] = n / (n - f);
return res;
}