Render::Render (Scene s) { int i,j; Video v; Reta r; Vetor du,dv; Vetor ini,pos; PointsShaded=0; RaysShooted=0; du=s.Proj.u*(Float (s.Wx)/Float (s.Rx)); dv=s.Proj.v*(Float (s.Wy)/Float (s.Ry)); ini=s.Proj.o+dv*s.y1; v.WaitForKey (); v.Init (); for (j=s.y1; j<=s.y2; j++) { pos=ini+du*s.x1; for (i=s.x1; i<=s.x2; i++) { r.TwoPoints (s.Obs,pos); r.Normalize (); v.Point (i,j,v.Inclui (Cor (ShootRay (r,s,0)))); PointsShaded++; pos+=du; if (v.KeyPressed ()) { v.Close (); return; } } ini+=dv; } v.WaitForKey (); v.Close (); }
Vector ShootRay (Reta R, double Relative) { PointList *P; Point *hit; Vector Target; Vector color; Vector Normal; Vector Zero (0,0,0); Reta S; if (Relative<reflection) return Zero; RaysShooted++; P=new PointList; scene->Intersect (R,P); hit=P->First (); if (hit!=NULL) { Target=R.O+R.R*hit->t; Normal=hit->owner->Normal (Target); color=lightlist->Shade (Target,Normal,scene); delete P; if (hit->owner->surface->GetKs()!=0.0) { S.O=Target+Normal*epsilon; S.R=R.R-Normal*(R.R*Normal)*2.0; return hit->owner->surface->Apply (color,ShootRay (S,Relative*hit->owner->surface->GetKs())); } else return hit->owner->surface->Apply (color,Zero); } else { delete P; return Zero; } }
void Draw (int x1, int y1, int length) { Vector t1,t2,t3,t4; int x2,y2; x2=x1+length-1; y2=y1+length-1; if (length==2) { Pixels+=4; PutPixel (x1,y1,MakeRGB (ShootRay (BuildReta (x1,y1),1.0))); PutPixel (x2,y1,MakeRGB (ShootRay (BuildReta (x2,y1),1.0))); PutPixel (x1,y2,MakeRGB (ShootRay (BuildReta (x1,y2),1.0))); PutPixel (x2,y2,MakeRGB (ShootRay (BuildReta (x2,y2),1.0))); } else { int factor; t1=ShootRay (BuildReta (x1,y1),1.0); t2=ShootRay (BuildReta (x2,y1),1.0); t3=ShootRay (BuildReta (x1,y2),1.0); t4=ShootRay (BuildReta (x2,y2),1.0); if (diff (t1,t2)+diff (t2,t3)+diff (t3,t4)+diff (t4,t1)>threshold) { factor=length/2; Draw (x1,y1,factor); Draw (x1+factor,y1,factor); Draw (x1,y1+factor,factor); Draw (x1+factor,y1+factor,factor); } else { int i,j; double alpha,beta; Vector p1,p2,p3; Pixels+=4; if (interpolation) { alpha=1.0/double (x2-x1); beta=1.0/double (y2-y1); p1=t1; p2=t3; for (i=x1; i<=x2; i++) { p3=p1; for (j=y1; j<=y2; j++) { PutPixel (i,j,MakeRGB (p3)); p3+=(p2-p1)*beta; } p1+=(t2-t1)*alpha; p2+=(t4-t3)*alpha; } } else { int i,j; for (i=x1; i<=x2; i++) for (j=y1; j<=y2; j++) PutPixel (i,j,MakeRGB (t1)); } } } }
void CCameraRayScan::ShootRayInt(ECameraRays camRay, const Vec3 &rayPos, const Vec3 &rayDir, const float &len, IPhysicalEntity **pSkipEnts, int numSkipEnts) { if(camRay < eNUM_RAYS) { if(m_rayInfo[camRay].rayID == INVALID_RAY_ID) { m_rayInfo[camRay].dir = rayDir; m_rayInfo[camRay].rayID = ShootRay(rayPos, rayDir * len, g_objTypes, g_geomFlags, pSkipEnts, numSkipEnts); } } }