3 Sphere::Sphere(const Vec3f
& center
, float radius
, Shader
* shader
)
15 Sphere::Intersect(Ray
& ray
)
17 float A
= ray
.direction().dot(ray
.direction());
18 float C
= (ray
.origin()-m_center
).dot(ray
.origin()-m_center
) - m_radius
*m_radius
;
19 float B
= 2 * ray
.direction().dot(ray
.origin()-m_center
);
24 float root
= sqrtf(B
*B
-4*A
*C
);
25 float t
= (-B
-root
)/(2.0f
*A
);
31 t
= (-B
+root
)/(2.0f
*A
);
32 if( t
< 1e-6 || t
> ray
.t())
40 Sphere::GetNormal(Ray
& ray
)
42 // We don't want to modify the ray (probably this is not needed, but I am
43 // too lazy to think about it now ...)
46 // Surface normal is the difference between intersection and center point
47 if(Intersect(tempRay
)) {
49 Vec3f i
= tempRay
.origin() + tempRay
.direction() * (tempRay
.t() - Epsilon
);
51 Vec3f n
= (i
- m_center
);
55 // no intersection with ray, so no surface normal
This page took 0.048887 seconds and 5 git commands to generate.