Ejemplo n.º 1
0
bool isEdgeToBoxCollision(const MVector3 & origin, const MVector3 & dest, const MVector3 & min, const MVector3 & max)
{
	MVector3 nrm[6];
	MVector3 pts[6];
	MVector3 pt;

	nrm[0].set( 1, 0, 0); pts[0] = max;
	nrm[1].set(-1, 0, 0); pts[1] = min;
	nrm[2].set( 0, 1, 0); pts[2] = max;
	nrm[3].set( 0,-1, 0); pts[3] = min;
	nrm[4].set( 0, 0, 1); pts[4] = max;
	nrm[5].set( 0, 0,-1); pts[5] = min;

	if(isPointInBox(origin, min, max) || isPointInBox(dest, min, max))
		return true;

	for(int i=0; i<6; i++)
	{
		if(isEdgePlaneIntersection(origin, dest, pts[i], nrm[i], &pt))
		{
			if(isPointInBox(pt, min, max))
				return true;
		}
	}

	return false;
}
Ejemplo n.º 2
0
/*!
 * \brief Search a node for a point. If its a leaf node, return the element we
 * found it in.
 */
bool Octree::findPointInNode( RCP_Node node,
			      iBase_EntityHandle &found_in_entity,
			      const double coords[3] )
{
    int error = 0;
    bool return_val = false;

    // First check at the node level.
    iBase_EntityHandle *node_elements = 0;
    int node_elements_allocated = 0; 
    int node_elements_size = 0; 
    iMesh_getEntities( d_mesh,
		       node->node_set,
		       d_entity_type,
		       d_entity_topology,
		       &node_elements,
		       &node_elements_allocated,
		       &node_elements_size,
		       &error );
    assert( iBase_SUCCESS == error );

    int i = 0;
    if ( node_elements_size > 0 )
    {
	while ( i < node_elements_size && !return_val )
	{
	    if ( TopologyTools::pointInVolume( d_mesh,
					       node_elements[i],
					       coords ) )
	    {
		return_val = true;
		found_in_entity = node_elements[i];
	    }
	    ++i;
	}
    }

    free( node_elements );

    // If we found the element or we're at a leaf then we're done. Otherwise,
    // recurse through the children if this point is in their bounding box.
    if ( !return_val && !node->is_leaf )
    {
	int j = 0;
	while ( j < 8 && !return_val )
	{
	    if ( isPointInBox( node->children[j]->bounding_box, coords ) )
	    {
		return_val = findPointInNode( node->children[j],
					      found_in_entity,
					      coords );
	    }
	    ++j;
	}
    }

    return return_val;
}