Ray casting engine implemented on the mBuino platform using the ST7735 LCD controller.
Ray casting engine written to test performance of the LCD_ST7735 library I wrote as a learning exercise on the mbed platform.
Diff: main.cpp
- Revision:
- 0:303768292f44
- Child:
- 2:4de2cb6f6fe8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Sep 21 22:04:22 2014 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "common.h" +#include "LCD_ST7735.h" +#include "Color565.h" +#include "Raycaster.h" + +static const uint8_t g_map[] = +{ + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,4, + 1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,4, + 1,0,1,0,0,0,0,1,1,0,0,0,0,1,0,4, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, + 1,1,3,4,3,3,3,0,0,2,2,2,2,2,2,4, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, + 1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,4, + 1,1,1,1,0,0,1,0,0,1,0,0,3,3,3,4, + 3,0,0,0,0,0,1,0,0,1,0,0,0,0,0,4, + 3,0,0,1,1,1,0,0,0,0,1,1,1,0,0,4, + 3,0,0,1,0,0,0,0,0,0,0,0,1,0,0,4, + 3,0,0,1,0,0,2,4,4,2,0,0,1,0,0,4, + 3,0,0,1,0,0,0,0,0,0,0,0,1,0,0,4, + 3,0,0,0,0,1,0,0,0,0,1,0,0,0,0,4, + 3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4, +}; + +static const uint16_t g_palette[] = +{ + Color565::Black, + Color565::Red, + Color565::Green, + Color565::Blue, + Color565::Yellow +}; + +AnalogIn stickX(P0_11); +AnalogIn stickY(P0_13); + +main() +{ + Raycaster rayCaster(0, 10, 160, 108, + 96, CELL_SIZE / 2, + g_map, 16, 16, + g_palette); + + rayCaster.setCellPosition(8, 8); + + while (true) + { + rayCaster.renderFrame(); + + if (stickX < 0.3) rayCaster.rotate(-0.1); + else if (stickX > 0.7) rayCaster.rotate(0.1);; + + if (stickY < 0.3) rayCaster.move(4); + else if (stickY > 0.7) rayCaster.move(-4); + } +} +