コード例 #1
0
ファイル: manipulator.cpp プロジェクト: blackvladimir/pyplasm
bool Manipulator::canManipulate(Ray3f ray,Box3f box,Mat4f* T)
{
	//nothing to do
	if (!box.isValid())
		return false;

	Vec3f size=box.size();

	Mat4f Direct=(*T) * getTransformationToBox(box);
    Mat4f Inverse=Direct.invert();

    // the ray is in world coordinate
    Vec3f P1=Inverse * (ray.origin        );
    Vec3f P2=Inverse * (ray.origin+ray.dir);
    
    // should be the unit bounding ball not the bounding box, but seems good enough (probably better)
    // is objects does not overlap too much!
	float epsilon=1e-4f;
	Box3f unit_box(
		Vec3f(
			size[0]?-1:-epsilon,
			size[1]?-1:-epsilon,
			size[2]?-1:-epsilon),
		Vec3f(
			size[0]?+1:+epsilon,
			size[1]?+1:+epsilon,
			size[2]?+1:+epsilon));


	float tmin,tmax;
    return (Ray3f(P1,P2-P1).intersectBox(tmin,tmax,unit_box) && tmin>0);
}
コード例 #2
0
ファイル: manipulator.cpp プロジェクト: blackvladimir/pyplasm
void Manipulator::setObject(Box3f box,Mat4f* T)
{
	this->T=T;
    this->box=box;
	this->ref=INVALID;
	this->bRunning=false;

	if (box.isValid())
		this->T_to_box=getTransformationToBox(box);
}