Demo code for basic 3D graphics on the MBED application shield's LCD (K64F). Left pot changes Z depth, joystick rotates one of the cubes.
Dependencies: C12832 FXOS8700CQ gfx3d mbed
Diff: main.cpp
- Revision:
- 1:3810f9d9c775
- Parent:
- 0:fe1c42b7b490
- Child:
- 2:297b43e931d0
diff -r fe1c42b7b490 -r 3810f9d9c775 main.cpp --- a/main.cpp Sun Nov 01 02:28:21 2015 +0000 +++ b/main.cpp Sun Nov 01 23:10:01 2015 +0000 @@ -94,6 +94,9 @@ int main (void) { angle_t a; +#ifdef BENCHMARK + int bt_start, bt_now, bt_trans = 0, bt_render = 0; +#endif /* initialise */ host.baud (38400); @@ -116,6 +119,11 @@ fxos.get_data (&fxos_acc, &fxos_mag); print_reading (); +#ifdef BENCHMARK + perftimer.reset (); + perftimer.start (); +#endif + a = 0; for (;;) { uint8_t cflags = 0x00; @@ -128,7 +136,12 @@ /* push last frame first */ shld_lcd.copy_to_lcd (); shld_lcd.cls (); - + +#ifdef BENCHMARK + bt_start = perftimer.read_us (); + bt_trans = 0; + bt_render = 0; +#endif for (i=0; i<4; i++) { g3d_p3_t trans = {3.0f * gfx3d_sin (a + (i * 64)), 0.0f, 3.0f * gfx3d_cos (a + (i * 64))}; @@ -141,12 +154,30 @@ } gfx3d_project (pts1, pts2, 8); - + +#ifdef BENCHMARK + bt_now = perftimer.read_us (); + bt_trans += (bt_now - bt_start); + bt_start = bt_now; +#endif + gfx3d_wirecube (pts2, shld_lcd); + +#ifdef BENCHMARK + bt_now = perftimer.read_us (); + bt_render += (bt_now - bt_start); + bt_start = bt_now; +#endif + } a++; - + +#ifdef BENCHMARK + /* write bt_trans and bt_render into the display */ + shld_lcd.locate (0, 24); + shld_lcd.printf ("T: %d, R: %d", bt_trans, bt_render); +#endif cflags |= PFLAG_TIMER; } if (pflags & PFLAG_FXOS) {