// Processes mouse movements for skeleton manipulation void trackMouse(int x, int y) { if(mode == 2 && selected >= joints.size()) { point *s = &xydpoints.at(selected - joints.size()); if(RM) { double shift = (clickpos.gety() - y)/50.; *s = point(s->getx(), s->gety(), clickpos.getz()+shift); } else { *s = point(x, y, s->getz()); } setTargets(); } else if(mode == 1) { if(LM && selected >= 0 && selected <= joints.size()) { double shift = clickpos.gety() - y; joints.at(selected)->settheta(clickpos.getz() + shift); } } }
// Convert mouse coordinates + depth to world coordinates point mouseToObj(point xyd) { int mx = xyd.getx(); int my = xyd.gety(); double depth = xyd.getz(); float clipx = 2.0*mx/win_width - 1; float clipy = 2.0*(win_height - my)/win_height - 1; glm::vec4 clip1 = projection*viewT*glm::vec4(0, 0, depth, 1); glm::vec4 clip(clipx, clipy, clip1.z/clip1.w, 1); glm::vec4 world = glm::inverse(projection*viewT*viewR)*clip; return point(world.x/world.w, world.y/world.w, world.z/world.w); }