#include <acknex.h>
void main () {
VECTOR cube_min, cube_max;
VECTOR ray_start, ray_end, ray_dir;
ENTITY *cube;
level_load(NULL);
vec_set(&sky_color, COLOR_WHITE);
cube = ent_create(CUBE_MDL, vector(100, 0, 0), NULL);
c_setminmax(cube);
// set up ray
vec_set(&ray_start, vector(100, -32, 0));
vec_set(&ray_end, vector(100, 32, 0));
vec_diff(&ray_dir, &ray_end, &ray_start);
// set up bounding box
vec_set(&cube_min, &(cube->x));
vec_add(&cube_min, &(cube->min_x));
vec_set(&cube_max, &(cube->x));
vec_add(&cube_max, &(cube->max_x));
while (1) {
var intersection1, intersection2;
// move ray
ray_start.z -= time_step;
if (ray_start.z < (cube_min.z - 10))
ray_start.z *= -1;
ray_end.z = ray_start.z;
// intersection test with ray endpoint
intersection1 = c_intersect(&ray_start, &ray_start, &ray_end, &cube_min, &cube_max, NULL);
DEBUG_VAR(intersection1, 10);
// intersection test with ray direction vector
intersection2 = c_intersect(&ray_start, &ray_start, &ray_dir, &cube_min, &cube_max, NULL);
DEBUG_VAR(intersection2, 50);
if ((intersection1 == -1) || (intersection2 == -1)) {
draw_text("intersection!", 50, 10, COLOR_BLACK);
}
// draw ray
draw_line3d(&ray_start, NULL, 100);
draw_line3d(&ray_start, COLOR_BLACK, 100);
draw_line3d(&ray_end, COLOR_BLACK, 100);
wait(1);
}
}