Skip to content

Commit

Permalink
Fixed skeletonview to display nodes undistorted by absolute position.
Browse files Browse the repository at this point in the history
    // Nodes are drawn directly using RelPosition, so that the debugview is accurate even in great distances.
    // To do that, we construct a custom modelview matrix.
  • Loading branch information
ohlidalp committed Sep 4, 2023
1 parent 699e203 commit 72d2cd9
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@ void RoR::GfxActor::UpdateDebugView()
}
}

// Nodes are drawn directly using RelPosition, so that the debugview is accurate even in great distances.
// To do that, we need a custom modelview matrix.
Ogre::Affine3 nodes_modelmatrix(m_actor->ar_origin, Ogre::Quaternion::IDENTITY);
World2ScreenConverter nodes2screen(
App::GetCameraManager()->GetCamera()->getViewMatrix(true) * nodes_modelmatrix,
App::GetCameraManager()->GetCamera()->getProjectionMatrix(),
Ogre::Vector2(screen_size.x, screen_size.y)
);

// Skeleton display. NOTE: Order matters, it determines Z-ordering on render
if ((m_debug_view == DebugViewType::DEBUGVIEW_SKELETON) ||
(m_debug_view == DebugViewType::DEBUGVIEW_NODES) ||
Expand All @@ -622,8 +631,8 @@ void RoR::GfxActor::UpdateDebugView()
beams[i].p2->nd_tyre_node || beams[i].p2->nd_rim_node))
continue;

Ogre::Vector3 pos1 = world2screen.Convert(beams[i].p1->AbsPosition);
Ogre::Vector3 pos2 = world2screen.Convert(beams[i].p2->AbsPosition);
Ogre::Vector3 pos1 = nodes2screen.Convert(beams[i].p1->RelPosition);
Ogre::Vector3 pos2 = nodes2screen.Convert(beams[i].p2->RelPosition);

if ((pos1.z < 0.f) && (pos2.z < 0.f))
{
Expand Down Expand Up @@ -677,7 +686,7 @@ void RoR::GfxActor::UpdateDebugView()
if (App::diag_hide_wheels->getBool() && (nodes[i].nd_tyre_node || nodes[i].nd_rim_node))
continue;

Ogre::Vector3 pos_xyz = world2screen.Convert(nodes[i].AbsPosition);
Ogre::Vector3 pos_xyz = nodes2screen.Convert(nodes[i].RelPosition);

if (pos_xyz.z < 0.f)
{
Expand All @@ -702,7 +711,7 @@ void RoR::GfxActor::UpdateDebugView()
(nodes[i].nd_tyre_node || nodes[i].nd_rim_node))
continue;

Ogre::Vector3 pos = world2screen.Convert(nodes[i].AbsPosition);
Ogre::Vector3 pos = nodes2screen.Convert(nodes[i].RelPosition);

if (pos.z < 0.f)
{
Expand Down Expand Up @@ -734,8 +743,8 @@ void RoR::GfxActor::UpdateDebugView()
continue;

// Position
Ogre::Vector3 world_pos = (beams[i].p1->AbsPosition + beams[i].p2->AbsPosition) / 2.f;
Ogre::Vector3 pos_xyz = world2screen.Convert(world_pos);
Ogre::Vector3 rel_pos = (beams[i].p1->RelPosition + beams[i].p2->RelPosition) / 2.f;
Ogre::Vector3 pos_xyz = nodes2screen.Convert(rel_pos);
if (pos_xyz.z >= 0.f)
{
continue; // Behind the camera
Expand Down

0 comments on commit 72d2cd9

Please sign in to comment.