singe/src/nav.h
2026-09-07 01:28:53 -05:00

76 lines
3.4 KiB
C

/*
*
* Singe 3
* Copyright (C) 2006-2026 Scott Duensing <scott@kangaroopunch.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
// Singe - Navigation: walkable meshes baked from scene geometry (Recast), paths across them
// (Detour) and agents that follow those paths without walking through each other (DetourCrowd),
// behind a C interface. Positions are world units; nodes are scene nodes.
#ifndef NAV_H
#define NAV_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "math3d.h"
#ifdef __cplusplus
extern "C" {
#endif
#define NAV_NO_HANDLE -1
#define NAV_MAX_PATH 256 // Corners navPath can hand back, and polygons a query may cross
#define NAV_ARRIVAL_QUEUE 64 // Arrivals held for navPollArrived between frames
#define NAV_MAX_CROWD_AGENTS 128 // Agents one mesh's crowd can steer
void navInit(void);
int32_t navPollArrived(int32_t *agents, int32_t max); // Agents that reached their targets since last asked
void navQuit(void);
void navUpdate(bool advance); // Once per frame: moves the agents
bool navAddNode(int32_t nav, int32_t node); // The node's mesh and its children's, where they stand now
bool navBuild(int32_t nav); // Bakes what was added; may take a moment
bool navDelete(int32_t nav);
int32_t navGetPolygons(int32_t nav, Vec3T *vertices, int32_t max); // Triangles of the baked mesh (3 per), for debug drawing
int32_t navLoad(const void *data, size_t size, float agentRadius, float agentHeight);
bool navNearest(int32_t nav, Vec3T point, Vec3T *out); // The closest point on the mesh
int32_t navNew(float agentRadius, float agentHeight, float maxSlopeDegrees, float maxStep);
int32_t navPath(int32_t nav, Vec3T from, Vec3T to, Vec3T *points, int32_t max); // Corners of the path, or -1 for none
bool navRandomPoint(int32_t nav, Vec3T *out);
bool navRaycast(int32_t nav, Vec3T from, Vec3T to, Vec3T *hit); // true when the walk from from to to is blocked, hit where
bool navSave(int32_t nav, const char *path); // The baked mesh, to reload with navLoad
bool navValid(int32_t nav);
bool navAgentDelete(int32_t agent);
int32_t navAgentGetNode(int32_t agent);
bool navAgentGetVelocity(int32_t agent, Vec3T *velocity);
bool navAgentIsArrived(int32_t agent);
bool navAgentMoveTo(int32_t agent, Vec3T target);
int32_t navAgentNew(int32_t nav, int32_t node, float radius, float height, float speed);
bool navAgentSetPlayer(int32_t agent, bool player); // Steer a player controller on the node instead of placing it
bool navAgentStop(int32_t agent);
bool navAgentValid(int32_t agent);
#ifdef __cplusplus
}
#endif
#endif