void scale_along_normal( CGEOMptr &obj, CWpt &scale_cent, CWpt &down_pt, CWvec &down_norm, CXYpt &cur ) { Wtransf xf (obj->xform()); Wpt dpt (xf * down_pt); Wpt spt (xf * scale_cent); Wvec upv ((xf * down_norm).normalized()); if (upv * (dpt - spt) < 0) upv = -upv; if ((cur - XYpt(dpt)).length() < 0.01) return; Wpt npt(Wline(dpt,upv).intersect(cur)); Wpt ctr(xf * scale_cent); double sval(((npt-dpt) * upv) / (dpt-ctr).length()); if ((npt-ctr) * (dpt-ctr) < 0) return; Wvec dnorm (fabs(down_norm[0]),fabs(down_norm[1]), fabs(down_norm[2])); ((GEOMptr)obj)->set_xform(xf * Wtransf::scaling(scale_cent, (dnorm*sval+Wvec(1,1,1)))); }
FPS::FPS() { XYpt c = lr_corner_loc(50, 10); // ugh, the above is broken since window dimensions are not // available when this is called... switching to hack for now: c = XYpt(0.671875,-0.95); // fixed below in tick() _text = new TEXT2D(str_ptr("fps"), str_ptr::null, c); _text->set_loc(c); _text->set_string(str_ptr("")); GEOMptr text(&*_text); NETWORK .set(text, 0); NO_COLOR_MOD .set(text, 1); NO_XFORM_MOD .set(text, 1); NO_DISP_MOD .set(text, 1); NO_COPY .set(text, 1); DONOT_CLIP_OBJ.set(text, 1); WORLD::create(text, false); _last_display = VIEW::stamp(); _clock.set(); }
RAYhit & LINE3D::intersect( RAYhit &ray, CWtransf&, int ) const { // Find the intersection point, its distance, and some kind of normal double distance = -1, d_2d = -1; Wvec surf_norm; Wpt nearpt; for (int i=0; i<num()-1; i++) { // Find the nearest point on the ray to the segment. Wpt ray_pt = ray.line().intersect(Wline(point(i), point(i+1))); // Accept only if ray_pt is in front of the ray if ((ray_pt - ray.point()) * ray.vec() > 0 ) { // Ok if the ray passes within 10 pixels of the segment const double PIX_THRESH = 10.0; Wpt hit_pt = nearest_pt_to_line_seg(ray_pt, point(i), point(i+1)); double screen_dist = PIXEL(hit_pt).dist(ray_pt); if ((screen_dist < PIX_THRESH) && (d_2d < 0 || screen_dist < d_2d)) { d_2d = screen_dist; distance = ray.point().dist(ray_pt); nearpt = hit_pt; // XXX - What should be the "normal"? For now, // just the vector pointing back to the camera. surf_norm = -ray.vec().normalized(); } } } // Then call ray.check() passing it all this stuff if (distance >= 0) ray.check(distance, 1, 0, (GEL*)this, surf_norm, nearpt, nearpt, 0, XYpt()); return ray; }
int TRACE::draw(CVIEWptr&) { if (!valid()) { return 0; } // load identity for model matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // set up to draw in PIXEL coords: glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixd(VIEW::peek()->xypt_proj().transpose().matrix()); // Set up line drawing attributes glPushAttrib(GL_ENABLE_BIT); glDisable(GL_LIGHTING); // GL_ENABLE_BIT glEnable(GL_TEXTURE_2D); // GL_ENABLE_BIT glDisable(GL_CULL_FACE); // GL_ENABLE_BIT glDisable(GL_DEPTH_TEST); // GL_ENABLE_BIT glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); _texture->apply_texture(); // GL_ENABLE_BIT if (_calib_mode_flag) { // no transparency if we are in calibration glColor4f(1.0,1.0,1.0,0.5); if(_cur_calib_pt_index==0){ WORLD::message("Calibrate trace: click upper left"); } else if(_cur_calib_pt_index==1){ WORLD::message("Calibrate trace: click lower right"); } } else { glColor4f(1.0, 1.0, 1.0, 0.5); } // begin drawing glBegin(GL_QUAD_STRIP); XYpt topleft, topright, bottomleft, bottomright; if (_calibrated) { // if we are calibrated, use the corners we got from // calibration if(_cur_calib_pt_index == 4){ topleft = _samples[_TOP_LEFT]; topright = _samples[_TOP_RIGHT]; bottomleft = _samples[_BOTTOM_RIGHT]; bottomright = _samples[_BOTTOM_LEFT]; } else if(_cur_calib_pt_index == 2){ topleft = _samples[0]; topright = XYpt( _samples[1][0], _samples[0][1]); bottomright = _samples[1]; bottomleft = XYpt(_samples[0][0], _samples[1][1]); } } else { // if we aren't calibrated, then draw the image over // the whole window double tex_dim[2]; Point2i ts = _texture->get_size(); tex_dim[0] = ts[0]; tex_dim[1] = ts[1]; if(tex_dim[1] >= tex_dim[0]){ tex_dim[0] = (1.0*tex_dim[0])/tex_dim[1]; tex_dim[1] = 1.0; } else { tex_dim[1] = (1.0*tex_dim[1])/tex_dim[0]; tex_dim[0] = 1.0; } topleft = XYpt(-tex_dim[0], tex_dim[1]); topright = XYpt( tex_dim[0], tex_dim[1]); bottomleft = XYpt(-tex_dim[0], -tex_dim[1]); bottomright = XYpt( tex_dim[0], -tex_dim[1]); } glTexCoord2f(0.0, 1.0); glVertex2dv(topleft.data()); glTexCoord2f(0.0, 0.0); glVertex2dv(bottomleft.data()); glTexCoord2f(1.0, 1.0); glVertex2dv(topright.data()); glTexCoord2f(1.0, 0.0); glVertex2dv(bottomright.data()); glEnd(); glPopAttrib(); if (_calib_mode_flag) { // if we are in calibration mode, draw point or else indicate // where the user is supposed to tap next } glMatrixMode(GL_PROJECTION); glPopMatrix(); // unloads our projection matrix glMatrixMode(GL_MODELVIEW); glPopMatrix(); // unloads model matrix return 1; }