예제 #1
0
IntersectData AABB::IntersectAABB(const AABB& other) const
{
	//The distance between the AABB's on the X, Y, and Z axis.
	//Computed twice because there are two possible valid distances, depending
	//on the location of the AABB's.
	Vector3f distances1 = other.GetMinExtents() - m_maxExtents;
	Vector3f distances2 = m_minExtents - other.GetMaxExtents();

	//The correct distances will be whichever distance is larger for that
	//particular axis.
	Vector3f distances = Vector3f(distances1.Max(distances2));

	float maxDistance = distances.Max();
	
	//If there is any distance between the two AABB's, then max distance will
	//be greather than or equal to 0. If there is distance between the two
	//AABBs, then they aren't intersecting.
	//
	//Therefore, if the AABBs are intersecting, then the distance between them
	//must be less than zero.

	//TODO: This might actually need to return the minDistance if they are 
	//intersecting.
	return IntersectData(maxDistance < 0, maxDistance);
}
예제 #2
0
PointLight::PointLight(const Vector3f& color, float intensity, const Attenuation& attenuation, const Shader& shader) :
	BaseLight(color, intensity, shader),
	m_attenuation(attenuation)
{
	float a = m_attenuation.GetExponent();
	float b = m_attenuation.GetLinear();
	float c = m_attenuation.GetConstant() - COLOR_DEPTH * intensity * color.Max();
	
	m_range = (-b + sqrtf(b*b - 4*a*c))/(2*a);
}