本文整理汇总了C++中ObjectList::getPrimitive方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectList::getPrimitive方法的具体用法?C++ ObjectList::getPrimitive怎么用?C++ ObjectList::getPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectList
的用法示例。
在下文中一共展示了ObjectList::getPrimitive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
int ireon::kd_tree::KdTree<T>::FindNearest( Ray& a_Ray, real& a_Dist, T*& a_Prim , kdstack<T> * const m_Stack, const aabb* extendBox)
{
real tnear = 0, tfar = a_Dist, t;
int retval = 0;
Vector3 p1 = extendBox->getPos();
Vector3 p2 = p1 + extendBox->getSize();
Vector3 D = a_Ray.getDirection(), O = a_Ray.getOrigin();
for ( int i = 0; i < 3; i++ ) if (D.val[i] < 0)
{
if (O.val[i] < p1.val[i]) return 0;
}
else if (O.val[i] > p2.val[i]) return 0;
// clip ray segment to box
for ( int i = 0; i < 3; i++ )
{
real pos = O.val[i] + tfar * D.val[i];
if (D.val[i] < 0)
{
// clip end point
if (pos < p1.val[i]) tfar = tnear + (tfar - tnear) * ((O.val[i] - p1.val[i]) / (O.val[i] - pos));
// clip start point
if (O.val[i] > p2.val[i]) tnear += (tfar - tnear) * ((O.val[i] - p2.val[i]) / (tfar * D.val[i]));
}
else
{
// clip end point
if (pos > p2.val[i]) tfar = tnear + (tfar - tnear) * ((p2.val[i] - O.val[i]) / (pos - O.val[i]));
// clip start point
if (O.val[i] < p1.val[i]) tnear += (tfar - tnear) * ((p1.val[i] - O.val[i]) / (tfar * D.val[i]));
}
if (tnear > tfar) return 0;
}
// init stack
int entrypoint = 0, exitpoint = 1;
// init traversal
KdTreeNode<T>* farchild, *currnode;
currnode = getRoot();
m_Stack[entrypoint].t = tnear;
if (tnear > 0.0f) m_Stack[entrypoint].pb = O + D * tnear;
else m_Stack[entrypoint].pb = O;
m_Stack[exitpoint].t = tfar;
m_Stack[exitpoint].pb = O + D * tfar;
m_Stack[exitpoint].node = 0;
// traverse kd-tree
while (currnode)
{
while (!currnode->isLeaf())
{
real splitpos = currnode->getSplitPos();
int axis = currnode->getAxis();
if (m_Stack[entrypoint].pb.val[axis] <= splitpos)
{
if (m_Stack[exitpoint].pb.val[axis] <= splitpos)
{
currnode = currnode->getLeft();
continue;
}
if (m_Stack[exitpoint].pb.val[axis] == splitpos)
{
currnode = currnode->getRight();
continue;
}
currnode = currnode->getLeft();
farchild = currnode + 1; // GetRight();
}
else
{
if (m_Stack[exitpoint].pb.val[axis] > splitpos)
{
currnode = currnode->getRight();
continue;
}
farchild = currnode->getLeft();
currnode = farchild + 1; // GetRight();
}
t = (splitpos - O.val[axis]) / D.val[axis];
int tmp = exitpoint++;
if (exitpoint == entrypoint) exitpoint++;
m_Stack[exitpoint].prev = tmp;
m_Stack[exitpoint].t = t;
m_Stack[exitpoint].node = farchild;
m_Stack[exitpoint].pb.val[axis] = splitpos;
int nextaxis = m_Mod[axis + 1];
int prevaxis = m_Mod[axis + 2];
m_Stack[exitpoint].pb.val[nextaxis] = O.val[nextaxis] + t * D.val[nextaxis];
m_Stack[exitpoint].pb.val[prevaxis] = O.val[prevaxis] + t * D.val[prevaxis];
}
ObjectList<T>* list = currnode->getList();
real dist = m_Stack[exitpoint].t;
while (list)
{
T* pr = list->getPrimitive();
int result;
m_Intersections++;
if (result = intersect( pr, a_Ray, dist ))
{
retval = result;
a_Dist = dist;
a_Prim = pr;
}
//.........这里部分代码省略.........