void mouse_move(int mouse_x, int mouse_y) { using namespace std; using namespace Eigen; using namespace igl; using namespace std; init_C(); glutSetCursor(GLUT_CURSOR_CROSSHAIR); // Push scene and object push_scene(); push_object(); // Unproject mouse at 0 depth and some positive depth win_s = Vector3f(mouse_x,height-mouse_y,0); Vector3f win_d(mouse_x,height-mouse_y,1); unproject(win_s,s); unproject(win_d,d); pop_object(); pop_scene(); report_gl_error(); // Shoot ray at unprojected mouse in view direction dir = d-s; int num_rays_shot; ei.intersectRay(s,dir,hits,num_rays_shot); for(vector<igl::embree::Hit>::iterator hit = hits.begin(); hit != hits.end(); hit++) { // Change color of hit faces C(hit->id,0) = 1; C(hit->id,1) = 0.4; C(hit->id,2) = 0.4; } }
IGL_INLINE void igl::embree::ambient_occlusion( const igl::embree::EmbreeIntersector & ei, const Eigen::PlainObjectBase<DerivedP> & P, const Eigen::PlainObjectBase<DerivedN> & N, const int num_samples, Eigen::PlainObjectBase<DerivedS> & S) { using namespace Eigen; using namespace igl; const int n = P.rows(); // Resize output S.resize(n,1); // Embree seems to be parallel when constructing but not when tracing rays #pragma omp parallel for // loop over mesh vertices for(int p = 0;p<n;p++) { const Vector3f origin = P.row(p).template cast<float>(); const Vector3f normal = N.row(p).template cast<float>(); int num_hits = 0; MatrixXf D = random_dir_stratified(num_samples).cast<float>(); for(int s = 0;s<num_samples;s++) { //Vector3d d = random_dir(); Vector3f d = D.row(s); if(d.dot(normal) < 0) { // reverse ray d *= -1; } igl::embree::Hit hit; const float tnear = 1e-4f; if(ei.intersectRay(origin,d,hit,tnear)) { num_hits++; } } S(p) = (double)num_hits/(double)num_samples; } }