MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / CollectSectorCollisionMeshTriangles

Method CollectSectorCollisionMeshTriangles

TombEngine/Game/room.cpp:140–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140void RoomData::CollectSectorCollisionMeshTriangles(CollisionMeshDesc& desc,
141 const FloorInfo& sector,
142 const FloorInfo& sectorNorth, const FloorInfo& sectorSouth,
143 const FloorInfo& sectorEast, const FloorInfo& sectorWest)
144{
145 constexpr auto SECTOR_SURFACE_COUNT = 2;
146
147 struct SectorVertexData
148 {
149 struct SurfaceData
150 {
151 struct TriangleData
152 {
153 bool IsWall = false;
154
155 Vector3 Vertex0 = Vector3::Zero;
156 Vector3 Vertex1 = Vector3::Zero;
157 Vector3 Vertex2 = Vector3::Zero;
158 };
159
160 struct NeighborData
161 {
162 bool IsWall = false;
163
164 Vector3 Vertex0 = Vector3::Zero;
165 Vector3 Vertex1 = Vector3::Zero;
166 };
167
168 bool IsSplit = false;
169 bool IsSplitAngle0 = false;
170
171 TriangleData Tri0 = {};
172 TriangleData Tri1 = {};
173
174 NeighborData NorthNeighbor = {};
175 NeighborData SouthNeighbor = {};
176 NeighborData EastNeighbor = {};
177 NeighborData WestNeighbor = {};
178 };
179
180 SurfaceData Floor = {};
181 SurfaceData Ceil = {};
182 };
183
184 auto getSurfaceTriangleVertexY = [](const FloorInfo& sector, int relX, int relZ, int triID, bool isFloor)
185 {
186 constexpr auto AXIS_OFFSET = -BLOCK(0.5f);
187 constexpr auto HEIGHT_STEP = BLOCK(1 / 32.0f);
188
189 const auto& tri = isFloor ? sector.FloorSurface.Triangles[triID] : sector.CeilingSurface.Triangles[triID];
190
191 relX += AXIS_OFFSET;
192 relZ += AXIS_OFFSET;
193
194 auto normal = tri.Plane.Normal();
195 float relPlaneHeight = -((normal.x * relX) + (normal.z * relZ)) / normal.y;
196 return (int)RoundToStep(tri.Plane.D() + relPlaneHeight, HEIGHT_STEP); // FAILSAFE: Round to circumvent plane query error.
197 };

Callers

nothing calls this directly

Calls 7

RoundToStepFunction · 0.85
IsSurfaceSplitMethod · 0.80
InsertTriangleMethod · 0.80
Vector2iClass · 0.50
Vector3Function · 0.50
IsWallMethod · 0.45
ToVector3Method · 0.45

Tested by

no test coverage detected