Kaynağa Gözat

Add more vector sub overloads

Kajetan Johannes Hammerle 1 ay önce
ebeveyn
işleme
1bd8ab5ca0
1 değiştirilmiş dosya ile 26 ekleme ve 14 silme
  1. 26 14
      include/core/Vector.h

+ 26 - 14
include/core/Vector.h

@@ -6,23 +6,35 @@
 #define VECTOR_OP2(name) name *r, const name *a
 #define VECTOR_OP3(name) VECTOR_OP2(name), const name* b
 
-#define VECTOR_ARG_Z2(type)
-#define VECTOR_ARG_Z3(type) type z;
-#define VECTOR_ARG_Z4(type) type z;
-
-#define VECTOR_ARG_W2(type)
-#define VECTOR_ARG_W3(type)
-#define VECTOR_ARG_W4(type) type w;
-
-#define DEFINE_VECTOR(N, name, sname, type)                                    \
+#define VECTOR_TYPE(type, Type)                                                \
+    typedef union {                                                            \
+        type data[2];                                                          \
+        struct {                                                               \
+            type x, y;                                                         \
+        };                                                                     \
+    } Type##2;                                                                 \
+    typedef union {                                                            \
+        type data[3];                                                          \
+        struct {                                                               \
+            type x, y, z;                                                      \
+        };                                                                     \
+        Type##2 xy;                                                            \
+    } Type##3;                                                                 \
     typedef union {                                                            \
-        type data[N];                                                          \
+        type data[4];                                                          \
+        struct {                                                               \
+            type x, y, z, w;                                                   \
+        };                                                                     \
         struct {                                                               \
-            type x;                                                            \
-            type y;                                                            \
-            VECTOR_ARG_Z##N(type) VECTOR_ARG_W##N(type)                        \
+            Type##2 xy, zw;                                                    \
         };                                                                     \
-    } name;                                                                    \
+        Type##3 xyz;                                                           \
+    } Type##4
+
+VECTOR_TYPE(float, Vector);
+VECTOR_TYPE(int, IntVector);
+
+#define DEFINE_VECTOR(N, name, sname, type)                                    \
     name* addSet##sname(VECTOR_OP2(name));                                     \
     name* add##sname(VECTOR_OP3(name));                                        \
     name* subSet##sname(VECTOR_OP2(name));                                     \