All pastes #735641 Raw Edit

Unbenannt

public text v1 · immutable
·published 2007-10-13 20:13 UTC
rendered paste body
double r2 = m_radius*m_radius;
	Vector3 M = m_center-ray.point;
	Vector3 P = ray.direction * (M).dot(ray.direction);

	double d = (M-P).lengthSquared();
	double t = P.length();
	if (d > r2)
		return false;
  
	if (d < r2)
	{
		P = P - ray.direction * sqrt(r2-d*d);
	}

	if (t < iData->t && t > ray.min_t && t < ray.max_t)
	{
		iData->t = t;
		iData->material = m_material;
		iData->color = getColor();
		iData->position = ray.point + P;
		return true;
	}