MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / SortForPerspective

Method SortForPerspective

src/Nazara/Graphics/ForwardRenderQueue.cpp:757–784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

755 }
756
757 void ForwardRenderQueue::SortForPerspective(const AbstractViewer* viewer)
758 {
759 Planef nearPlane = viewer->GetFrustum().GetPlane(FrustumPlane_Near);
760 Vector3f viewerPos = viewer->GetEyePosition();
761
762 for (auto& pair : layers)
763 {
764 Layer& layer = pair.second;
765
766 std::sort(layer.depthSortedMeshes.begin(), layer.depthSortedMeshes.end(), [&layer, &viewerPos] (std::size_t index1, std::size_t index2)
767 {
768 const Spheref& sphere1 = layer.depthSortedMeshData[index1].obbSphere;
769 const Spheref& sphere2 = layer.depthSortedMeshData[index2].obbSphere;
770
771 return viewerPos.SquaredDistance(sphere1.GetPosition()) > viewerPos.SquaredDistance(sphere2.GetPosition());
772 });
773
774 std::sort(layer.depthSortedSprites.begin(), layer.depthSortedSprites.end(), [&layer, &viewerPos] (std::size_t index1, std::size_t index2)
775 {
776 const Vector3f& pos1 = layer.depthSortedSpriteData[index1].vertices[0].position;
777 const Vector3f& pos2 = layer.depthSortedSpriteData[index2].vertices[0].position;
778
779 return viewerPos.SquaredDistance(pos1) > viewerPos.SquaredDistance(pos2);
780 });
781
782 SortBillboards(layer, nearPlane);
783 }
784 }
785
786 /*!
787 * \brief Handle the invalidation of an index buffer

Callers

nothing calls this directly

Calls 4

GetEyePositionMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
GetPositionMethod · 0.45

Tested by

no test coverage detected