MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / computeMinMaxGridCoordinates

Method computeMinMaxGridCoordinates

src/collision/HeightField.cpp:220–253  ·  view source on GitHub ↗

Compute the min/max grid coords corresponding to the intersection of the AABB of the height field and the AABB to collide

Source from the content-addressed store, hash-verified

218// Compute the min/max grid coords corresponding to the intersection of the AABB of the height field and
219// the AABB to collide
220void HeightField::computeMinMaxGridCoordinates(uint32* minCoords, uint32* maxCoords, const AABB& aabbToCollide) const {
221
222 // Clamp the min/max coords of the AABB to collide inside the height field AABB
223 Vector3 minPoint = Vector3::max(aabbToCollide.getMin(), mBounds.getMin());
224 minPoint = Vector3::min(minPoint, mBounds.getMax());
225
226 Vector3 maxPoint = Vector3::min(aabbToCollide.getMax(), mBounds.getMax());
227 maxPoint = Vector3::max(maxPoint, mBounds.getMin());
228
229 // Translate the min/max points such that the we compute grid points from [0 ... mNbWidthGridPoints]
230 // and from [0 ... mNbLengthGridPoints] because the AABB coordinates range are [-mWdith/2 ... mWidth/2]
231 // and [-mLength/2 ... mLength/2]
232 const Vector3 translateVec = mBounds.getExtent() * decimal(0.5);
233 minPoint += translateVec;
234 maxPoint += translateVec;
235
236 assert(minPoint.x >= 0);
237 assert(minPoint.y >= 0);
238 assert(minPoint.z >= 0);
239 assert(maxPoint.x >= 0);
240 assert(maxPoint.y >= 0);
241 assert(maxPoint.z >= 0);
242
243 // Convert the floating min/max coords of the AABB into closest integer
244 // grid values (note that we use the closest grid coordinate that is out
245 // of the AABB)
246 minCoords[0] = static_cast<int>(minPoint.x + 0.5) - 1;
247 minCoords[1] = static_cast<int>(minPoint.y + 0.5) - 1;
248 minCoords[2] = static_cast<int>(minPoint.z + 0.5) - 1;
249
250 maxCoords[0] = static_cast<int>(maxPoint.x + 0.5) + 1;
251 maxCoords[1] = static_cast<int>(maxPoint.y + 0.5) + 1;
252 maxCoords[2] = static_cast<int>(maxPoint.z + 0.5) + 1;
253}
254
255// Raycast method with feedback information
256/// Note that only the first triangle hit by the ray in the mesh will be returned, even if

Callers

nothing calls this directly

Calls 1

getExtentMethod · 0.80

Tested by

no test coverage detected