diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2015-02-18 12:49:58 -0500 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2015-02-18 12:49:58 -0500 |
| commit | 9defae4d6f7b30d844447549fadffea4eab5a0dd (patch) | |
| tree | 2c44f6fb193d9b3f7487714e7dfa3903bedb932d /apps | |
| parent | 1d3537f33d793e2cabe53e72f0e0ead911fcc870 (diff) | |
| download | kappa-9defae4d6f7b30d844447549fadffea4eab5a0dd.zip kappa-9defae4d6f7b30d844447549fadffea4eab5a0dd.tar.gz kappa-9defae4d6f7b30d844447549fadffea4eab5a0dd.tar.bz2 kappa-9defae4d6f7b30d844447549fadffea4eab5a0dd.tar.xz | |
support keyboard io
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/plugin.c | 9 | ||||
| -rw-r--r-- | apps/plugin.h | 3 | ||||
| -rw-r--r-- | apps/xracer/graphics.c | 19 | ||||
| -rw-r--r-- | apps/xracer/main.c | 20 | ||||
| -rw-r--r-- | apps/xracer/xracer.h | 4 |
5 files changed, 42 insertions, 13 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 440841a..fcb659d 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include "plugin.h" #include "gfx.h" +#include "ps2kbd.h" static void plugin_clear(void) { @@ -22,6 +23,11 @@ static void plugin_hline(int a, int b, int c) gfx_hline(a, b, c); } +static int button_get(void) +{ + return ps2kbd_button_get(); +} + static const struct plugin_api kappa_api = { &plugin_clear, &plugin_hline, @@ -40,7 +46,8 @@ static const struct plugin_api kappa_api = { &gfx_drawcircle, &gfx_fillcircle, &gfx_update, - &gfx_putsxy + &gfx_putsxy, + &button_get }; void plugin_load(enum plugin_status (*plugin)(const struct plugin_api*)) diff --git a/apps/plugin.h b/apps/plugin.h index 5d62b93..849dda9 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -5,6 +5,7 @@ #include <stdlib.h> #include <stdio.h> #include "gfx.h" +#include "ps2kbd.h" #include "timer.h" #define LCD_WIDTH (*gfx_width) @@ -48,6 +49,8 @@ struct plugin_api { void (*lcd_fillcircle)(int x, int y, int r); void (*lcd_update)(void); void (*lcd_putsxy)(int x, int y, const char*); + + int (*button_get)(void); }; /* defined by the plugin */ diff --git a/apps/xracer/graphics.c b/apps/xracer/graphics.c index eb31424..d523343 100644 --- a/apps/xracer/graphics.c +++ b/apps/xracer/graphics.c @@ -56,13 +56,18 @@ static inline int project(int cam_x, int cam_y, int cam_z, int camera_depth, str rel_x = pt_3d->x - cam_x; rel_y = pt_3d->y - cam_y; rel_z = pt_3d->z - cam_z; - float scale = (float)camera_depth / rel_z; - pt_2d->x = (LCD_WIDTH/2) + (scale * rel_x * (LCD_WIDTH/2)); - pt_2d->y = (LCD_WIDTH/2) - (scale * rel_y * (LCD_HEIGHT/2)); - pt_2d->w = scale * ROAD_WIDTH * (LCD_WIDTH/2); - if(scale_return) - *scale_return=scale; - return rel_z; + if(rel_z != 0) + { + float scale = (float)camera_depth / rel_z; + pt_2d->x = (LCD_WIDTH/2) + (scale * rel_x * (LCD_WIDTH/2)); + pt_2d->y = (LCD_WIDTH/2) - (scale * rel_y * (LCD_HEIGHT/2)); + pt_2d->w = scale * ROAD_WIDTH * (LCD_WIDTH/2); + if(scale_return) + *scale_return=scale; + + return rel_z; + } + return -1; } static inline int border_width(int projected_road_width, int lanes) diff --git a/apps/xracer/main.c b/apps/xracer/main.c index 9a51a31..5c88c4f 100644 --- a/apps/xracer/main.c +++ b/apps/xracer/main.c @@ -93,9 +93,6 @@ enum plugin_status do_flythrough(void) //road_length = load_external_map(road, MAX_ROAD_LENGTH, "/output.xrm"); - road_length = -1; - - road_length = MAX_ROAD_LENGTH; generate_random_road(road, road_length, HILLS, CURVES); @@ -106,6 +103,23 @@ enum plugin_status do_flythrough(void) while(1) { + int button = rb->button_get(); + switch(button) + { + case BUTTON_UP: + camera_height += MANUAL_SPEED; + break; + case BUTTON_DOWN: + camera_height -= MANUAL_SPEED; + break; + case BUTTON_LEFT: + camera.pos.x -= MANUAL_SPEED; + break; + case BUTTON_RIGHT: + camera.pos.x += MANUAL_SPEED; + break; + } + camera.pos.z += 512; /* loop the track right before going off the "end" */ camera.pos.z %= (road_length - DRAW_DIST) * SEGMENT_LENGTH; diff --git a/apps/xracer/xracer.h b/apps/xracer/xracer.h index 21375e3..804bf39 100644 --- a/apps/xracer/xracer.h +++ b/apps/xracer/xracer.h @@ -51,7 +51,7 @@ #define LANES 3 /* camera parameters */ -#define DRAW_DIST 256 +#define DRAW_DIST 1024 /* NOTE: FOV is not used, the tangent value (see below) is */ #define CAMERA_FOV 120 /* in degrees */ @@ -60,7 +60,7 @@ /* game parameters */ /* currently this is how far the camera moves per keypress */ -#define MANUAL_SPEED 50 +#define MANUAL_SPEED 10 /* number of bits to use for the fractional part of fixed-point numbers */ /* note that FOV calculation always uses 14 by default */ |