//---------------------------------------------------------------------------------------------
bool traceEye( e_Ray *ray, e_RayState *state )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) {
BSPStackElem fix_stack[80];
BSPStackElem *stack;
UINT stack_ptr;
bool del_stack;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
BSPNode *node = state->limitBSP;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Vector3f P;
float midPlane, lightPos, t, d, dmax, dmin;
BSPNode *nearChild, *midChild, *farChild;
bool inRanges;
int cx, cy, cz;
BOOL mid = FALSE;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if( state->opt->bspDepth <= 40 ) {
stack = fix_stack;
del_stack = false;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) } else {
stack = new BSPStackElem [ state->opt->bspDepth * 2 ];
del_stack = true;
}
stack_ptr = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while( node )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
node->createChildren( state->opt->bspSize, state->opt->bspDepth,
state->opt->bspMethod, node->depth, node->axis );
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while( node->child && !mid )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
switch( node->axis )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
case X_AXIS:
cx = 0; cy = 1; cz = 2; break;
case Y_AXIS:
cx = 1; cy = 2; cz = 0; break;
case Z_AXIS:
cx = 2; cy = 0; cz = 1; break;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
inRanges = true;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
midPlane = node->child[0].box.range[cx].max;
lightPos = ray->pos.arr[cx];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
t = ( midPlane - ray->src.arr[cx] ) * ray->inv_dir.arr[cx];
if( t <= 0.0f )
inRanges = false;
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
P.arr[cx] = midPlane;
P.arr[cy] = ray->src.arr[cy] + ray->dir.arr[cy] * t;
d = P.arr[cy];
dmax = node->box.range[cy].max;
dmin = node->box.range[cy].min;
if( d < dmin || d > dmax )
inRanges = false;
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
P.arr[cz] = ray->src.arr[cz] + ray->dir.arr[cz] * t;
d = P.arr[cz];
dmax = node->box.range[cz].max;
dmin = node->box.range[cz].min;
if( d < dmin || d > dmax )
inRanges = false;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if( lightPos < midPlane )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
nearChild = &node->child[0];
midChild = node;
farChild = &node->child[1];
}
else if( lightPos > midPlane )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
nearChild = &node->child[1];
midChild = node;
farChild = &node->child[0];
}
else if( lightPos == midPlane )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if( ray->dir.arr[cx] > 0.0f )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
nearChild = &node->child[1];
midChild = NULL;
farChild = NULL;
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
nearChild = &node->child[0];
midChild = NULL;
farChild = NULL;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
node = nearChild;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
node->createChildren( state->opt->bspSize, state->opt->bspDepth,
state->opt->bspMethod, node->depth, node->axis );
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if( inRanges )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if( farChild ) {
stack[ stack_ptr ].node = farChild;
stack[ stack_ptr ].mid = FALSE;
stack[ stack_ptr ].ray_entry = P;
++ stack_ptr;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if( midChild ) {
stack[ stack_ptr ].node = midChild;
stack[ stack_ptr ].mid = TRUE;
stack[ stack_ptr ].ray_entry = ray->pos;
++ stack_ptr;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
state->limitBSP = node;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if( intersectEye( ray, state ) ) {
if( del_stack )
delete [] stack;
return true;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if( stack_ptr != 0 ) {
-- stack_ptr;
node = stack[ stack_ptr ].node;
mid = stack[ stack_ptr ].mid;
ray->pos = stack[ stack_ptr ].ray_entry;
} else
node = NULL;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if( del_stack )
delete [] stack;
return false;
}
|