Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/HFTracer.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
Lint: Inaccurate Copyright Year: Inaccurate Copyright Year | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 26 Lines | |||||
// (N shouldn't be too huge else it'll hurt performance a little when | // (N shouldn't be too huge else it'll hurt performance a little when | ||||
// RayIntersect loops through it all.) | // RayIntersect loops through it all.) | ||||
// CTerrain::CalcPosition implements clamp-to-edge behaviour so the tracer | // CTerrain::CalcPosition implements clamp-to-edge behaviour so the tracer | ||||
// will have that behaviour. | // will have that behaviour. | ||||
static const int MARGIN_SIZE = 64; | static const int MARGIN_SIZE = 64; | ||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
// CHFTracer constructor | // CHFTracer constructor | ||||
CHFTracer::CHFTracer(CTerrain *pTerrain): | CHFTracer::CHFTracer(CTerrain& terrain): | ||||
m_pTerrain(pTerrain), | m_Terrain(terrain), | ||||
m_Heightfield(m_pTerrain->GetHeightMap()), | m_Heightfield(m_Terrain.GetHeightMap()), | ||||
m_MapSize(m_pTerrain->GetVerticesPerSide()), | m_MapSize(m_Terrain.GetVerticesPerSide()), | ||||
m_CellSize((float)TERRAIN_TILE_SIZE), | m_CellSize((float)TERRAIN_TILE_SIZE), | ||||
m_HeightScale(HEIGHT_SCALE) | m_HeightScale(HEIGHT_SCALE) | ||||
{ | { | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
// RayTriIntersect: intersect a ray with triangle defined by vertices | // RayTriIntersect: intersect a ray with triangle defined by vertices | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
// CellIntersect: test if ray intersects either of the triangles in the given | // CellIntersect: test if ray intersects either of the triangles in the given | ||||
// cell - return hit result, and distance to hit, if hit occurred | // cell - return hit result, and distance to hit, if hit occurred | ||||
bool CHFTracer::CellIntersect(int cx, int cz, const CVector3D& origin, const CVector3D& dir, float& dist) const | bool CHFTracer::CellIntersect(int cx, int cz, const CVector3D& origin, const CVector3D& dir, float& dist) const | ||||
{ | { | ||||
bool res=false; | bool res=false; | ||||
// get vertices for this cell | // get vertices for this cell | ||||
CVector3D vpos[4]; | CVector3D vpos[4]; | ||||
m_pTerrain->CalcPosition(cx,cz,vpos[0]); | m_Terrain.CalcPosition(cx,cz,vpos[0]); | ||||
m_pTerrain->CalcPosition(cx+1,cz,vpos[1]); | m_Terrain.CalcPosition(cx+1,cz,vpos[1]); | ||||
m_pTerrain->CalcPosition(cx+1,cz+1,vpos[2]); | m_Terrain.CalcPosition(cx+1,cz+1,vpos[2]); | ||||
m_pTerrain->CalcPosition(cx,cz+1,vpos[3]); | m_Terrain.CalcPosition(cx,cz+1,vpos[3]); | ||||
dist=1.0e30f; | dist=1.0e30f; | ||||
if (RayTriIntersect(vpos[0],vpos[1],vpos[2],origin,dir,dist)) { | if (RayTriIntersect(vpos[0],vpos[1],vpos[2],origin,dir,dist)) { | ||||
res=true; | res=true; | ||||
} | } | ||||
if (RayTriIntersect(vpos[0],vpos[2],vpos[3],origin,dir,dist)) { | if (RayTriIntersect(vpos[0],vpos[2],vpos[3],origin,dir,dist)) { | ||||
res=true; | res=true; | ||||
▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Inaccurate Copyright Year