Browse Source

Allow box array access and use it

Kajetan Johannes Hammerle 1 month ago
parent
commit
02b8906525
2 changed files with 7 additions and 8 deletions
  1. 6 3
      include/core/Box.h
  2. 1 5
      src/Box.c

+ 6 - 3
include/core/Box.h

@@ -3,9 +3,12 @@
 
 #include "core/Vector.h"
 
-typedef struct {
-    Vector3 min;
-    Vector3 max;
+typedef union {
+    struct {
+        Vector3 min;
+        Vector3 max;
+    };
+    Vector3 v[2];
 } Box;
 
 #define BOX ((Box){0})

+ 1 - 5
src/Box.c

@@ -28,11 +28,7 @@ bool collidesWithBox(const Box* box, const Box* other) {
 
 void expandBox(Box* box, const Vector3* offset) {
     for(size_t i = 0; i < 3; i++) {
-        if(offset->data[i] > 0.0f) {
-            box->max.data[i] += offset->data[i];
-        } else {
-            box->min.data[i] += offset->data[i];
-        }
+        box->v[offset->data[i] > 0.0f].data[i] += offset->data[i];
     }
 }