7 #include "cgmath/cgmath.h"
10 static int init(void);
11 static void destroy(void);
12 static void start(long trans_time);
13 static void draw(void);
15 static struct screen scr = {
24 static cgm_vec3 raydir[120][160];
25 static struct rtscene scn;
27 struct screen *raytrace_screen(void)
35 float z = 1.0f / tan(cgm_deg_to_rad(25.0f));
37 for(i=0; i<120; i++) {
38 cgm_vec3 *vptr = raydir[i];
39 float y = 1.0f - (float)i / 60.0f;
40 for(j=0; j<160; j++) {
41 vptr->x = ((float)j / 80.0f - 1.0f) * 1.333333f;
51 rt_specular(0.8f, 0.8f, 0.8f);
53 rt_add_sphere(&scn, 0, 0, 0, 1); /* x,y,z, rad */
55 rt_color(0.4, 0.4, 0.4);
58 rt_add_plane(&scn, 0, 1, 0, -1); /* nx,ny,nz, dist */
61 rt_add_light(&scn, -8, 15, -10);
65 static void destroy(void)
70 static void start(long start_time)
74 static void draw(void)
77 uint16_t pix, *fbptr = fb_pixels;
79 for(i=0; i<120; i++) {
80 for(j=0; j<160; j++) {
83 ray.dir = raydir[i][j];
84 cgm_vcons(&ray.origin, 0, 0, -5);
86 if(ray_trace(&ray, &scn, 0, &col)) {
87 r = cround64(col.x * 255.0f);
88 g = cround64(col.y * 255.0f);
89 b = cround64(col.z * 255.0f);
93 pix = PACK_RGB16(r, g, b);
97 fbptr[0] = fbptr[1] = fbptr[320] = fbptr[321] = pix;