diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/corridor.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/examples/corridor.c b/examples/corridor.c index e0bb81e..7c34591 100644 --- a/examples/corridor.c +++ b/examples/corridor.c @@ -5,7 +5,7 @@ * ./build.sh -d -m tile,font,assets,image obj/corridor (also loads sprites/marker.png from the assets if there is one) * run: obj/corridor * - * click to grab the mouse and look around with it, tab lets go. w and s walk, a and d strafe, the arrows turn too + * click to grab the mouse and look around with it, tab lets go. with the debug module the variable sens sets the mouse speed. w and s walk, a and d strafe, the arrows turn too * the walls are quads made from the tilemap every frame, the markers are billboards drawn with depth so walls hide them * the markers are plain placeholders, put your own sprite in assets/sprites/marker.png to see it in their place */ @@ -25,7 +25,6 @@ #define TILE 32 /* map pixels in one world unit, the collision works in those */ #define WALL_HEIGHT 1.2f #define MARKERS 5 -#define LOOK_SPEED 0.003f #define COL_SKY 0xFF1B1826u #define COL_DIM 0xFF9A93B3u @@ -58,6 +57,7 @@ typedef struct state { int ownsMarker; kon_box2_t player; /* map pixels */ float yaw, pitch; + float sensitivity; /* radians per pixel */ int forward, strafe, turn; double time; kon_vec2_t markers[MARKERS]; /* world units */ @@ -152,11 +152,6 @@ static void draw(kon_program_t *program, kon_framebuffer_t *game, void *user) light.direction = KON_VEC3(-0.3f, -1.0f, -0.5f); light.ambient = 0.55f; - quad(game, vp, &floor, &light, KON_VEC3(0, 0, 0), KON_VEC3(0, 0, size), KON_VEC3(size, 0, size), KON_VEC3(size, 0, 0), - KON_VEC3(0, 1, 0), KON_VEC2(0, 0), KON_VEC2(size, size)); - quad(game, vp, &floor, &light, KON_VEC3(0, WALL_HEIGHT, 0), KON_VEC3(size, WALL_HEIGHT, 0), KON_VEC3(size, WALL_HEIGHT, size), KON_VEC3(0, WALL_HEIGHT, size), - KON_VEC3(0, -1, 0), KON_VEC2(0, 0), KON_VEC2(size, size)); - for (row = 0; row < ROWS; row++) { for (column = 0; column < COLUMNS; column++) { float x = (float)column, z = (float)row; @@ -169,6 +164,12 @@ static void draw(kon_program_t *program, kon_framebuffer_t *game, void *user) } } + /* the big flat quads go after the walls, what a wall already covers gets thrown out by the depth test early */ + quad(game, vp, &floor, &light, KON_VEC3(0, 0, 0), KON_VEC3(0, 0, size), KON_VEC3(size, 0, size), KON_VEC3(size, 0, 0), + KON_VEC3(0, 1, 0), KON_VEC2(0, 0), KON_VEC2(size, size)); + quad(game, vp, &floor, &light, KON_VEC3(0, WALL_HEIGHT, 0), KON_VEC3(size, WALL_HEIGHT, 0), KON_VEC3(size, WALL_HEIGHT, size), KON_VEC3(0, WALL_HEIGHT, size), + KON_VEC3(0, -1, 0), KON_VEC2(0, 0), KON_VEC2(size, size)); + for (i = 0; i < MARKERS; i++) { float dx = state->markers[i].x - eye.x, dz = state->markers[i].y - eye.z; float bob = 0.08f * sinf((float)state->time * 2.0f + (float)i); @@ -188,8 +189,8 @@ static int event(kon_program_t *program, const kon_event_t *ev, void *user) int down; if (ev->type == KON_EVENT_MOUSE_MOVE && kon_isMouseCaptured(program->window)) { - state->yaw += (float)ev->mouseDX * LOOK_SPEED; - state->pitch -= (float)ev->mouseDY * LOOK_SPEED; + state->yaw += (float)ev->mouseDX * state->sensitivity; + state->pitch -= (float)ev->mouseDY * state->sensitivity; if (state->pitch > 1.2f) state->pitch = 1.2f; if (state->pitch < -1.2f) state->pitch = -1.2f; return 1; @@ -240,6 +241,8 @@ static int init(kon_program_t *program, void *user) int row, column, i; (void)program; + state->sensitivity = 0.0015f; + kon_debugVar(program->debug, "sens", KON_VAR_FLOAT, &state->sensitivity); state->map.columns = COLUMNS; state->map.rows = ROWS; state->map.tileWidth = TILE; |
