Added path showing
This commit is contained in:
parent
4eaefd25d4
commit
dc76986cd3
@ -111,6 +111,7 @@ target_compile_definitions(space-game001 PRIVATE
|
|||||||
WIN32_LEAN_AND_MEAN
|
WIN32_LEAN_AND_MEAN
|
||||||
PNG_ENABLED
|
PNG_ENABLED
|
||||||
SDL_MAIN_HANDLED
|
SDL_MAIN_HANDLED
|
||||||
|
SHOW_PATH
|
||||||
# NETWORK
|
# NETWORK
|
||||||
# SIMPLIFIED
|
# SIMPLIFIED
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
//precisionmediump float;
|
//precisionmediump float;
|
||||||
varying vec3 color;
|
varying vec3 color;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//gl_FragColor = vec4(color, 1.0);
|
gl_FragColor = vec4(color, 1.0);
|
||||||
gl_FragColor = vec4(1.0, 1.0, 0.5, 1.0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
36
src/Game.cpp
36
src/Game.cpp
@ -300,6 +300,10 @@ namespace ZL
|
|||||||
|
|
||||||
navigation.build(obstacles, "resources/config2/navigation.json", CONST_ZIP_FILE);
|
navigation.build(obstacles, "resources/config2/navigation.json", CONST_ZIP_FILE);
|
||||||
|
|
||||||
|
#ifdef SHOW_PATH
|
||||||
|
buildDebugNavMeshes();
|
||||||
|
#endif
|
||||||
|
|
||||||
auto planner = [this](const Eigen::Vector3f& start, const Eigen::Vector3f& end) {
|
auto planner = [this](const Eigen::Vector3f& start, const Eigen::Vector3f& end) {
|
||||||
return navigation.findPath(start, end);
|
return navigation.findPath(start, end);
|
||||||
};
|
};
|
||||||
@ -315,6 +319,35 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SHOW_PATH
|
||||||
|
void Game::buildDebugNavMeshes()
|
||||||
|
{
|
||||||
|
debugNavMeshes.clear();
|
||||||
|
const auto& areas = navigation.getAreas();
|
||||||
|
float y = navigation.getFloorY() + 0.02f;
|
||||||
|
Eigen::Vector3f red(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
for (const auto& area : areas) {
|
||||||
|
if (area.polygon.size() < 3) continue;
|
||||||
|
VertexRenderStruct mesh;
|
||||||
|
mesh.data = CreatePolygonFloor(area.polygon, y, red);
|
||||||
|
mesh.RefreshVBO();
|
||||||
|
debugNavMeshes.push_back(std::move(mesh));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::drawDebugNavigation()
|
||||||
|
{
|
||||||
|
renderer.shaderManager.PushShader("defaultColor");
|
||||||
|
renderer.SetMatrix();
|
||||||
|
for (const auto& mesh : debugNavMeshes) {
|
||||||
|
renderer.DrawVertexRenderStruct(mesh);
|
||||||
|
}
|
||||||
|
renderer.shaderManager.PopShader();
|
||||||
|
renderer.SetMatrix();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
InteractiveObject* Game::raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir) {
|
InteractiveObject* Game::raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir) {
|
||||||
if (interactiveObjects.empty()) {
|
if (interactiveObjects.empty()) {
|
||||||
std::cout << "[RAYCAST] No interactive objects to check" << std::endl;
|
std::cout << "[RAYCAST] No interactive objects to check" << std::endl;
|
||||||
@ -465,6 +498,9 @@ namespace ZL
|
|||||||
if (player) player->draw(renderer);
|
if (player) player->draw(renderer);
|
||||||
for (auto& npc : npcs) npc->draw(renderer);
|
for (auto& npc : npcs) npc->draw(renderer);
|
||||||
|
|
||||||
|
#ifdef SHOW_PATH
|
||||||
|
drawDebugNavigation();
|
||||||
|
#endif
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|
||||||
|
|||||||
@ -88,6 +88,10 @@ namespace ZL {
|
|||||||
ScriptEngine scriptEngine;
|
ScriptEngine scriptEngine;
|
||||||
PathFinder navigation;
|
PathFinder navigation;
|
||||||
|
|
||||||
|
#ifdef SHOW_PATH
|
||||||
|
std::vector<VertexRenderStruct> debugNavMeshes;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool rightMouseDown = false;
|
bool rightMouseDown = false;
|
||||||
int lastMouseX = 0;
|
int lastMouseX = 0;
|
||||||
@ -108,6 +112,11 @@ namespace ZL {
|
|||||||
InteractiveObject* raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir);
|
InteractiveObject* raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir);
|
||||||
Character* raycastNpcs(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir, float maxDistance = 100.0f);
|
Character* raycastNpcs(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir, float maxDistance = 100.0f);
|
||||||
|
|
||||||
|
#ifdef SHOW_PATH
|
||||||
|
void buildDebugNavMeshes();
|
||||||
|
void drawDebugNavigation();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
static Game* s_instance;
|
static Game* s_instance;
|
||||||
static void onResourcesZipLoaded(const char* filename);
|
static void onResourcesZipLoaded(const char* filename);
|
||||||
|
|||||||
@ -19,6 +19,12 @@ public:
|
|||||||
int z = 0;
|
int z = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NavigationArea {
|
||||||
|
std::string name;
|
||||||
|
bool available = true;
|
||||||
|
std::vector<Eigen::Vector2f> polygon;
|
||||||
|
};
|
||||||
|
|
||||||
void build(const std::vector<ObstacleMesh>& obstacleMeshes,
|
void build(const std::vector<ObstacleMesh>& obstacleMeshes,
|
||||||
const std::string& configPath,
|
const std::string& configPath,
|
||||||
const std::string& zipPath = "");
|
const std::string& zipPath = "");
|
||||||
@ -29,13 +35,10 @@ public:
|
|||||||
bool setAreaAvailable(const std::string& areaName, bool available);
|
bool setAreaAvailable(const std::string& areaName, bool available);
|
||||||
bool isReady() const { return ready; }
|
bool isReady() const { return ready; }
|
||||||
bool isWalkable(const Eigen::Vector3f& point) const;
|
bool isWalkable(const Eigen::Vector3f& point) const;
|
||||||
|
const std::vector<NavigationArea>& getAreas() const { return areas; }
|
||||||
|
float getFloorY() const { return floorY; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct NavigationArea {
|
|
||||||
std::string name;
|
|
||||||
bool available = true;
|
|
||||||
std::vector<Eigen::Vector2f> polygon;
|
|
||||||
};
|
|
||||||
|
|
||||||
float cellSize = 0.4f;
|
float cellSize = 0.4f;
|
||||||
float agentRadius = 0.45f;
|
float agentRadius = 0.45f;
|
||||||
|
|||||||
@ -179,6 +179,24 @@ namespace ZL {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VertexDataStruct CreatePolygonFloor(const std::vector<Eigen::Vector2f>& polygon, float yLevel, const Vector3f& color)
|
||||||
|
{
|
||||||
|
VertexDataStruct result;
|
||||||
|
if (polygon.size() < 3) return result;
|
||||||
|
|
||||||
|
for (size_t i = 1; i + 1 < polygon.size(); ++i) {
|
||||||
|
result.PositionData.push_back({ polygon[0].x(), yLevel, polygon[0].y() });
|
||||||
|
result.PositionData.push_back({ polygon[i].x(), yLevel, polygon[i].y() });
|
||||||
|
result.PositionData.push_back({ polygon[i + 1].x(), yLevel, polygon[i + 1].y() });
|
||||||
|
|
||||||
|
result.ColorData.push_back(color);
|
||||||
|
result.ColorData.push_back(color);
|
||||||
|
result.ColorData.push_back(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
VertexDataStruct CreateRectHorizontalSections2D(Vector2f center, Vector2f halfWidthHeight, float zLevel, size_t sectionCount)
|
VertexDataStruct CreateRectHorizontalSections2D(Vector2f center, Vector2f halfWidthHeight, float zLevel, size_t sectionCount)
|
||||||
{
|
{
|
||||||
Vector2f posFrom = center - halfWidthHeight;
|
Vector2f posFrom = center - halfWidthHeight;
|
||||||
|
|||||||
@ -87,6 +87,7 @@ namespace ZL {
|
|||||||
};
|
};
|
||||||
|
|
||||||
VertexDataStruct CreateRect2D(Vector2f center, Vector2f halfWidthHeight, float zLevel);
|
VertexDataStruct CreateRect2D(Vector2f center, Vector2f halfWidthHeight, float zLevel);
|
||||||
|
VertexDataStruct CreatePolygonFloor(const std::vector<Eigen::Vector2f>& polygon, float yLevel, const Vector3f& color);
|
||||||
VertexDataStruct CreateRectHorizontalSections2D(Vector2f center, Vector2f halfWidthHeight, float zLevel, size_t sectionCount);
|
VertexDataStruct CreateRectHorizontalSections2D(Vector2f center, Vector2f halfWidthHeight, float zLevel, size_t sectionCount);
|
||||||
VertexDataStruct CreateCube3D(float scale);
|
VertexDataStruct CreateCube3D(float scale);
|
||||||
VertexDataStruct CreateCubemap(float scale = 1000.f);
|
VertexDataStruct CreateCubemap(float scale = 1000.f);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user