Generating path from shore to pier

This commit is contained in:
2025-12-15 01:41:44 +03:00
parent 3f99099919
commit 9bb9e2c09b
3 changed files with 391 additions and 322 deletions

View File

@@ -988,6 +988,82 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
length += 1.0f;
}
}
static void findPierPath(std::vector<Ogre::Vector3> &path)
{
Ogre::Vector3 basePos =
ECS::get<EditorGizmo>().sceneNode->_getDerivedPosition();
Ogre::Quaternion baseRot =
ECS::get<EditorGizmo>()
.sceneNode->_getDerivedOrientation();
Ogre::Vector3 direction = baseRot * Ogre::Vector3(0, 0, 1);
float length = 0.0f;
while (length < 260.0f) {
Ogre::Vector3 currentPosition =
basePos + direction * (length);
float dheight =
ECS::get<Terrain>()
.mTerrainGroup->getHeightAtWorldPosition(
currentPosition);
Ogre::Vector3 localOffset =
Ogre::Vector3(0, 0, 1) * length;
if (dheight < 0 && path.size() == 0)
return;
if (path.size() == 0) {
Ogre::Vector3 localFromWorld =
ECS::get<EditorGizmo>()
.sceneNode
->convertWorldToLocalPosition(
{ currentPosition.x,
dheight,
currentPosition.z });
path.push_back({ localOffset.x,
localFromWorld.y,
localOffset.z });
} else {
float height = path.back().y;
if (height - dheight > 0.2f)
dheight = height - 0.2f;
height = dheight;
if (height < 0) {
height = 0;
Ogre::Vector3 localFromWorld =
ECS::get<EditorGizmo>()
.sceneNode
->convertWorldToLocalPosition(
{ currentPosition
.x,
height,
currentPosition
.z });
path.push_back({ localOffset.x,
localFromWorld.y,
localOffset.z });
break;
} else {
Ogre::Vector3 localFromWorld =
ECS::get<EditorGizmo>()
.sceneNode
->convertWorldToLocalPosition(
{ currentPosition
.x,
height,
currentPosition
.z });
path.push_back({ localOffset.x,
localFromWorld.y,
localOffset.z });
}
}
length += 0.5f;
}
}
static void to_json(nlohmann::json &j, const Ogre::Vector3 &position)
{
j["x"] = position.x;
j["y"] = position.y;
j["z"] = position.z;
}
void createHarbourItem()
{
Ogre::Vector3 itemPosition =
@@ -1002,6 +1078,8 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
pierDepth))
return;
findPierHeight(pierOffset + pierLength, pierHeight);
std::vector<Ogre::Vector3> pierPath;
findPierPath(pierPath);
flecs::entity e = StaticGeometryModule::createItem(
itemPosition, itemOrientation, "harbour");
Ogre::String prop = StaticGeometryModule::getItemProperties(e);
@@ -1010,6 +1088,13 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
j["pierLength"] = pierLength;
j["pierDepth"] = pierDepth;
j["pierHeight"] = pierHeight;
nlohmann::json p = nlohmann::json::array();
for (const auto &pt : pierPath) {
nlohmann::json pj;
to_json(pj, pt);
p.push_back(pj);
}
j["pierPath"] = p;
StaticGeometryModule::setItemProperties(e, j.dump());
// setHarbourSurface();
StaticGeometryModule::saveItems();
@@ -1017,8 +1102,19 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
// updateHeightmap();
// TerrainModule::save_heightmap();
}
void createHarbourMenu()
{
if (ImGui::MenuItem("Create"))
createHarbourItem();
}
void worldMapView()
{
bool riseLower = false;
bool riseLower2 = false;
bool smooth = false;
bool setLevel = false;
float setLevelValue = 0.0f;
float riseLowerChange = 0.0f;
OgreAssert(TerrainModule::get_img_x(0) ==
worldMap->getWidth() / 2,
"get_img_x");
@@ -1053,7 +1149,108 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
ImVec2(768, 768));
// ImGui::SetNextWindowScroll(
// ImVec2(worldMap->getWidth(), worldMap->getHeight()));
ImGui::Begin("WorldMap...");
ImGui::Begin("WorldMap...", nullptr, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("Create")) {
if (ImGui::BeginMenu("Harbour")) {
createHarbourMenu();
ImGui::EndMenu();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Heightmap")) {
if (ImGui::MenuItem("Update terrain"))
ECS::get<Terrain>()
.mTerrainGroup->update(false);
ImGui::Separator();
ImGui::SliderFloat("Strength...", &strength,
0.0f, 1.0f);
ImGui::SliderInt("Size", &size, 0, 32);
ImGui::Separator();
if (ImGui::Button("Elevate")) {
riseLower = true;
riseLowerChange = strength;
}
ImGui::SameLine();
if (ImGui::Button("Elevate2")) {
riseLower2 = true;
riseLowerChange = strength;
}
ImGui::SameLine();
if (ImGui::Button("Lower")) {
riseLower = true;
riseLowerChange = -strength;
}
if (ImGui::Button("Deepest")) {
setLevel = true;
setLevelValue = 0.0f;
}
ImGui::SameLine();
if (ImGui::Button("Deep")) {
setLevel = true;
setLevelValue = 0.25f;
}
ImGui::SameLine();
if (ImGui::Button("Shallow1")) {
setLevel = true;
setLevelValue = 0.35f;
}
ImGui::SameLine();
if (ImGui::Button("Shallow2")) {
setLevel = true;
setLevelValue = 0.47f;
}
if (ImGui::Button("Beach")) {
setLevel = true;
setLevelValue = 0.516f;
}
ImGui::SameLine();
if (ImGui::Button("Shore1")) {
setLevel = true;
setLevelValue = 0.536f;
}
ImGui::SameLine();
if (ImGui::Button("Shore2")) {
setLevel = true;
setLevelValue = 0.556f;
}
if (ImGui::Button("Shore3")) {
setLevel = true;
setLevelValue = 0.586f;
}
ImGui::SameLine();
if (ImGui::Button("Shore4")) {
setLevel = true;
setLevelValue = 0.606f;
}
ImGui::SameLine();
if (ImGui::Button("Shore5")) {
setLevel = true;
setLevelValue = 0.626f;
}
if (ImGui::Button("Shore6")) {
setLevel = true;
setLevelValue = 0.646f;
}
ImGui::SameLine();
if (ImGui::Button("Highest")) {
setLevel = true;
setLevelValue = 1.0f;
}
ImGui::SameLine();
if (ImGui::Button("Smooth")) {
smooth = true;
}
ImGui::Separator();
if (ImGui::MenuItem("Save heightmap")) {
updateWorldTexture();
updateHeightmap();
TerrainModule::save_heightmap();
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
ImGui::Spacing();
ImGui::BeginChild("WorldMap...", ImVec2(480, 480),
ImGuiChildFlags_None,
@@ -1156,9 +1353,6 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
ImGui::Text("Cursor position %f %f %f", position.x,
position.y, position.z);
}
if (ImGui::Button("Update terrain")) {
ECS::get<Terrain>().mTerrainGroup->update(false);
}
if (ImGui::Button("Update cursor position")) {
Ogre::Vector3 position =
ECS::get<EditorGizmo>()
@@ -1170,96 +1364,11 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
ECS::get<EditorGizmo>().sceneNode->_setDerivedPosition(
position);
}
ImGui::SliderFloat("Strength...", &strength, 0.0f, 1.0f);
ImGui::SliderInt("Size", &size, 0, 32);
ImGui::SliderFloat("Cursor Angle...", &cursorAngle, -180.0f,
180.0f);
bool riseLower = false;
bool riseLower2 = false;
bool smooth = false;
bool setLevel = false;
float setLevelValue = 0.0f;
float riseLowerChange = 0.0f;
ECS::get<EditorGizmo>().sceneNode->_setDerivedOrientation(
Ogre::Quaternion(Ogre::Degree(cursorAngle),
Ogre::Vector3::UNIT_Y));
if (ImGui::Button("Elevate")) {
riseLower = true;
riseLowerChange = strength;
}
ImGui::SameLine();
if (ImGui::Button("Lower")) {
riseLower = true;
riseLowerChange = -strength;
}
ImGui::SameLine();
if (ImGui::Button("Smooth")) {
smooth = true;
}
ImGui::SameLine();
if (ImGui::Button("Elevate2")) {
riseLower2 = true;
riseLowerChange = strength;
}
if (ImGui::Button("Deepest")) {
setLevel = true;
setLevelValue = 0.0f;
}
ImGui::SameLine();
if (ImGui::Button("Deep")) {
setLevel = true;
setLevelValue = 0.25f;
}
ImGui::SameLine();
if (ImGui::Button("Shallow1")) {
setLevel = true;
setLevelValue = 0.35f;
}
ImGui::SameLine();
if (ImGui::Button("Shallow2")) {
setLevel = true;
setLevelValue = 0.47f;
}
ImGui::SameLine();
if (ImGui::Button("Beach")) {
setLevel = true;
setLevelValue = 0.516f;
}
if (ImGui::Button("Shore1")) {
setLevel = true;
setLevelValue = 0.536f;
}
ImGui::SameLine();
if (ImGui::Button("Shore2")) {
setLevel = true;
setLevelValue = 0.556f;
}
ImGui::SameLine();
if (ImGui::Button("Shore3")) {
setLevel = true;
setLevelValue = 0.586f;
}
ImGui::SameLine();
if (ImGui::Button("Shore4")) {
setLevel = true;
setLevelValue = 0.606f;
}
if (ImGui::Button("Shore5")) {
setLevel = true;
setLevelValue = 0.626f;
}
ImGui::SameLine();
if (ImGui::Button("Shore6")) {
setLevel = true;
setLevelValue = 0.646f;
}
ImGui::SameLine();
if (ImGui::Button("Highest")) {
setLevel = true;
setLevelValue = 1.0f;
}
if (ImGui::Button("Harbour"))
createHarbourItem();
flecs::entity selected_item;
bool item_is_selected = false;
{
@@ -1460,11 +1569,6 @@ struct EditorGUIListener : public Ogre::RenderTargetListener {
updateWorldTexture();
updateHeightmap();
}
if (ImGui::Button("Save heightmap")) {
updateWorldTexture();
updateHeightmap();
TerrainModule::save_heightmap();
}
ImGui::EndChild();
ImGui::Spacing();
ImGui::End();