int hitRing(entity_t * ent, point_t base, vector_t dir, hitinfo_t * hit) { if(hitPlane(ent, base, dir, hit) != 1) return 0; assert(ent->magic == ENTITY_T); sobj_t *sobj = ent->entDerived; assert(sobj->magic == SCENEOBJ_T); plane_t *plane = sobj->sobjDerived; assert(plane->magic == PLANE_T); ring_t * ring = plane->planeDerived; assert(ring->magic == RING_T); tuple_t r_centerTOhit = ray(plane->point, hit->hitpoint); double d_hitpoint = length(r_centerTOhit); double d_inner = length(scale(unitize(r_centerTOhit), ring->radius1)); double d_outer = length(scale(unitize(r_centerTOhit), ring->radius2)); return ((d_hitpoint > d_inner) && (d_hitpoint < d_outer)); }
void hitObjects(Point3D_t rayO, Vector3D_t rayD,ShadeRec_t* sr) { int i; FLOAT_T t; Normal_t normal; Point3D_t localHitPoint; FLOAT_T tmin = kHugeValue; for(i = 0; i < nObjects; i++) { switch(objects[i]->type) { case SPHERE: if(hitSphere(rayO,rayD,&t,sr,objects[i]->center,objects[i]->radius) && (t < tmin)) { sr->hitAnObject = 1; tmin = t; sr->material = objects[i]->material; //sr.local_hit_point = ray.o + t * ray.d; sr->hitPoint.x = rayO.x + (t*rayD.x); sr->hitPoint.y = rayO.y + (t*rayD.y); sr->hitPoint.z = rayO.z + (t*rayD.z); normal.x = sr->normal.x; normal.y = sr->normal.y; normal.z = sr->normal.z; localHitPoint.x = sr->localHitPoint.x; localHitPoint.y = sr->localHitPoint.y; localHitPoint.z = sr->localHitPoint.z; } break; case PLANE: if(hitPlane(rayO,rayD,&t,sr,objects[i]->a,objects[i]->n) && (t < tmin)) { sr->hitAnObject = 1; tmin = t; sr->material = objects[i]->material; //sr.local_hit_point = ray.o + t * ray.d; sr->hitPoint.x = rayO.x + (t*rayD.x); sr->hitPoint.y = rayO.y + (t*rayD.y); sr->hitPoint.z = rayO.z + (t*rayD.z); normal.x = sr->normal.x; normal.y = sr->normal.y; normal.z = sr->normal.z; localHitPoint.x = sr->localHitPoint.x; localHitPoint.y = sr->localHitPoint.y; localHitPoint.z = sr->localHitPoint.z; } break; } } if(sr->hitAnObject) { sr->t = tmin; sr->normal.x = normal.x; sr->normal.y = normal.y; sr->normal.z = normal.z; sr->localHitPoint.x = localHitPoint.x ; sr->localHitPoint.y = localHitPoint.y ; sr->localHitPoint.z = localHitPoint.z ; } }