vec3 Point::computeNormal(const vec3& point) const { vec3 normal(point - getTransformedPosition()); normalizeOrRandomize(normal); return normal; }
Vector3D Line::computeNormal(const Vector3D& point) const { float d = -dotProduct(tDist,point); float sqrNorm = tDist.getSqrNorm(); float t = 0.0f; if (sqrNorm > 0.0f) { t = -(dotProduct(tDist,tBounds[0]) + d) / sqrNorm; // t is clamped to the segment if (t < 0.0f) t = 0.0f; else if (t > 1.0f) t = 1.0f; } Vector3D normal = point; normal -= tBounds[0] + t * tDist; normalizeOrRandomize(normal); return normal; }
Vector3D Sphere::computeNormal(const Vector3D& point) const { Vector3D normal(point - getTransformedPosition()); normalizeOrRandomize(normal); return normal; }