2 Raycasting terminal test.
8 #define RCL_PIXEL_FUNCTION pixelFunc
9 #define RCL_COMPUTE_WALL_TEXCOORDS 0
10 #define RCL_COMPUTE_FLOOR_DEPTH 0
11 #define RCL_COMPUTE_CEILING_DEPTH 0
14 #include "raycastlib.h"
24 char pixels
[SCREEN_W
* SCREEN_H
];
27 const int8_t level
[LEVEL_W
* LEVEL_H
] =
30 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 */
31 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, // 0
32 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, // 1
33 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0, // 2
34 1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0, // 3
35 0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,0, // 4
36 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, // 5
37 1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0, // 6
38 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0, // 7
39 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,1, // 8
40 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, // 9
41 0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1, // 10
42 0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,0,1, // 11
43 0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0, // 12
44 0,0,0,0,0,1,0,0,0,1,1,1,0,0,1,0,0,0,0,0, // 13
45 0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0 // 14
48 RCL_Unit
heightAt(int16_t x
, int16_t y
)
50 int32_t index
= y
* LEVEL_W
+ x
;
52 if (index
< 0 || (index
>= LEVEL_W
* LEVEL_H
))
53 return RCL_UNITS_PER_SQUARE
* 2;
55 return level
[y
* LEVEL_W
+ x
] * RCL_UNITS_PER_SQUARE
* 2;
58 void pixelFunc(RCL_PixelInfo
*p
)
64 switch (p
->hit
.direction
)
66 case 0: c
= 'X'; break;
67 case 1: c
= '#'; break;
68 case 2: c
= 'o'; break;
70 default: c
= '.'; break;
74 pixels
[p
->position
.y
* SCREEN_W
+ p
->position
.x
] = c
;
79 for (int i
= 0; i
< 10; ++i
)
84 RCL_initRayConstraints(&c
);
89 RCL_renderSimple(camera
,heightAt
,0,0,c
);
90 //RCL_renderComplex(camera,heightAt,0,0,c);
92 for (int j
= 0; j
< SCREEN_H
; ++j
)
94 for (int i
= 0; i
< SCREEN_W
; ++i
)
95 printf("%c",pixels
[j
* SCREEN_W
+ i
]);
108 RCL_initCamera(&camera
);
109 camera
.position
.x
= 2 * RCL_UNITS_PER_SQUARE
;
110 camera
.position
.y
= 2 * RCL_UNITS_PER_SQUARE
;
111 camera
.direction
= 0;
112 camera
.resolution
.x
= SCREEN_W
;
113 camera
.resolution
.y
= SCREEN_H
;
115 for (int i
= 0; i
< 10000; ++i
)
119 int squareX
= RCL_divRoundDown(camera
.position
.x
,RCL_UNITS_PER_SQUARE
);
120 int squareY
= RCL_divRoundDown(camera
.position
.y
,RCL_UNITS_PER_SQUARE
);
122 if (rand() % 100 == 0)
129 while (heightAt(squareX
+ dx
,squareY
+ dy
) > 0)
136 camera
.position
.x
+= dx
* 200;
137 camera
.position
.y
+= dy
* 200;
138 camera
.direction
+= dr
* 10;
140 camera
.height
= RCL_UNITS_PER_SQUARE
+ RCL_sinInt(frame
* 16) / 2;