Explorar o código

Allow box array access and use it

Kajetan Johannes Hammerle hai 1 mes
pai
achega
02b8906525
Modificáronse 2 ficheiros con 7 adicións e 8 borrados
  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];
     }
 }