tadd vector math definitions - slidergrid - grid of elastic sliders on a fricti… | |
git clone git://src.adamsgaard.dk/slidergrid | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit b6375bd6ba85b2129dcc4e88057883d4f6c9f458 | |
parent cc654a7b73a8bdb1f7771af8e6aa946262d7e0bd | |
Author: Anders Damsgaard <[email protected]> | |
Date: Tue, 15 Mar 2016 13:20:40 -0700 | |
add vector math definitions | |
Diffstat: | |
M Makefile | 2 +- | |
M slider.c | 18 +++++++++++++++++- | |
M slider.h | 10 ++++++---- | |
M typedefs.h | 4 ++-- | |
A vector_math.c | 27 +++++++++++++++++++++++++++ | |
A vector_math.h | 4 ++++ | |
6 files changed, 57 insertions(+), 8 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
t@@ -3,7 +3,7 @@ CFLAGS=-Wall -O3 -g -pg | |
LDLIBS=-lm | |
BIN=slidergrid | |
-$(BIN): main.o slider.o grid.o | |
+$(BIN): main.o slider.o grid.o vector_math.o | |
$(CC) $(LDLIBS) $^ -o $@ | |
profile: $(BIN) | |
diff --git a/slider.c b/slider.c | |
t@@ -1,7 +1,23 @@ | |
#include <stdio.h> | |
+#include "typedefs.h" | |
#include "slider.h" | |
+#include "vector_math.h" | |
void print_slider_position(slider s) | |
{ | |
printf("%f\t%f\t%f\n", s.pos.x, s.pos.y, s.pos.z); | |
-}; | |
+} | |
+ | |
+void integrate_kinematics(slider s, Float dt, int iteration) | |
+{ | |
+ | |
+ | |
+ | |
+ if (iteration == 0) { | |
+ Float3 acc0 = make_float3(0., 0., 0.); | |
+ } | |
+ | |
+ | |
+ | |
+ | |
+} | |
diff --git a/slider.h b/slider.h | |
t@@ -4,10 +4,10 @@ | |
#include "typedefs.h" | |
typedef struct { | |
- v3 pos; // spatial position | |
- v3 vel; // spatial velocity | |
- v3 acc; // spatial acceleration | |
- v3 force; // sum of forces | |
+ Float3 pos; // spatial position | |
+ Float3 vel; // spatial velocity | |
+ Float3 acc; // spatial acceleration | |
+ Float3 force; // sum of forces | |
Float bulk_modulus; // elastic compressibility | |
int neighbors[]; // indexes of sliders this one is bonded to | |
} slider; | |
t@@ -15,4 +15,6 @@ typedef struct { | |
void print_slider_position(slider s); | |
+void integrate_kinematics(slider s, Float dt, int iteration); | |
+ | |
#endif | |
diff --git a/typedefs.h b/typedefs.h | |
t@@ -5,11 +5,11 @@ | |
//typedef float Float; | |
typedef double Float; | |
- | |
+// 3-dimensional vector | |
typedef struct { | |
Float x; | |
Float y; | |
Float z; | |
-} v3; | |
+} Float3; | |
#endif | |
diff --git a/vector_math.c b/vector_math.c | |
t@@ -0,0 +1,27 @@ | |
+#include "typedefs.h" | |
+ | |
+inline Float3 make_float3(Float x, Float y, Float z) | |
+{ | |
+ Float3 v = {.x = x, .y = y, .z = z}; | |
+ return v; | |
+} | |
+ | |
+inline Float3 add_float3(Float3 v1, Float3 v2) | |
+{ | |
+ return make_float3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); | |
+} | |
+ | |
+inline Float3 subtract_float3(Float3 v1, Float3 v2) | |
+{ | |
+ return make_float3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); | |
+} | |
+ | |
+inline Float3 multiply_float3(Float3 v1, Float3 v2) | |
+{ | |
+ return make_float3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); | |
+} | |
+ | |
+inline Float3 divide_float3(Float3 v1, Float3 v2) | |
+{ | |
+ return make_float3(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z); | |
+} | |
diff --git a/vector_math.h b/vector_math.h | |
t@@ -0,0 +1,4 @@ | |
+#include "typedefs.h" | |
+ | |
+inline Float3 make_float3(Float x, Float y, Float z); | |
+ |