void CameraManipulator::pr_step_fps(float dt, const Vector2& mouse_delta, int32 /*wheel_delta*/) { const KeyboardState& ks = *RushPlatform_GetKeyboardState(m_context); const MouseState& ms = *RushPlatform_GetMouseState(m_context); Vector3 cam_move(0,0,0); Vector3 cam_rotate(0,0,0); if( ks.is_key_down(get_key(KeyFunction_MoveX_Pos)) ) cam_move.x = 1; if( ks.is_key_down(get_key(KeyFunction_MoveX_Neg)) ) cam_move.x = -1; if( ks.is_key_down(get_key(KeyFunction_MoveY_Pos)) ) cam_move.y = 1; if( ks.is_key_down(get_key(KeyFunction_MoveY_Neg)) ) cam_move.y = -1; if( ks.is_key_down(get_key(KeyFunction_MoveZ_Pos)) ) cam_move.z = 1; if( ks.is_key_down(get_key(KeyFunction_MoveZ_Neg)) ) cam_move.z = -1; if( ks.is_key_down(get_key(KeyFunction_RotateY_Pos)) ) cam_rotate.y = -2*dt*m_turn_speed; if( ks.is_key_down(get_key(KeyFunction_RotateY_Neg)) ) cam_rotate.y = 2*dt*m_turn_speed; if( ks.is_key_down(get_key(KeyFunction_RotateX_Pos)) ) cam_rotate.x = -2*dt*m_turn_speed; if( ks.is_key_down(get_key(KeyFunction_RotateX_Neg)) ) cam_rotate.x = 2*dt*m_turn_speed; if( (ms.buttons[0]) != 0) { cam_rotate.y = mouse_delta.x*0.005f; cam_rotate.x = mouse_delta.y*0.005f; } if( cam_move!=Vector3(0,0,0) ) { cam_move.normalise_this(); if( ks.is_key_down(get_key(KeyFunction_Faster)) ) cam_move *= 10.0f; if( ks.is_key_down(get_key(KeyFunction_Slower)) ) cam_move *= 0.1f; m_camera->move(cam_move*dt*m_move_speed); } float rot_len = cam_rotate.length(); if( rot_len>0 ) { m_camera->rotate_on_axis(cam_rotate.y, Vector3(0,1,0)); m_camera->rotate_on_axis(cam_rotate.x, m_camera->right()); } }
int main(int argc, char **argv) { float amb[] = {0, 0, 0, 0}; float lpos[] = {-0.2, 0.2, 1, 0}; glutInitWindowSize(1280, 720); glutInit(&argc, argv); if(parse_args(argc, argv) == -1) { return 1; } glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (stereo ? GLUT_STEREO : 0)); glutCreateWindow("metasurf - volume rendering"); orig_xsz = glutGet(GLUT_WINDOW_WIDTH); orig_ysz = glutGet(GLUT_WINDOW_HEIGHT); if(fullscreen) { glutFullScreen(); } glutDisplayFunc(disp); glutReshapeFunc(reshape); glutKeyboardFunc(keyb); glutKeyboardUpFunc(keyb_up); glutMouseFunc(mouse); glutMotionFunc(motion); #ifndef NO_SHADERS glewInit(); if(!(sdr = create_program_load("sdr/vert.glsl", "sdr/frag.glsl"))) { return 1; } #endif glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lpos); glEnable(GL_NORMALIZE); cam_focus_dist(3.0); cam_clip(0.1, 200.0); cam_rotate(0, 0); cam_dolly(2); msurf = msurf_create(); msurf_eval_func(msurf, eval); msurf_vertex_func(msurf, vertex); msurf_set_threshold(msurf, threshold); msurf_set_resolution(msurf, xres, yres, num_slices); msurf_set_bounds(msurf, -1, -1, -1, 1, 1, 1); glClearColor(0.6, 0.6, 0.6, 1.0); dlist = glGenLists(1); glutMainLoop(); return 0; }
bool handle_input(ALLEGRO_EVENT_QUEUE *ev_queue, Camera *cam) { ALLEGRO_EVENT ev; ALLEGRO_MOUSE_STATE state; while (al_get_next_event(ev_queue, &ev)) { switch (ev.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: return false; break; case ALLEGRO_EVENT_MOUSE_BUTTON_UP: //al_show_mouse_cursor(dpy); //al_ungrab_mouse(); break; case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: //al_hide_mouse_cursor(dpy); //al_grab_mouse(dpy); break; case ALLEGRO_EVENT_MOUSE_AXES: if (ev.mouse.dz != 0) cam_dolly(cam, ev.mouse.dz); al_get_mouse_state(&state); /* The y coordinate needs to be inverted because OpenGL has * the origin in the lower-left and Allegro the upper-left */ if (state.buttons & 1) cam_orbit(cam, ev.mouse.dx, -ev.mouse.dy); else if (state.buttons & 2) cam_rotate(cam, ev.mouse.dx, -ev.mouse.dy); break; case ALLEGRO_EVENT_KEY_CHAR: if (ev.keyboard.unichar == 'w') { wireframe = !wireframe; if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glDisable(GL_CULL_FACE); } else { glPolygonMode(GL_FRONT, GL_FILL); glEnable(GL_CULL_FACE); } } else if (ev.keyboard.unichar == 'c') { Vec3 upv = quat_transform(cam->orientation, (Vec3){0, 1, 0}); cam_lookat(cam, cam->position, cam->target, upv); } break; case ALLEGRO_EVENT_DISPLAY_RESIZE: cam->width = ev.display.width; cam->height = ev.display.height; glmLoadIdentity(glmProjectionMatrix); cam_projection_matrix(cam, glmProjectionMatrix); glViewport(cam->left, cam->bottom, cam->width, cam->height); default: break; } } return true; }