コード例 #1
0
ファイル: Intersect.cpp プロジェクト: saggita/r5ge
bool Intersect::RayBounds (const Vector3f& origin, const Vector3f& dir, const Bounds& bounds)
{
	const Vector3f& max		= bounds.GetMax();
	const Vector3f& center	= bounds.GetCenter();

	Vector3f ext  (max		- center);
	Vector3f diff (origin	- center);

	if (Float::Abs(diff.x) > ext.x && Float::IsProductPositive(diff.x, dir.x)) return false;
	if (Float::Abs(diff.y) > ext.y && Float::IsProductPositive(diff.y, dir.y)) return false;
	if (Float::Abs(diff.z) > ext.z && Float::IsProductPositive(diff.z, dir.z)) return false;

	Vector3f adir (Float::Abs(dir.x), Float::Abs(dir.y), Float::Abs(dir.z));

	float a = dir.y * diff.z - dir.z * diff.y;
	float b = ext.y * adir.z + ext.z * adir.y;

	if (Float::Abs(a) > b) return false;
	
	a = dir.z * diff.x - dir.x * diff.z;
	b = ext.x * adir.z + ext.z * adir.x;

	if (Float::Abs(a) > b) return false;
	
	a = dir.x * diff.y - dir.y * diff.x;
	b = ext.x * adir.y + ext.y * adir.x;

	return !(Float::Abs(a) > b);
}
コード例 #2
0
ファイル: OutdoorLevel.cpp プロジェクト: alanzw/JimEngine
void GetQChildBounds(const Bounds &bounds, int childnum, Bounds &child)
{
    Vect center = bounds.GetCenter();

    child.Max.y = bounds.Max.y;
    child.Min.y = bounds.Min.y;

    if(childnum > 1)    {child.Min.z = center.z;     child.Max.z = bounds.Max.z;  childnum -= 2;}
    else                {child.Min.z = bounds.Min.z; child.Max.z = center.z;}

    if(childnum == 1)   {child.Min.x = center.x;     child.Max.x = bounds.Max.x;}
    else                {child.Min.x = bounds.Min.x; child.Max.x = center.x;}
}
コード例 #3
0
ファイル: Intersect.cpp プロジェクト: saggita/r5ge
bool Intersect::BoundsSphere (const Bounds& bounds, const Vector3f& pos, float radius)
{
	const Vector3f& center = bounds.GetCenter();
	Vector3f dir (center - pos);
	float mag = dir.Magnitude();

	if (mag > radius)
	{
		dir /= mag;
		dir *= radius;
		return bounds.Contains(pos + dir);
	}
	return true;
}