コード例 #1
0
	bool OctreeObject::ClipSegment(fsVector3& A, fsVector3& B, const fsVector3& Min, const fsVector3& Max)
	{
		fsVector3 S = A;
		fsVector3 D = (B - A);

		float t0 = 0.0f, t1 = 1.0f;

		if (!ClipSegment(Min.x(), Max.x(), A.x(), B.x(), D.x(), t0, t1)) 
		{
			return false;
		}

		if (!ClipSegment(Min.y(), Max.y(), A.y(), B.y(), D.y(), t0, t1)) 
		{
			return false;
		}

		if (!ClipSegment(Min.z(), Max.z(), A.z(), B.z(), D.z(), t0, t1)) 
		{
			return false;
		}

		A = S + D * t0;
		B = S + D * t1;

		return true;
	}
コード例 #2
0
ファイル: geometry.cpp プロジェクト: ezhangle/DrawSomething
bool SegmentIntersectsAABB(const vec3& v1, const vec3& v2, const AABB& b, CCollisionResult& tr)
{
	float tmin = 0;
	float tmax = 1;

	vec3 vecDir = v2 - v1;

	if (!ClipSegment(b.m_mins.x, b.m_maxs.x, v1.x, v2.x, vecDir.x, tmin, tmax))
		return false;

	if (!ClipSegment(b.m_mins.y, b.m_maxs.y, v1.y, v2.y, vecDir.y, tmin, tmax))
		return false;

	if (!ClipSegment(b.m_mins.z, b.m_maxs.z, v1.z, v2.z, vecDir.z, tmin, tmax))
		return false;

	float flFraction = (tmin < 0) ? 0 : tmin;
	if (flFraction > tr.flFraction)
		return false;

	tr.m_hit = true;
	tr.bStartInside = tmin < 0;
	tr.flFraction = (float)flFraction;
	//tr.vecHit not set and not used.
	//tr.vecNormal not set and not used.

	return true;
}
コード例 #3
0
	bool OctreeObject::RayIntersect(const fsVector3& _f3RayBegin, const fsVector3& _f3RayEnd, fsVector3& _f3Intersect1, fsVector3& _f3Intersect2)
	{
		_f3Intersect1 = _f3RayBegin;
		_f3Intersect2 = _f3RayEnd;
		return ClipSegment(_f3Intersect1, _f3Intersect2, m_vPoints[EOctreeAABB_BOTTOMLEFTTNEAR], m_vPoints[EOctreeAABB_TOPRIGHTTFAR]);
	}