From e202a7c9c343931d83311a79b9a7a91a0c2fd4c3 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 9 Apr 2023 22:09:13 +0200 Subject: [PATCH] Cab mesh - eliminated distortion at large world distances I took advantage of the fact the mesh is regenerated every frame. Instead of choosing an arbitrary mesh origin and generating the mesh from node absolute positions, I place the mesh origin at physics origin and generate the mesh from node relative positions. This creates an illusion of smooth movement within world space while the mesh is actualy not moving, only vertices within the mesh are moving. The same fix can be applied to flextires, flexbodies and flex airfoil, but this commit only fixes the cab mesh as proof of concept. --- source/main/gfx/GfxActor.cpp | 3 ++- source/main/physics/flex/FlexObj.cpp | 18 +++++++----------- source/main/physics/flex/FlexObj.h | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index 20ba62ba67..ac3d09ce9f 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -1815,7 +1815,8 @@ void RoR::GfxActor::UpdateCabMesh() { if ((m_cab_entity != nullptr) && (m_cab_mesh != nullptr)) { - m_cab_scene_node->setPosition(m_cab_mesh->UpdateFlexObj()); + m_cab_scene_node->setPosition(m_simbuf.simbuf_origin); + m_cab_mesh->UpdateFlexObj(); } } diff --git a/source/main/physics/flex/FlexObj.cpp b/source/main/physics/flex/FlexObj.cpp index e006ab631c..12624c1560 100644 --- a/source/main/physics/flex/FlexObj.cpp +++ b/source/main/physics/flex/FlexObj.cpp @@ -183,14 +183,13 @@ int FlexObj::ComputeVertexPos(int tidx, int v, std::vector& submeshe return 0; } -Vector3 FlexObj::UpdateMesh() +void FlexObj::UpdateMesh() { RoR::NodeSB* all_nodes = m_gfx_actor->GetSimNodeBuffer(); - Ogre::Vector3 center=(all_nodes[m_vertex_nodes[0]].AbsPosition+all_nodes[m_vertex_nodes[1]].AbsPosition)/2.0; for (size_t i=0; iUpdateMesh(); + this->UpdateMesh(); m_hw_vbuf->writeData(0, m_hw_vbuf->getSizeInBytes(), m_vertices_raw, true); - return center; } FlexObj::~FlexObj() diff --git a/source/main/physics/flex/FlexObj.h b/source/main/physics/flex/FlexObj.h index 3aec214c56..7f1e4cca74 100644 --- a/source/main/physics/flex/FlexObj.h +++ b/source/main/physics/flex/FlexObj.h @@ -74,7 +74,7 @@ class FlexObj ~FlexObj(); - Ogre::Vector3 UpdateFlexObj(); + void UpdateFlexObj(); void ScaleFlexObj(float factor); private: @@ -88,7 +88,7 @@ class FlexObj /// Compute vertex position in the vertexbuffer (0-based offset) for node `v` of triangle `tidx` int ComputeVertexPos(int tidx, int v, std::vector& submeshes); - Ogre::Vector3 UpdateMesh(); + void UpdateMesh(); Ogre::MeshPtr m_mesh; std::vector m_submeshes;