void pmotionfunc(int x, int y) { if (bound) { glutSetMenu(canvas_menu_id); int deltax = x - mousex; int deltay = y - mousey; mousex = x; mousey = y; bool warp = false; if (mousex > 3*canvas.get_width()/4 || mousex < canvas.get_width()/4) { mousex = canvas.get_width()/2; warp = true; } if (mousey > 3*canvas.get_height()/4 || mousey < canvas.get_height()/4) { mousey = canvas.get_height()/2; warp = true; } if (warp) glutWarpPointer(mousex, mousey); if (scene.active_camera_valid()) { scene.cameras[scene.active_camera]->orientation[1] -= (float)deltax/500.0; scene.cameras[scene.active_camera]->orientation[0] -= (float)deltay/500.0; } glutPostRedisplay(); } else if (scene.active_camera_valid()) { vec3f direction; vec3f position; if (scene.active_camera_valid()) { if (scene.cameras[scene.active_camera]->type == "ortho") { position = canvas.unproject(canvas.to_window(vec2i(x, y))); direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation); } else { position = scene.cameras[scene.active_camera]->position; direction = norm(canvas.unproject(canvas.to_window(vec2i(x, y)))); } } int old_active_object = scene.active_object; scene.active_object = -1; for (int i = 0; i < scene.objects.size(); i++) { if (scene.objects[i] != NULL && scene.cameras[scene.active_camera]->model != scene.objects[i]) { bool is_light = false; bool is_camera = false; // TODO Assignment 3: uncomment this //for (int j = 0; j < scene.lights.size() && !is_light; j++) // if (scene.lights[j] != NULL && scene.lights[j]->model == scene.objects[i]) // is_light = true; for (int j = 0; j < scene.cameras.size() && !is_camera; j++) if (scene.cameras[j] != NULL && scene.cameras[j]->model == scene.objects[i]) is_camera = true; if ((!is_light && !is_camera) || (is_light && scene.render_lights) || (is_camera && scene.render_cameras)) { vec3f invdir = 1.0f/direction; vec3i sign((int)(invdir[0] < 0), (int)(invdir[1] < 0), (int)(invdir[2] < 0)); vec3f origin = position - scene.objects[i]->position; float tmin, tmax, tymin, tymax, tzmin, tzmax; tmin = (scene.objects[i]->bound[0 + sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0]; tmax = (scene.objects[i]->bound[0 + 1-sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0]; tymin = (scene.objects[i]->bound[2 + sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1]; tymax = (scene.objects[i]->bound[2 + 1-sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1]; if ((tmin <= tymax) && (tymin <= tmax)) { if (tymin > tmin) tmin = tymin; if (tymax < tmax) tmax = tymax; tzmin = (scene.objects[i]->bound[4 + sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2]; tzmax = (scene.objects[i]->bound[4 + 1-sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2]; if ((tmin <= tzmax) && (tzmin <= tmax)) { scene.active_object = i; i = scene.objects.size(); } } } } } if (scene.active_object != old_active_object) { bool is_light = false; bool is_camera = false; // TODO Assignment 3: uncomment this //for (int i = 0; i < scene.lights.size() && !is_light; i++) // if (scene.lights[i] != NULL && scene.active_object_valid() && scene.lights[i]->model == scene.objects[scene.active_object]) // is_light = true; for (int i = 0; i < scene.cameras.size() && !is_camera; i++) if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object]) is_camera = true; glutDetachMenu(GLUT_RIGHT_BUTTON); if (scene.active_object == -1) glutSetMenu(canvas_menu_id); else if (is_light) glutSetMenu(light_menu_id); else if (is_camera) glutSetMenu(camera_menu_id); else glutSetMenu(object_menu_id); glutAttachMenu(GLUT_RIGHT_BUTTON); glutPostRedisplay(); } } }
void object_menu(int num) { if (num == 0) { if (scene.active_object >= 0 && scene.active_object < scene.objects.size()) { if (scene.objects[scene.active_object] != NULL) { // TODO Assignment 3: uncomment this /*for (int i = 0; i < scene.lights.size(); ) { if (scene.lights[i] != NULL && scene.lights[i]->model == scene.objects[scene.active_object]) { delete scene.lights[i]; scene.lights.erase(scene.lights.begin() + i); } else i++; }*/ for (int i = 0; i < scene.cameras.size(); ) { if (scene.cameras[i] != NULL && scene.cameras[i]->model == scene.objects[scene.active_object]) { delete scene.cameras[i]; if (scene.active_camera > i) scene.active_camera--; scene.cameras.erase(scene.cameras.begin() + i); } else i++; } delete scene.objects[scene.active_object]; } scene.objects.erase(scene.objects.begin() + scene.active_object); glutPostRedisplay(); } } else if (num == 4) { scene.active_camera = -1; for (int i = 0; i < scene.cameras.size(); i++) if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object]) scene.active_camera = i; if (scene.active_camera_valid()) scene.cameras[scene.active_camera]->project(&canvas); glutPostRedisplay(); } else if (num == 1) manipulator = manipulate::translate; else if (num == 2) manipulator = manipulate::rotate; else if (num == 3) manipulator = manipulate::scale; else if (num == 5 && scene.active_object_valid() && scene.active_camera_valid()) { scene.cameras[scene.active_camera]->focus = scene.objects[scene.active_object]; scene.cameras[scene.active_camera]->radius = dist(scene.objects[scene.active_object]->position, scene.cameras[scene.active_camera]->position); } // TODO Assignment 4: uncomment this /*else if (num == 6 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new texturehdl(); } glutPostRedisplay(); }*/ // TODO Assignment 3: uncomment this /*else if (num == 7 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new customhdl(); } glutPostRedisplay(); } else if (num == 8 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new phonghdl(); } glutPostRedisplay(); } else if (num == 9 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new gouraudhdl(); } glutPostRedisplay(); } else if (num == 10 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new whitehdl(); } glutPostRedisplay(); }*/ }
void motionfunc(int x, int y) { if (!bound && !menu) { int deltax = x - mousex; int deltay = mousey - y; mousex = x; mousey = y; vec3f direction; vec3f position; if (scene.active_camera_valid()) { if (scene.cameras[scene.active_camera]->type == "ortho") { position = canvas.unproject(canvas.to_window(vec2i(x, y))); direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation); } else { position = scene.cameras[scene.active_camera]->position; direction = norm(canvas.unproject(canvas.to_window(vec2i(x, y)))); } } if (scene.active_object_valid() && scene.active_camera_valid()) { if (manipulator == manipulate::translate) { float d = mag(scene.objects[scene.active_object]->position - position); scene.objects[scene.active_object]->position = d*direction + position; } else if (manipulator == manipulate::rotate) scene.objects[scene.active_object]->orientation += vec3f(-(float)deltay/100.0, (float)deltax/100.0, 0.0); else if (manipulator == manipulate::scale) scene.objects[scene.active_object]->scale += (float)deltay/100.0; for (int i = 0; i < scene.cameras.size(); i++) if (scene.cameras[i]->model == scene.objects[scene.active_object]) { scene.cameras[i]->position = scene.objects[scene.active_object]->position; scene.cameras[i]->orientation = scene.objects[scene.active_object]->orientation; } } if (scene.active_camera_valid()) { if (manipulator == manipulate::fovy && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->fovy += (float)deltay/100.0; else if (manipulator == manipulate::aspect && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->aspect += (float)deltay/100.0; else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "ortho") { ((orthohdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0; ((orthohdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0; } else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "frustum") { ((frustumhdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0; ((frustumhdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0; } else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "ortho") { ((orthohdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0; ((orthohdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0; } else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "frustum") { ((frustumhdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0; ((frustumhdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0; } else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "ortho") ((orthohdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0; else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "frustum") ((frustumhdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0; else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0; else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "ortho") ((orthohdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0; else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "frustum") ((frustumhdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0; else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0; if (manipulator == manipulate::fovy || manipulator == manipulate::aspect || manipulator == manipulate::width || manipulator == manipulate::height || manipulator == manipulate::front || manipulator == manipulate::back) scene.cameras[scene.active_camera]->project(&canvas); } glutPostRedisplay(); } else if (!bound) { menu = false; pmotionfunc(x, y); } }
void object_menu(int num) { if (num == 0) { if (scene.active_object >= 0 && scene.active_object < scene.objects.size()) { if (scene.objects[scene.active_object] != NULL) { for (int i = 0; i < scene.lights.size(); ) { if (scene.lights[i] != NULL && scene.lights[i]->model == scene.objects[scene.active_object]) { delete scene.lights[i]; scene.lights.erase(scene.lights.begin() + i); } else i++; } for (int i = 0; i < scene.cameras.size(); ) { if (scene.cameras[i] != NULL && scene.cameras[i]->model == scene.objects[scene.active_object]) { delete scene.cameras[i]; if (scene.active_camera > i) scene.active_camera--; scene.cameras.erase(scene.cameras.begin() + i); } else i++; } delete scene.objects[scene.active_object]; } scene.objects.erase(scene.objects.begin() + scene.active_object); glutPostRedisplay(); } } else if (num == 4) { scene.active_camera = -1; for (int i = 0; i < scene.cameras.size(); i++) if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object]) scene.active_camera = i; if (scene.active_camera_valid()) scene.cameras[scene.active_camera]->project(); glutPostRedisplay(); } else if (num == 1) manipulator = manipulate::translate; else if (num == 2) manipulator = manipulate::rotate; else if (num == 3) manipulator = manipulate::scale; else if (num == 5 && scene.active_object_valid() && scene.active_camera_valid()) { scene.cameras[scene.active_camera]->focus = scene.objects[scene.active_object]; scene.cameras[scene.active_camera]->radius = dist(scene.objects[scene.active_object]->position, scene.cameras[scene.active_camera]->position); } else if (num == 6 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new texturehdl(); } glutPostRedisplay(); } else if (num == 7 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new customhdl(); } glutPostRedisplay(); } else if (num == 8 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new phonghdl(); } glutPostRedisplay(); } else if (num == 9 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new gouraudhdl(); } glutPostRedisplay(); } else if (num == 10 && scene.active_object_valid()) { for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++) { if (i->second != NULL) delete i->second; i->second = new whitehdl(); } glutPostRedisplay(); } else if (num == 11) manipulator = manipulate::stepsize; else if (num == 12 && scene.active_object_valid()) scene.objects[scene.active_object]->position_interpolator = 0; else if (num == 13 && scene.active_object_valid()) scene.objects[scene.active_object]->position_interpolator = 1; else if (num == 14 && scene.active_object_valid()) scene.objects[scene.active_object]->position_interpolator = 2; else if (num == 15 && scene.active_object_valid()) scene.objects[scene.active_object]->position_interpolator = 3; else if (num == 16 && scene.active_object_valid()) scene.objects[scene.active_object]->position_interpolator = 4; else if (num == 20 && scene.active_object_valid()) scene.objects[scene.active_object]->orientation_interpolator = 0; else if (num == 21 && scene.active_object_valid()) scene.objects[scene.active_object]->orientation_interpolator = 1; else if (num == 22 && scene.active_object_valid()) scene.objects[scene.active_object]->orientation_interpolator = 2; else if (num == 23 && scene.active_object_valid()) scene.objects[scene.active_object]->orientation_interpolator = 3; else if (num == 24 && scene.active_object_valid()) scene.objects[scene.active_object]->orientation_interpolator = 4; }
void motionfunc(int x, int y) { if (!bound && !menu) { int deltax = x - mousex; int deltay = mousey - y; mousex = x; mousey = y; vec3f direction; vec3f position; if (scene.active_camera_valid()) { if (scene.cameras[scene.active_camera]->type == "ortho") { GLdouble model[16]; GLdouble proj[16]; GLint view[4]; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); vec<double, 3> p; gluUnProject(x, height-y, 0.0, model, proj, view, &p[0], &p[1], &p[2]); position = p; direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation); } else { GLdouble model[16]; GLdouble proj[16]; GLint view[4]; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); vec<double, 3> p; gluUnProject(x, height-y, 0.0, model, proj, view, &p[0], &p[1], &p[2]); position = scene.cameras[scene.active_camera]->position; direction = norm(p - position); } } if (scene.active_object_valid() && scene.active_camera_valid()) { if (manipulator == manipulate::translate) { float d = mag(scene.objects[scene.active_object]->position - position); scene.objects[scene.active_object]->position = d*direction + position; } else if (manipulator == manipulate::rotate) scene.objects[scene.active_object]->orientation += vec3f(-(float)deltay/100.0, (float)deltax/100.0, 0.0); else if (manipulator == manipulate::scale) scene.objects[scene.active_object]->scale += (float)deltay/100.0; else if (manipulator == manipulate::stepsize) { scene.objects[scene.active_object]->minstep += (float)deltay/100.0; if (scene.objects[scene.active_object]->minstep < 0.0) scene.objects[scene.active_object]->minstep = 0.0; } for (int i = 0; i < scene.cameras.size(); i++) if (scene.cameras[i]->model == scene.objects[scene.active_object]) { scene.cameras[i]->position = scene.objects[scene.active_object]->position; scene.cameras[i]->orientation = scene.objects[scene.active_object]->orientation; } } if (scene.active_camera_valid()) { if (manipulator == manipulate::fovy && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->fovy += (float)deltay/100.0; else if (manipulator == manipulate::aspect && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->aspect += (float)deltay/100.0; else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "ortho") { ((orthohdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0; ((orthohdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0; } else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "frustum") { ((frustumhdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0; ((frustumhdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0; } else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "ortho") { ((orthohdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0; ((orthohdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0; } else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "frustum") { ((frustumhdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0; ((frustumhdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0; } else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "ortho") ((orthohdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0; else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "frustum") ((frustumhdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0; else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0; else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "ortho") ((orthohdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0; else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "frustum") ((frustumhdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0; else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "perspective") ((perspectivehdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0; if (manipulator == manipulate::fovy || manipulator == manipulate::aspect || manipulator == manipulate::width || manipulator == manipulate::height || manipulator == manipulate::front || manipulator == manipulate::back) scene.cameras[scene.active_camera]->project(); } glutPostRedisplay(); } else if (!bound) { menu = false; pmotionfunc(x, y); } }
void pmotionfunc(int x, int y) { if (bound) { glutSetMenu(canvas_menu_id); int deltax = x - mousex; int deltay = y - mousey; mousex = x; mousey = y; bool set_warp = false; if (mousex > 3*width/4 || mousex < width/4) { mousex = width/2; set_warp = true; } if (mousey > 3*height/4 || mousey < height/4) { mousey = height/2; set_warp = true; } if (!set_warp) warp = false; if (scene.active_camera_valid() && !warp) { scene.cameras[scene.active_camera]->orientation[1] -= (float)deltax/500.0; scene.cameras[scene.active_camera]->orientation[0] -= (float)deltay/500.0; } if (set_warp) { glutWarpPointer(mousex, mousey); warp = true; } glutPostRedisplay(); } else if (scene.active_camera_valid()) { vec3f direction; vec3f position; if (scene.cameras[scene.active_camera]->type == "ortho") { GLdouble model[16]; GLdouble proj[16]; GLint view[4]; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); vec<double, 3> p; gluUnProject(x, height-y, 0.0f, model, proj, view, &p[0], &p[1], &p[2]); position = p; direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation); } else { GLdouble model[16]; GLdouble proj[16]; GLint view[4]; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); vec<double, 3> p; gluUnProject(x, height-y, 0.0f, model, proj, view, &p[0], &p[1], &p[2]); position = scene.cameras[scene.active_camera]->position; direction = norm(p - position); } int old_active_object = scene.active_object; scene.active_object = -1; for (int i = 0; i < scene.objects.size(); i++) { if (scene.objects[i] != NULL && scene.cameras[scene.active_camera]->model != scene.objects[i]) { bool is_light = false; bool is_camera = false; for (int j = 0; j < scene.lights.size() && !is_light; j++) if (scene.lights[j] != NULL && scene.lights[j]->model == scene.objects[i]) is_light = true; for (int j = 0; j < scene.cameras.size() && !is_camera; j++) if (scene.cameras[j] != NULL && scene.cameras[j]->model == scene.objects[i]) is_camera = true; if ((!is_light && !is_camera) || (is_light && scene.render_lights) || (is_camera && scene.render_cameras)) { vec3f invdir = 1.0f/direction; vec3i sign((int)(invdir[0] < 0), (int)(invdir[1] < 0), (int)(invdir[2] < 0)); vec3f origin = position - scene.objects[i]->position; float tmin, tmax, tymin, tymax, tzmin, tzmax; tmin = (scene.objects[i]->bound[0 + sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0]; tmax = (scene.objects[i]->bound[0 + 1-sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0]; tymin = (scene.objects[i]->bound[2 + sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1]; tymax = (scene.objects[i]->bound[2 + 1-sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1]; if ((tmin <= tymax) && (tymin <= tmax)) { if (tymin > tmin) tmin = tymin; if (tymax < tmax) tmax = tymax; tzmin = (scene.objects[i]->bound[4 + sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2]; tzmax = (scene.objects[i]->bound[4 + 1-sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2]; if ((tmin <= tzmax) && (tzmin <= tmax)) { scene.active_object = i; i = scene.objects.size(); } } } } } if (scene.active_object != old_active_object) { bool is_light = false; bool is_camera = false; for (int i = 0; i < scene.lights.size() && !is_light; i++) if (scene.lights[i] != NULL && scene.active_object_valid() && scene.lights[i]->model == scene.objects[scene.active_object]) is_light = true; for (int i = 0; i < scene.cameras.size() && !is_camera; i++) if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object]) is_camera = true; glutDetachMenu(GLUT_RIGHT_BUTTON); if (scene.active_object == -1) glutSetMenu(canvas_menu_id); else if (is_light) glutSetMenu(light_menu_id); else if (is_camera) glutSetMenu(camera_menu_id); else glutSetMenu(object_menu_id); glutAttachMenu(GLUT_RIGHT_BUTTON); glutPostRedisplay(); } } }