本文整理汇总了C++中AABB::Intersection方法的典型用法代码示例。如果您正苦于以下问题:C++ AABB::Intersection方法的具体用法?C++ AABB::Intersection怎么用?C++ AABB::Intersection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AABB
的用法示例。
在下文中一共展示了AABB::Intersection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UnCollide
void UnCollide(GameObject* go, const Vec3f& oldPos, const AABB& aabb)
{
/*
Move back so not interpenetrating:
Boxes now intersect in all axes. Moving away by penetration depth in any
axis will resolve the intersection. To choose which axis, use the previous
position. E.g. if previously not intersecting in X, move away in X axis.
*/
// Intersecton region
AABB ir = aabb.Intersection(go->GetAABB());
Vec3f goPos = go->GetPos();
AABB oldBox = go->GetAABB();
Vec3f move = oldPos - goPos;
oldBox.Translate(move);
// Oldbox should NOT be intersecting in one or more axes
Vec3f penDist(
ir.GetMax(0) - ir.GetMin(0),
ir.GetMax(1) - ir.GetMin(1),
ir.GetMax(2) - ir.GetMin(2));
penDist *= 1.01f; // move away a bit more to be sure of clearing the collision
if (oldBox.GetMax(0) < aabb.GetMin(0))
{
// Old box to left of box, so move away to the left
goPos.x -= penDist.x;
}
else if (oldBox.GetMin(0) > aabb.GetMax(0))
{
goPos.x += penDist.x;
}
/*
else if (oldBox.GetMax(1) < aabb.GetMin(1))
{
goPos.y -= penDist.y;
}
else if (oldBox.GetMin(1) > aabb.GetMax(1))
{
goPos.y += penDist.y;
}
*/
else if (oldBox.GetMax(2) < aabb.GetMin(2))
{
goPos.z -= penDist.z;
}
else if (oldBox.GetMin(2) > aabb.GetMax(2))
{
goPos.z += penDist.z;
}
go->SetPos(goPos);
}
示例2: construct
// recursive construction algorithm
//void Kdtree::construct(unsigned int fn, const AABB& box, const std::list<unsigned int>& triList, AABB * bounds, unsigned int depth)
//void Kdtree::construct(unsigned int fn, AABB& box, std::list<IPrimitive*>& primList, AABB * bounds, unsigned int depth)
void Kdtree::construct(unsigned int fn, AABB& box, unsigned int size,
unsigned int depth, bool isLeft, unsigned int rIndex,
unsigned int pre_size, bool dsize, int tries)
{
//BSPNode *node = &m_pTree[fn];
//printf("max num: %i\n", m_pTree.max_size());
//m_pTree.assign(BSPNode(), fn);
BSPNode *node = &m_pTree[fn];
//unsigned int size = (unsigned int)primList.size();
//std::list<IPrimitive*>::iterator p;
//printf(".");
// if end condition met
// if(abs(previous size - size) <= 3 ...
if((int)abs((int)(pre_size-size)) <= 3)
{
dsize = true;
tries++;
}
else
{
dsize = false;
tries = 0;
}
if(size <= m_MaxItemPerNode || depth >= m_MaxDepth || (dsize && tries == 3))
{
IPrimitive** myList = 0;
if(size > 0)
myList = new IPrimitive*[size];
//std::list<IPrimitive*>* myList = new std::list<IPrimitive*>;
if(depth == 0)
{
std::list<IPrimitive*>::iterator tit;
int i = 0;
for(tit = m_PrimList.begin(); tit != m_PrimList.end(); tit++, i++)
myList[i] = (*tit);
}
else if(isLeft)
{
for(unsigned int i = 0; i < size; i++)
myList[i] = leftBOX[i];
}
else
{
for(unsigned int i = 0; i < size; i++)
myList[i] = rightBOX[rIndex+i];
}
node->initLeaf(size, myList);
// increment counts
m_TotalTreeTri += size;
totalLeaf++;
return; // leaf with triangle
}
// each node must have a split axis and split position
int axis = 0;
float splitpos = 0;
unsigned int i;
#ifdef SAH
AABB tbox;
// build up information of bounding box and edges
if(depth == 0)
{
i = 0;
std::list<IPrimitive*>::iterator tit;
for(tit = m_PrimList.begin(); tit != m_PrimList.end(); tit++, i++)
{
tbox = (*tit)->getAABB();
AABB* mybox = &(box.Intersection(tbox)); // get intersection of triangle box + bounding box of this node
Point3 minp = mybox->getPos();
Point3 maxp = minp + mybox->getSize();
// add x position to the list
edge[0][i*2].set(minp.X(), (*tit), true);
edge[0][i*2+1].set(maxp.X(), (*tit), false);
// add y
edge[1][i*2].set(minp.Y(), (*tit), true);
edge[1][i*2+1].set(maxp.Y(), (*tit), false);
// add z
edge[2][i*2].set(minp.Z(), (*tit), true);
edge[2][i*2+1].set(maxp.Z(), (*tit), false);
}
}
else if(isLeft)
{
for(i = 0; i < size; i++)
{
tbox = leftBOX[i]->getAABB();
AABB* mybox = &(box.Intersection(tbox)); // get intersection of triangle box + bounding box of this node
Point3 minp = mybox->getPos();
Point3 maxp = minp + mybox->getSize();
// add x position to the list
//.........这里部分代码省略.........