⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sphere.c

📁 This contains Graphic gems code
💻 C
字号:
#include "Sphere.h"#include "solver.h"/*************************************************************************									** This method computes the intersection between a ray and the sphere.	** It returns the distance between the origin of the ray and the closest ** point of intersection (or 0.0 if no intersection occurs).		**									*************************************************************************/double Sphere::intersect(vec3& ray_org, vec3& ray_dir){double	c[3],			    // coefficients of the quadric equation.	s[2];			    // solutions of the quadric equationvec3	d = ray_org - pos;	    // vector from the center of the sphere to				    // the origin of the ray.// compute the coefficients of the resolvent equationc[2] = 1.0;c[1] = 2.0 * ray_dir * d;c[0] = d * d - radius * radius;// return the closest intersection pointreturn closest_intersection(s, solveQuadric(c, s));}/*************************************************************************									** This method computes the normal vector to the sphere at the point of	** intersection. (NB: normalization is "built-in" for the sphere).	**									*************************************************************************/vec3 Sphere::normalAt(vec3& p){ return (p - pos) / radius; }/*************************************************************************									** Input from stream.							**									*************************************************************************/istream& operator >> (istream& s, Sphere& a){s >> *((Primitive*) &a);s >> a.radius;return s;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -