aboutsummaryrefslogtreecommitdiff
path: root/ctranslate.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-03-26 21:47:51 +0100
committerJulian T <julian@jtle.dk>2020-03-26 21:47:51 +0100
commita9651189ac52139c374f97a311d090a8d95b957e (patch)
treefc6fd39fd4bcb4afd0214f145bd287958cf88618 /ctranslate.c
parentcdfd399ea9d79dcfac3107b23cbab7b25c7a12e0 (diff)
MOved hemisphere transformation stuff out of ray.c
Diffstat (limited to 'ctranslate.c')
-rw-r--r--ctranslate.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/ctranslate.c b/ctranslate.c
new file mode 100644
index 0000000..f7dfe64
--- /dev/null
+++ b/ctranslate.c
@@ -0,0 +1,41 @@
+#include "ctranslate.h"
+
+#include <math.h>
+
+// TODO remove dublicate pi definitions
+#define PI 3.14159265359
+
+void csystem_init(csystem_t *cs, vector_t *up)
+{
+ cs->up = up;
+
+ // Create new coordinate system where N is up. To do this we need two more vectors for the other axises.
+ // Create the 2. by setting x or y to 0
+ if (up->x > up->y) {
+ vector_set(&cs->ax, up->z, 0, -up->x);
+ } else {
+ vector_set(&cs->ax, 0, -up->z, up->y);
+ }
+ // Normalice
+ vector_scale_inv(&cs->ax, &cs->ax, vector_len(&cs->ax));
+
+ // Create the 3. axis by taking the cross of the other
+ vector_cross(&cs->az, up, &cs->ax);
+}
+
+void csystem_calc_real(csystem_t *cs, vector_t *inside, vector_t *real)
+{
+ vector_set(real, inside->x * cs->ax.x + inside->y * cs->up->x + inside->z * cs->az.x,
+ inside->x * cs->ax.y + inside->y * cs->up->y + inside->z * cs->az.y,
+ inside->x * cs->ax.z + inside->y * cs->up->z + inside->z * cs->az.z);
+}
+
+void csystem_hemisphere_random(csystem_t *cs, COORD_T r1, COORD_T r2, vector_t *out)
+{
+ COORD_T sinTheta = sqrt(1 - r1 * r1);
+ COORD_T phi = 2 * PI * r2;
+
+ // Calculate the random direction vector
+ vector_set(out, sinTheta * cos(phi), r1, sinTheta * sin(phi));
+}
+