void Cone::isectTo2DMap(const isect& i, const vec3f& pos, int density, int& x, int& y) const { vec3f posLocal = transform->globalToLocalCoords(pos); auto bounds = ComputeLocalBoundingBox(); if (abs(posLocal[2] - bounds.min[2]) < 1e-8 || abs(posLocal[2] - bounds.max[2]) < 1e-8) return; double theta; if (posLocal[0] > 0) { theta = asin(posLocal[1]); if (theta < 0) theta += 2 * M_PI; } else { theta = M_PI - asin(posLocal[1]); } x = theta / (2 * M_PI) * density; y = posLocal[2] * density; if (x < 0) x = 0; if (y < 0) y = 0; }
bool Box::intersectLocal( const ray& r, isect& i ) const { BoundingBox bounds = ComputeLocalBoundingBox(); vec3f p = r.getPosition(); vec3f d = r.getDirection(); //find tmin and tmax vec3f tmin; vec3f tmax; vec3f nmin(0, 0, 0); vec3f nmax(0, 0, 0); double min; double max; for(int j=0; j<3; j++) { if(d[j]>=0) { tmin[j] = (bounds.min[j] - p[j]) / d[j]; tmax[j] = (bounds.max[j] - p[j]) / d[j]; nmin[j] = -1; nmax[j] = 1; } else { tmin[j] = (bounds.max[j] - p[j]) / d[j]; tmax[j] = (bounds.min[j] - p[j]) / d[j]; nmin[j] = 1; nmax[j] = -1; } } //min of tmax, max of tmin max = std::min( std::min(tmax[0], tmax[1]), tmax[2]); min = std::max( std::max(tmin[0], tmin[1]), tmin[2]); if(min > max || max < RAY_EPSILON) return false; i.obj = this; vec3f N(0, 0, 0); if(min >= RAY_EPSILON) { i.t = min; for(int i=0; i<3; i++) { if(tmin[i] == min) { N[i] = nmin[i]; break; } } } else { i.t = max; for(int i=0; i<3; i++) { if(tmax[i] == max) { N[i] = nmax[i]; break; } } } i.N = N; return true; }