summaryrefslogtreecommitdiff
path: root/kon/konworld.h
diff options
context:
space:
mode:
authorKonAki <konaki@anokonaki.org>2026-10-11 22:06:56 +0800
committerKonAki <konaki@anokonaki.org>2026-10-11 22:06:56 +0800
commit20bbe2731a2d04b6dde65e9f893ad360915a889b (patch)
tree787880beefd26783f75c8399a586970c036d3ca9 /kon/konworld.h
parent95bd48a7b0556adab5250cae766ee9dd9c6b2cde (diff)
world: rays and line of sight through sectors, terrain, tiles and shapes
Diffstat (limited to 'kon/konworld.h')
-rw-r--r--kon/konworld.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/kon/konworld.h b/kon/konworld.h
index bce5187..364d400 100644
--- a/kon/konworld.h
+++ b/kon/konworld.h
@@ -120,4 +120,32 @@ void kon_worldPlace(const kon_world_t *world, kon_body_t *body);
of the world. then gravity: steps up are taken at once and drops are falls. dt is seconds */
void kon_worldMove(kon_world_t *world, kon_body_t *body, float dx, float dz, double dt);
+/*** rays ***/
+
+typedef enum kon_hitKind {
+ KON_HIT_NONE = 0,
+ KON_HIT_WALL, /* a wall of a sector, or the step or lintel of an opening */
+ KON_HIT_FLOOR,
+ KON_HIT_CEILING,
+ KON_HIT_COLLIDER,
+ KON_HIT_TERRAIN,
+ KON_HIT_TILE
+} kon_hitKind_t;
+
+typedef struct kon_rayHit {
+ int kind;
+ float distance;
+ kon_vec3_t point, normal; /* normal faces back at the ray */
+ int sector; /* the room a wall, floor or ceiling belongs to, -1 for the rest */
+ int edge; /* which wall of that room, -1 for the rest */
+ int collider; /* the index, -1 for the rest */
+} kon_rayHit_t;
+
+/* shoots a ray and finds the first thing it hits within maxDistance. direction does not have to be 1 long. hit can be NULL.
+ a ray through the rooms of a sector map has to start inside one. shapes the ray starts inside are not hit */
+int kon_worldRay(const kon_world_t *world, kon_vec3_t origin, kon_vec3_t direction, float maxDistance, kon_rayHit_t *hit);
+
+/* 1 if nothing is between the two points. for "can the monster see me" and "is the light reaching here" */
+int kon_worldVisible(const kon_world_t *world, kon_vec3_t from, kon_vec3_t to);
+
#endif