summaryrefslogtreecommitdiff
path: root/modules/ray/ray_euler.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2016-12-13 07:57:56 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2016-12-13 08:01:22 -0800
commit8340e615d46615894b44b4ffce5dc2dd86cbad40 (patch)
treeca9f82767d360f03e09425f21e35d0188eb52d1c /modules/ray/ray_euler.h
parent8add1663d9a02db2bc65224cdceb480733a81379 (diff)
ray: introduce a rudimentary ray tracer
My first ray tracer, it only has spheres, planes, and point light sources. No texture mapping, no soft shadows, no global illumination. This is all very basic right now, the camera movement is simple and boring, but sufficient for further development and optimization. I made some effort to support multiple CPUs, it should detect the number of CPUs in the system and use enough pthreads to keep them busy. Jacco Bikker's tutorial on flipcode was the original impetus to do this, and definitely served as a guide early on.
Diffstat (limited to 'modules/ray/ray_euler.h')
-rw-r--r--modules/ray/ray_euler.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/modules/ray/ray_euler.h b/modules/ray/ray_euler.h
new file mode 100644
index 0000000..86f5221
--- /dev/null
+++ b/modules/ray/ray_euler.h
@@ -0,0 +1,45 @@
+#ifndef _RAY_EULER_H
+#define _RAY_EULER_H
+
+#include <math.h>
+
+#include "ray_3f.h"
+
+
+/* euler angles are convenient for describing orientation */
+typedef struct ray_euler_t {
+ float pitch; /* pitch in radiasn */
+ float yaw; /* yaw in radians */
+ float roll; /* roll in radians */
+} ray_euler_t;
+
+
+/* convenience macro for converting degrees to radians */
+#define RAY_EULER_DEGREES(_deg) \
+ (_deg * (2 * M_PI / 360.0f))
+
+
+/* produce basis vectors from euler angles */
+static inline void ray_euler_basis(ray_euler_t *e, ray_3f_t *forward, ray_3f_t *up, ray_3f_t *left)
+{
+ float cos_yaw = cosf(e->yaw);
+ float sin_yaw = sinf(e->yaw);
+ float cos_roll = cosf(e->roll);
+ float sin_roll = sinf(e->roll);
+ float cos_pitch = cosf(e->pitch);
+ float sin_pitch = sinf(e->pitch);
+
+ forward->x = sin_yaw;
+ forward->y = -sin_pitch * cos_yaw;
+ forward->z = cos_pitch * cos_yaw;
+
+ up->x = -cos_yaw * sin_roll;
+ up->y = -sin_pitch * sin_yaw * sin_roll + cos_pitch * cos_roll;
+ up->z = cos_pitch * sin_yaw * sin_roll + sin_pitch * cos_roll;
+
+ left->x = cos_yaw * cos_roll;
+ left->y = sin_pitch * sin_yaw * cos_roll + cos_pitch * sin_roll;
+ left->z = -cos_pitch * sin_yaw * cos_roll + sin_pitch * sin_roll;
+}
+
+#endif
© All Rights Reserved