diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/maps/house.kmap | 4 | ||||
| -rw-r--r-- | examples/sectorview.c | 43 |
2 files changed, 43 insertions, 4 deletions
diff --git a/examples/maps/house.kmap b/examples/maps/house.kmap index 50912b6..b9fccb7 100644 --- a/examples/maps/house.kmap +++ b/examples/maps/house.kmap @@ -37,7 +37,9 @@ edge 1 2 wallpaper # kind x y z angle, then name= and target= and anything else you like entity spawn 4 1.6 2 0 -entity light 4 2.6 2 0 color=ffe0a0 radius=8 +entity light 4 2.6 2 0 color=ffe0a0 radius=5.5 +entity light 4 2.6 -2 0 color=a8c4ff radius=4.5 intensity=0.7 +entity light 11 2.3 3 0 color=ffc890 radius=4.5 entity button 7.8 1.2 1 270 target=door1 entity door 8 0 2 90 name=door1 speed=2 width=4 height=2.6 diff --git a/examples/sectorview.c b/examples/sectorview.c index 2d5b5df..937507e 100644 --- a/examples/sectorview.c +++ b/examples/sectorview.c @@ -5,7 +5,7 @@ * run: obj/sectorview (from the folder with examples/) * * click to grab the mouse, tab lets go, a click after that shoots a ray and the top line says what it hit. w and s walk, a and d strafe, - * space jumps, e presses a button close to you. + * space jumps, e presses a button close to you, f turns the flashlight on and off. the lamps are the "light" entities of the map. * the door is a box in the world that the program lifts, nothing else about it is built in * the map is examples/maps/house.kmap, it is plain text so change it and run again. try moving the watcher */ @@ -31,6 +31,8 @@ #define RADIUS 0.2f #define HEIGHT 1.0f #define REACH 1.6f +#define MAX_LAMPS 16 +#define AMBIENT 0.12f #define COL_SKY 0xFF1B1826u #define COL_DIM 0xFF9A93B3u @@ -47,6 +49,7 @@ typedef struct state { kon_material_t doorMaterial, buttonMaterial; kon_vec3_t eye; float feet; /* what the eyes follow, it catches up with the body after a step */ + int flashlight; int door[MAX_ENTITIES]; /* the collider of a door entity, -1 for the others */ float open[MAX_ENTITIES]; /* how far a door is open, 0 to 1 */ int opening[MAX_ENTITIES]; @@ -129,6 +132,10 @@ static int event(kon_program_t *program, const kon_event_t *ev, void *user) else snprintf(state->note, sizeof(state->note), "shot, hit nothing"); return 1; } + if (ev->type == KON_EVENT_KEY_DOWN && ev->key == KON_KEY_F) { + state->flashlight = !state->flashlight; + return 1; + } if (ev->type == KON_EVENT_KEY_DOWN && ev->key == KON_KEY_SPACE) { kon_bodyJump(&state->body); return 1; @@ -221,7 +228,8 @@ static void draw(kon_program_t *program, kon_framebuffer_t *game, void *user) kon_clearFramebuffer(game, COL_SKY); light.direction = KON_VEC3(-0.3f, -1.0f, -0.2f); - light.ambient = 0.5f; + light.ambient = 1.0f; + light.intensity = 0.0f; kon_sectorDraw(game, &camera, state->mesh, state->materials, state->map->textureCount, &light); for (i = 0; i < state->map->entityCount; i++) { @@ -237,10 +245,39 @@ static void draw(kon_program_t *program, kon_framebuffer_t *game, void *user) } } + /* the scene was drawn in plain colors, the lights are what makes it dark: the lamps in the map and the flashlight */ + { + kon_pointLight_t lamps[MAX_LAMPS]; + int count = 0; + + for (i = 0; i < state->map->entityCount && count < MAX_LAMPS - 1; i++) { + const kon_entity_t *e = &state->map->entities[i]; + + if (strcmp(e->kind, "light") != 0) continue; + lamps[count].position = e->position; + lamps[count].color = 0xFF000000u | (uint32_t)strtoul(kon_entityString(e, "color", "ffffff"), NULL, 16); + lamps[count].radius = kon_entityFloat(e, "radius", 6.0f); + lamps[count].intensity = kon_entityFloat(e, "intensity", 1.0f); + lamps[count].cone = 0.0f; + count++; + } + if (state->flashlight) { + lamps[count].position = camera.position; + lamps[count].direction = KON_VEC3(camera.target.x - camera.position.x, camera.target.y - camera.position.y, camera.target.z - camera.position.z); + lamps[count].color = 0xFFFFF4D8; + lamps[count].radius = 14.0f; + lamps[count].intensity = 1.2f; + lamps[count].cone = 0.45f; + lamps[count].soft = 0.6f; + count++; + } + kon_lightPass(game, vp, lamps, count, AMBIENT); + } + kon_fillRectangle(game, game->width / 2 - 3, game->height / 2, 7, 1, COL_NOTE); kon_fillRectangle(game, game->width / 2, game->height / 2 - 3, 1, 7, COL_NOTE); if (program->font) { - snprintf(line, sizeof(line), "room %d click shoots a ray, e presses buttons, space jumps", state->body.sector); + snprintf(line, sizeof(line), "room %d click shoots a ray, f flashlight, e button, space jumps", state->body.sector); kon_drawText(game, program->font, 8, 16, line, COL_DIM); if (state->note[0]) kon_drawText(game, program->font, 8, 30, state->note, COL_NOTE); } |
