diff --git a/src/features/editScene/systems/EditorUISystem.cpp b/src/features/editScene/systems/EditorUISystem.cpp index 688fbc7..a87a7d7 100644 --- a/src/features/editScene/systems/EditorUISystem.cpp +++ b/src/features/editScene/systems/EditorUISystem.cpp @@ -345,11 +345,23 @@ void EditorUISystem::update(float deltaTime) normal)) { Ogre::Vector3 hit = ray.getPoint(t); + /* Decal at hit (physical); + * brush converts to physical + * coords that visual-map + * back to hit location. */ ts->updateBrushDecal(hit, normal, ts->getSculptRadius()); if (ImGui::IsMouseDown( ImGuiMouseButton_Left)) { - ts->applySculptBrush(hit); + Ogre::Vector3 brushPos = hit; + brushPos.x = + ts->visualToPhysicalX( + hit.x); + brushPos.z = + ts->visualToPhysicalZ( + hit.z); + ts->applySculptBrush( + brushPos); } } else { ts->hideBrushDecal(); diff --git a/src/features/editScene/systems/TerrainSystem.cpp b/src/features/editScene/systems/TerrainSystem.cpp index 6c4ca1d..c6cad15 100644 --- a/src/features/editScene/systems/TerrainSystem.cpp +++ b/src/features/editScene/systems/TerrainSystem.cpp @@ -1520,7 +1520,7 @@ void TerrainSystem::updateBrushDecal(const Ogre::Vector3 &worldPos, pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA); pass->setDepthWriteEnabled(false); - pass->setDepthCheckEnabled(true); + pass->setDepthCheckEnabled(false); pass->setCullingMode(Ogre::CULL_NONE); /* Vertex colours provide the actual colour. */ pass->setVertexColourTracking( @@ -1600,6 +1600,17 @@ void TerrainSystem::hideBrushDecal() m_brushDecalNode->setVisible(false); } +/* ------------------------------------------------------------------ */ +/* getTerrainWorldHalfSize */ +/* ------------------------------------------------------------------ */ + +float TerrainSystem::getTerrainWorldHalfSize() const +{ + if (!mTerrainGroup) + return 1000.0f; + return mTerrainGroup->getTerrainWorldSize() * 0.5f; +} + /* ------------------------------------------------------------------ */ /* destroyCollider */ /* ------------------------------------------------------------------ */ @@ -1633,6 +1644,33 @@ float TerrainSystem::physicalToVisualZ(float physicalZ) const return 2.0f * pageZ + halfSize - physicalZ; } +/* ------------------------------------------------------------------ */ +/* visualToPhysicalX */ +/* ------------------------------------------------------------------ */ + +float TerrainSystem::visualToPhysicalX(float visualX) const +{ + if (!mTerrainGroup) + return visualX; + return visualX + mTerrainGroup->getTerrainWorldSize() * 0.5f; +} + +/* ------------------------------------------------------------------ */ +/* visualToPhysicalZ */ +/* ------------------------------------------------------------------ */ + +float TerrainSystem::visualToPhysicalZ(float visualZ) const +{ + if (!mTerrainGroup) + return visualZ; + Ogre::Real ws = mTerrainGroup->getTerrainWorldSize(); + float halfSize = ws * 0.5f; + /* Visual page: page 0 covers [-halfSize, halfSize). */ + float pageV = floorf((visualZ + halfSize) / ws) * ws; + /* Physical Z such that the ManualObject displays it at visual Z. */ + return 2.0f * pageV + halfSize - visualZ; +} + void TerrainSystem::destroyCollider(uint64_t /*key*/, TerrainCollider & /*collider*/) { diff --git a/src/features/editScene/systems/TerrainSystem.hpp b/src/features/editScene/systems/TerrainSystem.hpp index 18be184..33e1603 100644 --- a/src/features/editScene/systems/TerrainSystem.hpp +++ b/src/features/editScene/systems/TerrainSystem.hpp @@ -103,11 +103,21 @@ public: * Same for Z but Z-inverted (see physicalToVisualZ). */ float physicalToVisualX(float physicalX) const; + /* Inverse: physical X corresponding to a given visual world X. */ + float visualToPhysicalX(float visualX) const; + + /* Half the terrain world size (for coordinate math). */ + float getTerrainWorldHalfSize() const; + /* Convert physical heightmap Z to visual display Z. * Terrain pages render row j at Z = pageMinZ + halfSize - j*step * but the height data lives at Z = pageMinZ + j*step. */ float physicalToVisualZ(float physicalZ) const; + /* Inverse: physical Z that maps to the given visual world Z. + * Uses visual page indexing, unlike physicalToVisualZ. */ + float visualToPhysicalZ(float visualZ) const; + private: void activate(struct TerrainComponent &tc, struct TransformComponent &xform);