-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraycaster.c
45 lines (35 loc) · 1.06 KB
/
raycaster.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
#include "headers/raycaster.h"
#include "headers/vector.h"
#include "headers/object.h"
#include "headers/renderer.h"
Object* objects;
int objectCount;
bool raycast(int x, int y){
float invWidth = 1/((float) width);
float invHeight = 1/((float) height);
float aspectRatio = width/((float) height);
float angle = tan(M_PI * 0.5 * (FOV/180.0));
float xx = (2*(x+0.5)*invWidth - 1) * angle * aspectRatio;
float yy = (1 - 2*(y+0.5)*invHeight) * angle;
Vector3f vec = { .x = xx, .y = yy, .z = -1};
normalize(&vec);
}
bool intersect(Vector3f* position){
for(int i = 0; i < objectCount; i++){
Object* obj = &objects[i];
if(!obj->visible)
continue;
if(SQUARE(obj->position.x - position->x)
+ SQUARE(obj->position.y - position->y)
+ SQUARE(obj->position.z - position->z)){
}
}
}
bool trace(Vector3f origin, Vector3f direction){
for(int i = 0; i < MAX_STEPS; i++){
add(&origin, &direction);
}
}