@@ 1,6 1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
+#include <pthread.h>
#define HEIGHT 50
#define WIDTH 100
@@ 80,8 81,8 @@ float opDisp(vec3 p, float amt) {
}
vec2 scene(vec3 position) {
- vec2 sphere = { sdSphere(position, 0.6f) + opDisp(position, 3.0f), 10.0f };
- vec2 plane = { sdPlane(position, 0.6f), 10.0f };
+ vec2 sphere = { sdSphere(position, 0.6f) + opDisp(position, 3.5f), 10.0f };
+ vec2 plane = { sdPlane(position, 0.8f), 10.0f };
return opUnion(plane, sphere);
}
@@ 105,15 106,50 @@ vec2 traceRay(vec3 origin, vec3 direction)
return (vec2){ t, material };
}
+vec3 cam;
+
+void input(void)
+{
+ // camera movement
+ while (1) {
+ char ch = fgetc(stdin);
+ switch(ch) {
+ case 'w':
+ cam.z -= 1.0f;
+ printf("\033[%dF\n", 1);
+ break;
+ case 's':
+ cam.z += 1.0f;
+ printf("\033[%dF\n", 1);
+ break;
+ case 'a':
+ cam.x -= 1.0f;
+ printf("\033[%dF\n", 1);
+ break;
+ case 'd':
+ cam.x += 1.0f;
+ printf("\033[%dF\n", 1);
+ break;
+ }
+ }
+}
+
int main(void)
{
- int i, j, n;
+ int i, j, n, err;
float time;
+ pthread_t thread;
// camera stuff
vec3 origin = { 0.0f, 0.0f, 0.0f };
vec3 target = { 0.0f, 0.0f, 0.0f };
- //printf("origin: (%f, %f, %f)", origin.x, origin.y, origin.z);
+ cam = (vec3){ 0.0f, 0.0f, 5.0 + 2.0f * sin(time) };
+
+ err = pthread_create(&thread, NULL, input, NULL);
+ if (err) {
+ printf("An error occured: %d", err);
+ return 1;
+ }
time = 0.0;
@@ 151,10 187,14 @@ int main(void)
printf("\033[0;0m\n");
}
time += 0.002f;
+
//origin.x = 2.0f * cos(time);
- origin.z = 5.0 + 2.0f * sin(time);
+ origin.z = cam.z + 2.0f * sin(time);
+ origin.x = cam.x;
+
printf("\033[%dF\n", HEIGHT + 1);
}
+ pthread_join(thread, NULL);
return 0;
}