rodecomp/Source/Contents/World/WorldTerrainPicking.cpp
ragnarok-clanker 750f35b3dd Maintenance: [forced, user-approved] Family W5 (resubmission of 10276 without the STATIC lines; replaces agent 2's 10270, returned by
Batch #10277 by ragnarok-clanker: forced by an admin (17 lower score(s), 63 changed function(s)); checked with 414 compiled unit(s), including every includer of Source/Contents/Effects/RagEffect.h, Source/Contents/Models/ModelActor.h, Source/Contents/Models/ModelNode.h, Source/Contents/Models/ModelRendering.h, Source/Contents/World/WorldModelView.h, Source/Contents/World/WorldOcclusion.h, Source/Contents/World/WorldTerrainPicking.h, Source/Render/Projection/RendererViewport.h, Source/Render/Projection/RenderProjection.h.
Deletes: Source/Render/Projection/RenderProjection.h
2026-11-03 15:49:14 +00:00

44 lines
1.2 KiB
C++

#include "Contents/World/WorldRayQuery.h"
#include "Contents/World/WorldSpatialTree.h"
#include "Render/Renderer.h"
#include "Contents/World/WorldTerrainPicking.h"
#include "Resource/World/TerrainResource.h"
// OFFSET: 0x00CD4060
// FUNCTION: fn_21274
bool PickScreenTerrain(
int x, int y, const float* origin, const float* cameraMatrix, WorldSpatialTree& root, int& column, int& row
) {
WorldRayQuery query;
float ray[6]{};
g_renderer->viewport.Ray(x, y, origin, cameraMatrix, ray);
query.Collect(ray, &root);
float nearest = 999999.0f;
float result = nearest;
for (WorldSpatialTree* node : query.nodes) {
C3dAttr* terrain = node->terrain;
int candidateRow = node->terrainCells[1];
while (candidateRow <= node->terrainCells[3]) {
int candidateColumn = node->terrainCells[0];
while (candidateColumn <= node->terrainCells[2]) {
const float distance = terrain->RayDistance(ray, candidateColumn, candidateRow);
if (nearest > distance) {
nearest = distance;
column = candidateColumn;
row = candidateRow;
}
result = nearest;
candidateColumn = candidateColumn + 1;
}
candidateRow = candidateRow + 1;
}
}
return result < 999999.0f;
}