6 #include <ngl/Colour.h>
22 float sphere_center_x = this->
getCenter().m_x;
23 float sphere_center_y = this->
getCenter().m_y;
24 float sphere_center_z = this->
getCenter().m_z;
27 float b = (2*(ray_origin_x - sphere_center_x)*ray_direction_x)
28 + (2*(ray_origin_y - sphere_center_y)*ray_direction_y)
29 + (2*(ray_origin_z - sphere_center_z)*ray_direction_z);
30 float c = pow(ray_origin_x - sphere_center_x, 2)
31 + pow(ray_origin_y - sphere_center_y, 2)
32 + pow(ray_origin_z - sphere_center_z, 2)
34 float discriminant = b*b - 4*c;
41 float root_1 = ((-1*b - sqrt(discriminant))/2) - 0.000001;
51 float root_2 = ((sqrt(discriminant)-b)/2) - 0.000001;
virtual ngl::Vec3 getNormalAt(ngl::Vec3 _p)
Calculates what the normal is at a given point of a sphere. It doesn't check whether it is on the sur...
ngl::Vec3 getOrigin()
Getter method for the origin.
virtual float getIntersection(geo::Ray &_ray)
Calculates the intersection of the passed ray with the sphere according to the parametric form of a r...
A class for implicit sphere definitions.
float getRadius() const
Returns radius of a sphere.
ngl::Vec3 getCenter() const
Returns center of a sphere.
ngl::Vec3 m_center
Center of the sphere, in world space coordinates.
ngl::Vec3 getDirection()
Getter method for the direction.