[Algorithms] Re: [GDAlgorithms-list digest, Vol 1 #103 - 2 msgs]
Brought to you by:
vexxed72
From: Sohaib A. <soh...@us...> - 2000-08-30 06:53:39
|
There you go David... this is from a raytracer i made... hope you understand it... To find out if the ray is tangent to the sphere, the dicriminant must be zero... i think you'll figure it out. COLORREF RayTracer::TraceRay(Vector3D endPoint, Vector3D direction, unsigned int depth) { float Ia, Kd, Ks, Kt, Krg, Ktg; float neta1=1.0f, neta2=0.9f, ns=1000.0f, nt=1000.0f, k=20.0f, dist=100.0f; Sphere *pSphere; Vector3D center, EO, H, H1, L, P, N, normal; float radius, v, disc, d, distfactor, LdotN; float t, tray=200000.0; Vector3D Ipoint, Inormal; COLORREF Ilocalcolor; bool Intersection=FALSE; for(unsigned int io = 0; io < theScene->objectList.size(); io++) { pSphere=(Sphere *)(theScene->objectList[io]); center=pSphere->center; radius=pSphere->radius; // Intersection Code ////////////////////////////////////////////////////////////////////////////////////// EO=center-endPoint; v=EO*direction; disc=radius*radius-((EO*EO)-v*v); if(disc<0) continue; // Rejected, No intersection. // Intersection d=sqrt(disc); t=v-d; // Reject t if a closer intersection is already found i.e. t > t ray if(t<TOL || t>=tray) continue; P=endPoint+direction*t; normal=(P-center)/radius; normal.Normalize(); // P: Intersection point, // normal: Normal vector at P ////////////////////////////////////////////////////////////////////////////////////// Intersection=TRUE; tray=t; Ipoint=P; Inormal=normal; Ilocalcolor=pSphere->color; Ia= pSphere->Ia; Kd = pSphere->Kd; Ks = pSphere->Ks; Kt = pSphere->Kt; Krg= pSphere->Krg; Ktg= pSphere->Ktg; continue; } // End For(Object3D) ........ Regards, Sohaib Athar. ____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1 |