MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / SortTrianglesBackToFront

Method SortTrianglesBackToFront

Source/Graphics/model.cpp:2408–2445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2406};
2407
2408void Model::SortTrianglesBackToFront(const vec3 &camera) {
2409 std::vector<TriData> tris(faces.size() / 3);
2410
2411 unsigned index = 0;
2412 for (int i = 0, len = faces.size() / 3; i < len; ++i) {
2413 tris[i].added = false;
2414 tris[i].score = 0.0f;
2415 tris[i].verts[0] = faces[index++];
2416 tris[i].verts[1] = faces[index++];
2417 tris[i].verts[2] = faces[index++];
2418 }
2419
2420 vec3 center;
2421 for (int i = 0, len = faces.size() / 3; i < len; ++i) {
2422 center[0] = (vertices[tris[i].verts[0] * 3 + 0] +
2423 vertices[tris[i].verts[1] * 3 + 0] +
2424 vertices[tris[i].verts[2] * 3 + 0]) /
2425 3.0f;
2426 center[1] = (vertices[tris[i].verts[0] * 3 + 1] +
2427 vertices[tris[i].verts[1] * 3 + 1] +
2428 vertices[tris[i].verts[2] * 3 + 1]) /
2429 3.0f;
2430 center[2] = (vertices[tris[i].verts[0] * 3 + 2] +
2431 vertices[tris[i].verts[1] * 3 + 2] +
2432 vertices[tris[i].verts[2] * 3 + 2]) /
2433 3.0f;
2434 tris[i].score = distance_squared(center, camera);
2435 }
2436
2437 std::sort(tris.begin(), tris.end(), TriScoreSorter());
2438
2439 index = 0;
2440 for (auto &tri : tris) {
2441 faces[index++] = tri.verts[0];
2442 faces[index++] = tri.verts[1];
2443 faces[index++] = tri.verts[2];
2444 }
2445}

Callers

nothing calls this directly

Calls 6

TriScoreSorterClass · 0.85
distance_squaredFunction · 0.70
sortFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected