summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-03-27 17:20:21 +0100
committerGitHub <[email protected]>2020-03-27 17:20:21 +0100
commit4631dd44685b84634455e1bfb5f4fee8177468ea (patch)
tree0d4ac758717407c041c7bc0e2061e2e2de9b2bc5
parentee7dec6e6aec1c3093bccf637ab6a71b8412ba7b (diff)
downloadSTC-modified-4631dd44685b84634455e1bfb5f4fee8177468ea.tar.gz
STC-modified-4631dd44685b84634455e1bfb5f4fee8177468ea.zip
Add files via upload
-rw-r--r--c_lib/cvec3.h21
1 files changed, 10 insertions, 11 deletions
diff --git a/c_lib/cvec3.h b/c_lib/cvec3.h
index 1197998f..c70ab894 100644
--- a/c_lib/cvec3.h
+++ b/c_lib/cvec3.h
@@ -27,8 +27,7 @@
#include <stdbool.h>
#include <math.h>
-#define cvec3_initializer {0, 0, 0}
-#define cvec3_data(v) (&(v).x)
+#define cvec3_data(v) (&(v).x)
#define declare_CVec3(tag, T) \
typedef struct CVec3##tag { T x, y, z; } CVec3##tag; \
@@ -61,23 +60,23 @@
return _cvec3_DOT(v, v); \
} \
static inline CVec3##tag cvec3##tag##_plus(CVec3##tag u, CVec3##tag v) { \
- CVec3##tag w = {u.x + v.x, u.y + v.y, u.z + v.z}; return w; \
+ u.x += v.x, u.y += v.y, u.z += v.z; return u; \
} \
static inline CVec3##tag cvec3##tag##_minus(CVec3##tag u, CVec3##tag v) { \
- CVec3##tag w = {u.x - v.x, u.y - v.y, u.z - v.z}; return w; \
+ u.x -= v.x, u.y -= v.y, u.z -= v.z; return u; \
} \
static inline CVec3##tag cvec3##tag##_mult(CVec3##tag v, double s) { \
- CVec3##tag w = {(T)(v.x*s), (T)(v.y*s), (T)(v.z*s)}; return w; \
+ v.x = (T)(s*v.x), v.y = (T)(s*v.y), v.z = (T)(s*v.z); return v; \
+ } \
+ static inline CVec3##tag cvec3##tag##_multInverse(CVec3##tag v, double s) { \
+ v.x = (T)(s/v.x), v.y = (T)(s/v.y), v.z = (T)(s/v.z); return v; \
} \
static inline CVec3##tag cvec3##tag##_neg(CVec3##tag v) { \
- CVec3##tag w = {-v.x, -v.y, -v.z}; return w; \
+ v.x = -v.x, v.y = -v.y, v.z = -v.z; return v; \
} \
static inline CVec3##tag cvec3##tag##_unit(CVec3##tag v) { \
- double s = 1.0 / cvec3##tag##_length(v); \
- CVec3##tag w = {(T)(v.x*s), (T)(v.y*s), (T)(v.z*s)}; return w; \
- } \
- static inline CVec3##tag cvec3##tag##_multInverse(CVec3##tag v, double s) { \
- CVec3##tag w = {(T)(s/v.x), (T)(s/v.y), (T)(s/v.z)}; return w; \
+ double s = 1.0 / sqrt(_cvec3_DOT(v, v)); \
+ v.x = (T)(v.x*s), v.y = (T)(v.y*s), v.z = (T)(v.z*s); return v; \
} \
static inline double cvec3##tag##_dot(CVec3##tag u, CVec3##tag v) { \
return _cvec3_DOT(u, v); \