bool CSpaceRestrictorWrapper::inside				(const Fvector &position, float radius) const
{
	Fsphere							sphere;
	sphere.P						= position;
	sphere.R						= radius;

	typedef CShapeData::ShapeVec	ShapeVec;
	ShapeVec::const_iterator		I = object().shapes.begin();
	ShapeVec::const_iterator		E = object().shapes.end();
	for ( ; I != E; ++I) {
		switch ((*I).type) {
			case 0 : {
				Fsphere				temp;
				m_xform.transform_tiny(temp.P,(*I).data.sphere.P);
				temp.R				= (*I).data.sphere.R;
				if (sphere.intersect(temp))
					return			(true);

				continue;
			}
			case 1 : {
				Fmatrix				temp;
				temp.mul_43			(m_xform,(*I).data.box);

				// Build points
				Fvector				vertices;
				Fvector				points[8];
				Fplane				plane;

				vertices.set(-.5f, -.5f, -.5f);	temp.transform_tiny(points[0],vertices);
				vertices.set(-.5f, -.5f, +.5f);	temp.transform_tiny(points[1],vertices);
				vertices.set(-.5f, +.5f, +.5f);	temp.transform_tiny(points[2],vertices);
				vertices.set(-.5f, +.5f, -.5f);	temp.transform_tiny(points[3],vertices);
				vertices.set(+.5f, +.5f, +.5f);	temp.transform_tiny(points[4],vertices);
				vertices.set(+.5f, +.5f, -.5f);	temp.transform_tiny(points[5],vertices);
				vertices.set(+.5f, -.5f, +.5f);	temp.transform_tiny(points[6],vertices);
				vertices.set(+.5f, -.5f, -.5f);	temp.transform_tiny(points[7],vertices);

				plane.build(points[0],points[3],points[5]);	if (plane.classify(sphere.P)>sphere.R) break;
				plane.build(points[1],points[2],points[3]);	if (plane.classify(sphere.P)>sphere.R) break;
				plane.build(points[6],points[5],points[4]);	if (plane.classify(sphere.P)>sphere.R) break;
				plane.build(points[4],points[2],points[1]);	if (plane.classify(sphere.P)>sphere.R) break;
				plane.build(points[3],points[2],points[4]);	if (plane.classify(sphere.P)>sphere.R) break;
				plane.build(points[1],points[0],points[6]);	if (plane.classify(sphere.P)>sphere.R) break;
				return				(true);
			}
			default :				NODEFAULT;
		}
	}

	return							(false);
}
Example #2
0
bool CBone::Pick(float& dist, const Fvector& S, const Fvector& D, const Fmatrix& parent)
{
	Fvector start, dir;
    Fmatrix M; M.mul_43(parent,_LTransform());
    M.invert();
    M.transform_tiny(start,S);
    M.transform_dir(dir,D);
	switch (shape.type){
    case SBoneShape::stBox:		return shape.box.intersect		(start,dir,dist);		
    case SBoneShape::stSphere:  return shape.sphere.intersect	(start,dir,dist);
    case SBoneShape::stCylinder:return shape.cylinder.intersect	(start,dir,dist);
    default:
    	Fsphere S;
        S.P.set(0,0,0);
        S.R=0.025f;
        return S.intersect(start,dir,dist);
    }
}
Example #3
0
//----------------------------------------------------------------------
int CObjectSpace::GetNearest		( xr_vector<ISpatial*>& q_spatial, xr_vector<CObject*>&	q_nearest, const Fvector &point, float range, CObject* ignore_object )
{
	q_spatial.clear_not_free		( );
	// Query objects
	q_nearest.clear_not_free		( );
	Fsphere				Q;	Q.set	(point,range);
	Fvector				B;	B.set	(range,range,range);
	g_SpatialSpace->q_box(q_spatial,0,STYPE_COLLIDEABLE,point,B);

	// Iterate
	xr_vector<ISpatial*>::iterator	it	= q_spatial.begin	();
	xr_vector<ISpatial*>::iterator	end	= q_spatial.end		();
	for (; it!=end; it++)		{
		CObject* O				= (*it)->dcast_CObject		();
		if (0==O)				continue;
		if (O==ignore_object)	continue;
		Fsphere mS				= { O->spatial.sphere.P, O->spatial.sphere.R	};
		if (Q.intersect(mS))	q_nearest.push_back(O);
	}

	return q_nearest.size();
}