本文整理汇总了C++中Box3F::collideLine方法的典型用法代码示例。如果您正苦于以下问题:C++ Box3F::collideLine方法的具体用法?C++ Box3F::collideLine怎么用?C++ Box3F::collideLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box3F
的用法示例。
在下文中一共展示了Box3F::collideLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: castLeafRay
bool AtlasGeomChunkTracer::castLeafRay(const Point2I pos, const Point3F &start,
const Point3F &end, const F32 &startT,
const F32 &endT, RayInfo *info)
{
if(AtlasInstance::smRayCollisionDebugLevel == AtlasInstance::RayCollisionDebugToColTree)
{
const F32 invSize = 1.f / F32(BIT(mTreeDepth-1));
// This is a bit of a hack. But good for testing.
// Do collision against the collision tree leaf bounding box and return the result...
F32 t; Point3F n;
Box3F box;
box.minExtents.set(Point3F(F32(pos.x ) * invSize, F32(pos.y ) * invSize, getSquareMin(0, pos)));
box.maxExtents.set(Point3F(F32(pos.x+1) * invSize, F32(pos.y+1) * invSize, getSquareMax(0, pos)));
//Con::printf(" checking at xy = {%f, %f}->{%f, %f}, [%d, %d]", start.x, start.y, end.x, end.y, pos.x, pos.y);
if(box.collideLine(start, end, &t, &n) && t >= startT && t <= endT)
{
info->t = t;
info->normal = n;
return true;
}
return false;
}
else if( AtlasInstance::smRayCollisionDebugLevel == AtlasInstance::RayCollisionDebugToMesh )
{
bool haveHit = false;
U32 currentIdx = 0;
U32 numIdx = mChunk->mIndexCount;
F32 bestT = F32_MAX;
U32 bestTri = -1;
Point2F bestBary;
while( !haveHit && currentIdx < numIdx )
{
const Point3F& a = mChunk->mVert[ mChunk->mIndex[ currentIdx ] ].point;
const Point3F& b = mChunk->mVert[ mChunk->mIndex[ currentIdx + 1 ] ].point;
const Point3F& c = mChunk->mVert[ mChunk->mIndex[ currentIdx + 2 ] ].point;
F32 localT;
Point2F localBary;
// Do the cast, using our conveniently precalculated ray delta...
if(castRayTriangle(mRayStart, mRayDelta, a,b,c, localT, localBary))
{
if(localT < bestT)
{
// And it hit before anything else we've seen.
bestTri = currentIdx;
bestT = localT;
bestBary = localBary;
haveHit = true;
}
}
currentIdx += 3;
}
// Fill in extra info for the hit.
if(!haveHit)
return false;
// Calculate the normal, we skip that for the initial check.
Point3F norm; // Hi norm!
const Point3F &a = mChunk->mVert[mChunk->mIndex[bestTri+0]].point;
const Point3F &b = mChunk->mVert[mChunk->mIndex[bestTri+1]].point;
const Point3F &c = mChunk->mVert[mChunk->mIndex[bestTri+2]].point;
const Point2F &aTC = mChunk->mVert[mChunk->mIndex[bestTri+0]].texCoord;
const Point2F &bTC = mChunk->mVert[mChunk->mIndex[bestTri+1]].texCoord;
const Point2F &cTC = mChunk->mVert[mChunk->mIndex[bestTri+2]].texCoord;
// Store everything relevant into the info structure.
info->t = bestT;
const Point3F e0 = b-a;
const Point3F e1 = c-a;
info->normal = mCross(e1, e0);
info->normal.normalize();
// Calculate and store the texture coords.
const Point2F e0TC = bTC-aTC;
const Point2F e1TC = cTC-aTC;
info->texCoord = e0TC * bestBary.x + e1TC * bestBary.y + aTC;
// Return true, we hit something!
return true;
}
else
{
// Get the triangle list...
U16 *triOffset = mChunk->mColIndicesBuffer +
mChunk->mColIndicesOffsets[pos.x * BIT(mChunk->mColTreeDepth-1) + pos.y];
//.........这里部分代码省略.........