Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

base_jotapp.C

Go to the documentation of this file.
00001 #include "disp/colors.H"
00002 #include "geom/gl_view.H"
00003 #include "geom/distrib.H"
00004 #include "geom/hspline.H"
00005 #include "geom/text2d.H"
00006 #include "geom/hspline.H"
00007 #include "geom/texture.H"
00008 #include "gtex/ref_image.H"
00009 #include "manip/cam_pz.H"
00010 #include "manip/cam_fp.H"
00011 #include "manip/cam_edit.H"
00012 #include "mesh/bmesh.H"
00013 #include "mesh/objreader.H"
00014 #include "mlib/points.H"
00015 #include "net/io_manager.H"
00016 #include "std/time.H"
00017 #include "widgets/menu.H"
00018 #include "widgets/fps.H"
00019 #include "widgets/kbd_nav.H"
00020 
00021 #include "base_jotapp.H"
00022 
00023 using namespace mlib;
00024 
00025 /*****************************************************************
00026  * BaseJOTapp
00027  *****************************************************************/
00028 
00029 //////////////////////////////////////////////////////
00030 // BaseJOTapp Static Variables Initialization
00031 //////////////////////////////////////////////////////
00032 
00033 ARRAY<BaseJOTapp::WINDOW *>   BaseJOTapp::_windows  = 0;
00034 BaseJOTapp*                   BaseJOTapp::_instance = 0;
00035 
00036 //////////////////////////////////////////////////////
00037 // BaseJOTapp Methods
00038 //////////////////////////////////////////////////////
00039 
00040 /////////////////////////////////////
00041 // Constructor
00042 /////////////////////////////////////
00043 BaseJOTapp::BaseJOTapp(int argc, char** argv) :
00044    _prog_name(argv[0]),
00045    _argv(argv),
00046    _argc(argc),
00047    _pen_manager(0),
00048    _key_menu(0)
00049 {
00050    assert(!_instance);
00051 
00052    _instance = this;
00053 
00054    atexit(BaseJOTapp::Clean_On_Exit);
00055 }
00056 
00057 /////////////////////////////////////
00058 // Constructor
00059 /////////////////////////////////////
00060 BaseJOTapp::BaseJOTapp(Cstr_ptr& name) :
00061    _prog_name(name),
00062    _argv(0),
00063    _argc(0),
00064    _pen_manager(0),
00065    _key_menu(0)
00066 {
00067    assert(!_instance);
00068    
00069    _instance = this;
00070 
00071    atexit(BaseJOTapp::Clean_On_Exit);
00072 }
00073 
00074 /////////////////////////////////////
00075 // clean_on_exit()
00076 /////////////////////////////////////
00077 void
00078 BaseJOTapp::clean_on_exit() 
00079 {
00080    if (Config::get_var_bool("DEBUG_CLEAN_ON_EXIT",false))
00081       cerr << "BaseJOTapp::clean_on_exit" << endl;
00082 
00083    while (!_events.empty()) {
00084       delete _events.pop();
00085    }
00086 }
00087 
00088 /////////////////////////////////////
00089 // init()
00090 /////////////////////////////////////
00091 void
00092 BaseJOTapp::init()
00093 {
00094    // initialize random number generator:
00095    srand48((long)the_time());
00096 
00097    init_top();                          // Create top level widget
00098 
00099    init_world();                        // Create world
00100 
00101    for (int i=0;i<_windows.num(); i++) {
00102       init_view(*_windows[i]);          // Create views,add mapped handler
00103       init_camera(_windows[i]->_view);
00104       init_buttons(_windows[i]->_view); // Create on-screen controls
00105    }
00106    VIEW::push(&*_windows[0]->_view);    // VIEW #0 is the default view
00107 
00108    init_scene();                        // Create basic scene
00109 
00110    load_scene();                        // Load world, setup networking
00111 
00112    for (int j=0; j<_windows.num(); j++) {
00113       init_win_cb(*_windows[j]);
00114       init_dev_cb(*_windows[j]);
00115       init_interact_cb(*_windows[j]);   // Add Interaction stuff
00116    }
00117 
00118    init_fsa();                          // activate all interactor FSAs
00119 
00120    // Call this now so OpenGL info gets printed sooner.
00121    IDRefImage::setup_bits(VIEWS[0]);
00122 
00123    // Add fps counter
00124    if (!Config::get_var_bool("JOT_SUPPRESS_FPS",false))
00125       WORLD::timer_callback(new FPS());
00126 
00127    // Print helpful info.
00128    cerr << "Type 'H' to see the list of key commands" << endl << endl;
00129 }
00130 
00131 /////////////////////////////////////
00132 // init_top()
00133 /////////////////////////////////////
00134 
00135 void
00136 BaseJOTapp::init_top()
00137 {
00138    _windows += new_window(WINSYS::create(_argc, _argv));
00139 
00140    _wins_to_map = 1;
00141    
00142    //XXX - Obsolete! Way too much code expects
00143    //      that there's a single window...
00144   
00145    int num_wins = Config::get_var_int("JOT_NUM_WINS",1,true);
00146  
00147    for (int i = 1; i < num_wins; i++) 
00148       {
00149          _windows += new_window(_windows[0]->_win->copy());
00150       }
00151    _wins_to_map = num_wins;
00152 }
00153 
00154 /////////////////////////////////////
00155 // init_world()
00156 /////////////////////////////////////
00157 void
00158 BaseJOTapp::init_world()
00159 {
00160    _world = new WORLD();
00161 
00162    WORLD::set_world  (&*_world);
00163 }
00164 
00165 
00166 /////////////////////////////////////
00167 // create_view()
00168 /////////////////////////////////////
00169 void
00170 BaseJOTapp::init_view(WINDOW &win)
00171 {
00172    VIEWptr v = new_view(win._win);
00173    assert(v != NULL);
00174    v->set_screen(new SCREENbasic(v->cam()));
00175    v->set_color(Color::get_var_color("BGCOLOR", Color::tan));
00176    win._view = v;
00177 
00178    if (Config::get_var_bool("USE_STEREO",false,true)) {
00179       v->stereo(VIEWimpl::TWO_BUFFERS);
00180    }
00181    
00182    _world->schedule(v);
00183 }
00184 
00185 /////////////////////////////////////
00186 // new_view()
00187 /////////////////////////////////////
00188 VIEWptr
00189 BaseJOTapp::new_view(WINSYS *win)
00190 {
00191    // Create a new instance of a view. This is a factory method that
00192    // allows subclasses to make their own types of views without
00193    // repeating the code in BaseJOTapp::create_view.
00194 
00195    return new VIEW(str_ptr("OGL View"), win, new GL_VIEW);
00196 }
00197 
00198 
00199 /////////////////////////////////////
00200 // init_camera()
00201 /////////////////////////////////////
00202 void
00203 BaseJOTapp::init_camera(CVIEWptr &view)
00204 {
00205    // Set up the camera
00206    CAMptr cam(view->cam());
00207 
00208    cam->data()->set_focal(0.1);
00209    cam->data()->set_width(0.1);
00210    cam->data()->set_height(0.1);
00211 
00212    cam->data()->set_from(Wpt(20, 30, 50));
00213    cam->data()->set_at  (Wpt::Origin());
00214    cam->data()->set_up  (Wpt(20, 31, 50));
00215    
00216    if (Config::get_var_bool("BIRD_CAM",false,true)) {
00217       cam->data()->set_from(Wpt(0,0,0));
00218       cam->data()->set_at  (Wpt(0,0,-1));
00219       cam->data()->set_up  (Wpt(0,1,0));
00220    } if (Config::get_var_bool("ORTHO_CAM",false,true)) {
00221       cam->data()->set_width(50);
00222       cam->data()->set_height(50);
00223       cam->data()->set_persp(false);
00224    }
00225 }
00226 
00227 /////////////////////////////////////
00228 // init_buttons()
00229 // create's icon2d Buttons:
00230 // constructor sets name, filename, 
00231 // camera number, toggle, and 
00232 // screen position, respectively
00233 /////////////////////////////////////
00234 void
00235 BaseJOTapp::init_buttons(CVIEWptr &view)
00236 {
00237    
00238 
00239    //////////////////////////
00240    //Cam Switch Button
00241    //////////////////////////
00242    //set to "cam 0" since its used in cam1 and cam2
00243    _buttons.push(new ICON2D("eye_button","nprdata/icons/eye", 0, false, PIXEL(0.0,0.0)));
00244   // GEOMptr g = _buttons[0];
00245    NETWORK.set(_buttons[0], 0);
00246    WORLD::create(_buttons[0], false);
00247 
00248    //////////////////////////
00249    //Cam Orbit Button
00250    //////////////////////////
00251    //set to cam 2, and initially not displayed
00252    _buttons.push(new ICON2D("orbit","nprdata/icons/orbit", 2, true, PIXEL(0.0,32.0)));
00253    _buttons[0]->toggle_suppress_draw();
00254    //g = _buttons[0];
00255    NETWORK.set(_buttons[0], 0);
00256    WORLD::create(_buttons[0], false);
00257 
00258    //////////////////////////
00259    //Cam Breathe Button
00260    //////////////////////////
00261    //set to cam 2 so not initally displayed
00262    _buttons.push(new ICON2D("breathe","nprdata/icons/breathe", 2, true, PIXEL(0.0,64.0)));
00263    _buttons[0]->toggle_suppress_draw();
00264    //g = _buttons[0];
00265    NETWORK.set(_buttons[0], 0);
00266    WORLD::create(_buttons[0], false);
00267 
00268    //////////////////////////
00269    //Cam Cruise Button
00270    //////////////////////////
00271    //set to cam 2 so not initally displayed
00272    _buttons.push(new ICON2D("cruise","nprdata/icons/control", 2, true, PIXEL(0.0,96.0)));
00273    _buttons[0]->toggle_suppress_draw();
00274    //g = _buttons[0];
00275    NETWORK.set(_buttons[0], 0);
00276    WORLD::create(_buttons[0], false);
00277 
00278    //////////////////////////
00279    //Cam Grow Button
00280    //////////////////////////
00281    //set to cam 2 so not initally displayed
00282    _buttons.push(new ICON2D("grow","nprdata/icons/grow", 2, true, PIXEL(0.0,128.0)));
00283    _buttons[0]->toggle_suppress_draw();
00284    //g = _buttons[0];
00285    NETWORK.set(_buttons[0], 0);
00286    WORLD::create(_buttons[0], false);
00287 
00288    //////////////////////////
00289    //Gravity Buttons
00290    //////////////////////////
00291    //set to cam 2 so not initally displayed
00292    //_buttons.push(new ICON2D("gravity","nprdata/icons/gravity1", 2, false, PIXEL(0.0,160.0)));
00293    //_buttons[0]->toggle_suppress_draw();
00294    //g = _buttons[0];
00295    //NETWORK.set(_buttons[0], 0);
00296    //WORLD::create(_buttons[0], false);
00297 
00298    //_buttons[0]->add_skin("nprdata/icons/gravity2");
00299    //_buttons[0]->add_skin("nprdata/icons/gravity3");
00300 
00301 
00302    //////////////////////////
00303    //Edit Scale Button
00304    //////////////////////////
00305    //set to cam 3 so not initally displayed
00306    _buttons.push(new ICON2D("scale","nprdata/icons/scale", 3, true, PIXEL(0.0,32.0)));
00307    _buttons[0]->toggle_suppress_draw();
00308    //g = _buttons[0];
00309    NETWORK.set(_buttons[0], 0);
00310    WORLD::create(_buttons[0], false);
00311 
00312    
00313    //////////////////////////
00314    //Edit Rotate Button
00315    //////////////////////////
00316    //set to cam 3 so not initally displayed
00317    _buttons.push(new ICON2D("rotateX","nprdata/icons/rotatex", 3, true, PIXEL(0.0,64.0)));
00318    _buttons[0]->toggle_suppress_draw();
00319    //g = _buttons[0];
00320    NETWORK.set(_buttons[0], 0);
00321    WORLD::create(_buttons[0], false);
00322 
00323    //////////////////////////
00324    //Edit RotateY Button
00325    //////////////////////////
00326    //set to cam 3 so not initally displayed
00327    _buttons.push(new ICON2D("rotateY","nprdata/icons/rotatey", 3, true, PIXEL(0.0,96.0)));
00328    _buttons[0]->toggle_suppress_draw();
00329    //g = _buttons[0];
00330    NETWORK.set(_buttons[0], 0);
00331    WORLD::create(_buttons[0], false);
00332 
00333    //////////////////////////
00334    //Edit RotateZ Button
00335    //////////////////////////
00336    //set to cam 3 so not initally displayed
00337    _buttons.push(new ICON2D("rotateZ","nprdata/icons/rotatez", 3, true, PIXEL(0.0,128.0)));
00338    _buttons[0]->toggle_suppress_draw();
00339    //g = _buttons[0];
00340    NETWORK.set(_buttons[0], 0);
00341    WORLD::create(_buttons[0], false);
00342 
00343    //////////////////////////
00344    //Edit ScaleX Button
00345    //////////////////////////
00346    //set to cam 3 so not initally displayed
00347    _buttons.push(new ICON2D("scalex","nprdata/icons/scalex", 3, true, PIXEL(0.0,160.0)));
00348    _buttons[0]->toggle_suppress_draw();
00349    //g = _buttons[0];
00350    NETWORK.set(_buttons[0], 0);
00351    WORLD::create(_buttons[0], false);
00352 
00353       //////////////////////////
00354    //Edit ScaleY Button
00355    //////////////////////////
00356    //set to cam 3 so not initally displayed
00357    _buttons.push(new ICON2D("scaley","nprdata/icons/scaley", 3, true, PIXEL(0.0,192.0)));
00358    _buttons[0]->toggle_suppress_draw();
00359    //g = _buttons[0];
00360    NETWORK.set(_buttons[0], 0);
00361    WORLD::create(_buttons[0], false);
00362 
00363    //////////////////////////
00364    //Edit Scale Button
00365    //////////////////////////
00366    //set to cam 3 so not initally displayed
00367    _buttons.push(new ICON2D("scalez","nprdata/icons/scalez", 3, true, PIXEL(0.0,224.0)));
00368    _buttons[0]->toggle_suppress_draw();
00369    //g = _buttons[0];
00370    NETWORK.set(_buttons[0], 0);
00371    WORLD::create(_buttons[0], false);
00372 
00373 }
00374 
00375 
00376 /////////////////////////////////////
00377 // init_scene()
00378 /////////////////////////////////////
00379 void
00380 BaseJOTapp::init_scene()
00381 {
00382    // Init the IOManager before attempting to load anything...
00383    IOManager::init();
00384 }
00385 
00386 void 
00387 BaseJOTapp::print_usage() const
00388 {
00389    cerr << "Usage: " << endl << "  " << _prog_name
00390         << " [ -j ] scene.jot" << endl
00391         << "or: "  << endl << "  " << _prog_name
00392         << " [ [ -m ] mesh.sm | -o mesh.obj ]+" << endl
00393         << endl
00394         << "  There can be just 1 scene file (-j switch), but any number of "
00395         << endl
00396         << "  mesh files, in either .sm (native jot) or .obj format."
00397         << endl << endl;
00398 }
00399 
00400 /////////////////////////////////////
00401 // load_scene()
00402 /////////////////////////////////////
00403 void
00404 BaseJOTapp::load_scene()
00405 {
00406    while (_argc > 1) {
00407       if (_argv[1][0] == '-') {
00408          char flag = _argv[1][1];
00409          pop_arg();
00410          switch(flag) {
00411           case 'm':
00412             load_sm_file(_argv[1]);
00413             break;
00414           case 'o':
00415             load_obj_file(_argv[1]);
00416             break;
00417           case 'j':
00418             load_jot_file(_argv[1]);
00419             break;
00420           default:
00421             print_usage();
00422             WORLD::Quit();
00423          }
00424       } else {
00425          if (!load_sm_file(_argv[1]))
00426             load_jot_file(_argv[1]);
00427       }
00428       pop_arg();
00429    }
00430 
00431    // Do "viewall" if:
00432    //   (1) the camera was not specified in file, and
00433    //   (2) at least one 3D object is outside the view frustum.
00434 
00435    for (int i=0; i<_windows.num(); i++)
00436       if (_windows[i]->_view->cam()->data()->loaded_from_file())
00437          return;
00438 
00439    for (int j=0; j<DRAWN.num(); j++) {
00440       GEOM* geom = GEOM::upcast(DRAWN[j]);
00441       if (geom && geom->bbox().is_off_screen()) {
00442          VIEW::peek()->viewall();
00443          return; // once is enough
00444       }
00445    }
00446 }
00447 
00448 bool
00449 BaseJOTapp::create_mesh(BMESH* mesh, Cstr_ptr &file) const
00450 {
00451    // Put the mesh in GEOM and add it to the scene:
00452 
00453    if (!mesh || mesh->empty())
00454       return false;
00455 
00456    if (Config::get_var_bool("JOT_RECENTER",false))
00457       mesh->recenter();
00458 
00459    BMESH::set_center_of_interest(mesh);
00460    WORLD::create(new_geom(mesh, file));
00461 
00462    return true;
00463 }
00464 
00465 BMESH* 
00466 BaseJOTapp::new_mesh() const
00467 {
00468    return new BMESH;
00469 }
00470 
00471 GEOM* 
00472 BaseJOTapp::new_geom(BMESH* mesh, Cstr_ptr& name) const
00473 {
00474    // Default method for creating GEOM or derived type to hold a mesh:
00475 
00476    return new GEOM(name, mesh);
00477 }
00478 
00479 bool
00480 BaseJOTapp::load_sm_file(Cstr_ptr &file)
00481 {
00482    // read an .sm file
00483 
00484    BMESHptr mesh = new_mesh();
00485    if (!mesh)
00486       return false;
00487 
00488    mesh->read_file(**file);
00489    return create_mesh(mesh, file);
00490 }
00491 
00492 bool
00493 BaseJOTapp::load_obj_file(Cstr_ptr &file)
00494 {
00495    // read an .obj file
00496 
00497    ifstream obj_stream(**file);
00498    if (!obj_stream.is_open()) {
00499       cerr << "BaseJOTapp::load_obj_file: error: couldn't open .obj file"
00500            << endl;
00501       return 0;
00502    }
00503 
00504    OBJReader reader;
00505    if (!reader.read(obj_stream)) {
00506       cerr << "BaseJOTapp::load_obj_file: error: couldn't understand .obj file"
00507            << endl;
00508       return 0;
00509    }
00510 
00511    BMESHptr mesh = new_mesh();
00512    reader.get_mesh(mesh);
00513 
00514    return create_mesh(mesh, file);
00515 }
00516 
00517 /////////////////////////////////////
00518 // load_jot_file()
00519 /////////////////////////////////////
00520 bool
00521 BaseJOTapp::load_jot_file(Cstr_ptr &file) 
00522 {
00523    LOADobs::load_status_t status;
00524 
00525    NetStream s(file, NetStream::ascii_r);
00526 
00527    LOADobs::notify_load_obs(s, status, true, true);
00528 
00529    return (status == LOADobs::LOAD_ERROR_NONE);
00530 }
00531 
00532 /////////////////////////////////////
00533 // activate_button()
00534 /////////////////////////////////////
00535 void 
00536 BaseJOTapp::activate_button(Cstr_ptr &file)
00537 {
00538 for(int i = 0; i < BaseJOTapp::instance()->_buttons.num(); i++)
00539     {
00540    if(BaseJOTapp::instance()->_buttons[i]->name() == file)
00541       BaseJOTapp::instance()->_buttons[i]->activate();
00542    }
00543 }
00544 
00545 /////////////////////////////////////
00546 // update_button()
00547 /////////////////////////////////////
00548 void 
00549 BaseJOTapp::update_button(Cstr_ptr &file)
00550 {
00551 for(int i = 0; i < BaseJOTapp::instance()->_buttons.num(); i++)
00552     {
00553    if(BaseJOTapp::instance()->_buttons[i]->name() == file)
00554       BaseJOTapp::instance()->_buttons[i]->update_skin();
00555    }
00556 }
00557 
00558 /////////////////////////////////////
00559 // deactivate_button()
00560 /////////////////////////////////////
00561 void 
00562 BaseJOTapp::deactivate_button()
00563 {
00564 for(int i = 0; i < BaseJOTapp::instance()->_buttons.num(); i++)
00565    BaseJOTapp::instance()->_buttons[i]->deactivate();
00566 }
00567 
00568 /////////////////////////////////////
00569 // toggle_button()
00570 /////////////////////////////////////
00571 void 
00572 BaseJOTapp::toggle_button(Cstr_ptr &file)
00573 {
00574 for(int i = 0; i < BaseJOTapp::instance()->_buttons.num(); i++)
00575     {
00576    if(BaseJOTapp::instance()->_buttons[i]->name() == file)
00577       BaseJOTapp::instance()->_buttons[i]->toggle_active();
00578    }
00579 }
00580 
00581 
00582 /////////////////////////////////////
00583 // init_win_cb()
00584 /////////////////////////////////////
00585 void
00586 BaseJOTapp::init_win_cb(WINDOW &window)
00587 {
00588    WINSYS *w = window._win;
00589    w->setup(window._view);          // Set up WINSYS for view
00590    w->map_cb(this);                 // Get callbacks when this view is mapped
00591 
00592 }
00593 
00594 /////////////////////////////////////
00595 // init_dev_cb()
00596 /////////////////////////////////////
00597 void
00598 BaseJOTapp::init_dev_cb(WINDOW &window)
00599 {
00600    WINSYS *w = window._win;
00601 
00602    window._mouse_map.set_devs(&w->mouse()->pointer(), &w->mouse()->buttons());
00603 
00604 }
00605 
00606 
00607 /////////////////////////////////////
00608 // init_interact_cb()
00609 /////////////////////////////////////
00610 
00611 void
00612 BaseJOTapp::init_interact_cb(WINDOW &win)
00613 {
00614    static MoveMenu *menu = 0;
00615 
00616    if (win._view->view_id() == 0){
00617       init_kbd_nav(win);
00618       init_kbd(win);
00619       init_pens(win);
00620       init_menu(win);
00621       init_obj_manip(win);
00622       menu = win._menu;
00623    } else {
00624       win._menu = menu;
00625    }
00626    
00627    init_cam_manip(win);
00628 }
00629 
00630 /////////////////////////////////////
00631 // init_menu()
00632 /////////////////////////////////////
00633 
00634 class RenderSet : public MenuItem 
00635 {
00636  protected:
00637    VIEWptr  _view;
00638    Cstr_ptr  _render_mode;
00639  public:
00640    RenderSet(CVIEWptr &view, Cstr_ptr &m) : MenuItem(**m), _view(view), _render_mode(m) {}
00641    virtual void exec(CXYpt &) { _view->set_rendering(_render_mode); }
00642 };
00643 
00644 inline void
00645 add_render_styles(CVIEWptr& view, MoveMenu* menu)
00646 {
00647    str_list rend_modes = view->rend_list();
00648    for (int i=0; i<rend_modes.num(); i++) {
00649       menu->items() += new RenderSet(view, rend_modes[i]); 
00650    }
00651 }
00652 
00653 void
00654 BaseJOTapp::init_menu(WINDOW &win)
00655 {
00656    // Get an empty menu:
00657    win._menu = win._win->menu("Render Mode");
00658 
00659    // Add render style names to menu:
00660    add_render_styles(win._view, win._menu);
00661 
00662 
00663    // hide menu:
00664    win._menu->hide();
00665 
00666    if (Config::get_var_bool("SHOW_JOT_MENU",true)) {
00667       win._menu->menu();
00668       win._menu->move_local(XYpt(-1,0));
00669       win._menu->show();
00670    }
00671 }
00672 
00673 /////////////////////////////////////
00674 // init_cam_manip()
00675 /////////////////////////////////////
00676 void
00677 BaseJOTapp::init_cam_manip(
00678    WINDOW       &win)
00679 {
00680 
00681    ButtonMapper *map = &win._mouse_map;   
00682 
00683    State          *start = &win._start;
00684    VIEWptr         view  = &*win._view;
00685 
00686 
00687    
00688    //initialize all cameras
00689    //unicam
00690    win._cam1 = new Cam_int(map->b3d(), map->mov(), map->b3u(),
00691                               map->b1d(Evd::ANY), map->b1u(), 
00692                               map->b1dC(), map->b2dC(), map->b3dC(),
00693                               map->b1u(), map->b2u(), map->b3u()
00694                               );
00695    //first person cam
00696    win._cam2 = new Cam_int_fp(map->b3d(), map->mov(), map->b3u(),
00697                               map->b1d(Evd::ANY), map->b1u(), 
00698                               map->b1dC(), map->b2dC(), map->b3dC(),
00699                               map->b1u(), map->b2u(), map->b3u()
00700                               );
00701    win._cam3 = new Cam_int_edit(map->b3d(), map->mov(), map->b3u(),
00702                               map->b1d(Evd::ANY), map->b1u(), 
00703                               map->b1dC(), map->b2dC(), map->b3dC(),
00704                               map->b1u(), map->b2u(), map->b3u()
00705                               );
00706 
00707    //start off using cam 1(the unicam)
00708 //   int cam_num = 1;
00709    *start += *win._cam1->entry();
00710 
00711 }
00712 
00713 /////////////////////////////////////
00714 // init_kbd()
00715 /////////////////////////////////////
00716 
00717 void
00718 BaseJOTapp::init_kbd(WINDOW &win)
00719 {
00720    
00721    // Make sure we only create one KeyMenu
00722    // XXX - This may need to be removed at some point if we need to support
00723    // KeyMenu on multiple windows.
00724    //assert(_key_menu == 0);
00725    
00726    // Create the KeyMenu and link it to the supplied window:
00727    _key_menu = new KeyMenu(&win._start);
00728    
00729    // Add some default keys to the menu:   
00730    _key_menu->add_menu_item('Y',  "Toggle Buttons",     &button_toggle);
00731    _key_menu->add_menu_item('H',  "Show this help",     &keymenu_help_cb);
00732    _key_menu->add_menu_item('M',  "Toggle render menu", &show_menu_cb);
00733    _key_menu->add_menu_item("qQ", "Quit",               &keymenu_quit_cb);
00734    _key_menu->add_menu_item('V',  "Viewall",            &viewall);
00735 }
00736 
00737 /////////////////////////////////////
00738 // init_pens()
00739 /////////////////////////////////////
00740 
00741 void
00742 BaseJOTapp::init_pens(WINDOW &win)
00743 {
00744    
00745    // Make sure we only create one PenManager
00746    // XXX - This may need to be remove at some point if we need to support
00747    // Pens on multiple windows.
00748    assert(_pen_manager == 0);
00749    
00750    // Create the PenManager and link it to the supplied window:
00751    _pen_manager = new PenManager(&win._start);
00752    
00753 }
00754 
00755 /////////////////////////////////////
00756 // init_kbd_nav()
00757 /////////////////////////////////////
00758 
00759 void
00760 BaseJOTapp::init_kbd_nav(WINDOW &win)
00761 {
00762    new kbd_nav(win._view);
00763 }
00764 
00765 /////////////////////////////////////
00766 // init_fsa()
00767 /////////////////////////////////////
00768 void
00769 BaseJOTapp::init_fsa()
00770 {
00771    for (int i = 0; i < _windows.num(); i++)
00772       {
00773          VIEWint_list::add(_windows[i]->_view, &_windows[i]->_start);
00774       }
00775 }
00776 
00777 /////////////////////////////////////
00778 // Run()
00779 /////////////////////////////////////
00780 void
00781 BaseJOTapp::Run()
00782 {
00783 
00784    if (_windows.num() == 0)
00785       {
00786          cerr << "BaseJOTapp::Run" << endl;
00787       }
00788 
00789    for (int i=0; i<_windows.num(); i++) 
00790       {
00791          _windows[i]->_win->mouse()->add_handler(VIEWint_list::get(_windows[i]->_view));
00792          _windows[i]->_win->display();
00793       }
00794 
00795    FD_MANAGER::mgr()->loop();
00796 }
00797 
00798 
00799 /////////////////////////////////////
00800 // pop_arg()
00801 /////////////////////////////////////
00802 void
00803 BaseJOTapp::pop_arg()
00804 {
00805    for (int i = 1; i <_argc - 1; i++) {
00806       _argv[i] = _argv[i+1];
00807    }
00808    _argc--;
00809 }
00810 
00811 
00812 /////////////////////////////////////
00813 // timeout()
00814 /////////////////////////////////////
00815 void
00816 BaseJOTapp::timeout()
00817 {
00818    // This method is the timeout callback, 
00819    // which is called periodically to redraw
00820 
00821    _world->poll();      // does nothing (at least for desktop jot)
00822    _world->tick();      // frame observers get their shot at the CPU
00823    _world->draw();      // each view gets a draw call
00824 }
00825 
00826 /////////////////////////////////////
00827 // mapped()
00828 /////////////////////////////////////
00829 void
00830 BaseJOTapp::mapped()
00831 {
00832    if (_wins_to_map) {
00833       if (--_wins_to_map != 0) {
00834          return;
00835       }
00836    }
00837    FD_MANAGER::mgr()->add_timeout(this);
00838 }
00839 
00840 /////////////////////////////////////
00841 // icon()
00842 /////////////////////////////////////
00843 void
00844 BaseJOTapp::icon()
00845 {
00846    FD_MANAGER::mgr()->rem_timeout(this);
00847 }
00848 
00849 /*!
00850  *  \note To support multiple windows, this code may need to be modified to
00851  *  determine which window's menu to work with.
00852  *
00853  */
00854 bool
00855 BaseJOTapp::menu_is_shown()
00856 {
00857    
00858    return (window(0)->_menu) ? window(0)->_menu->is_shown() : false;
00859    
00860 }
00861 
00862 /*!
00863  *  \copydoc BaseJOTapp::menu_is_shown()
00864  *
00865  */
00866 void
00867 BaseJOTapp::show_menu()
00868 {
00869    
00870    if(!(window(0)->_menu))
00871       return;
00872    
00873    //_menu->menu(true);
00874    // XXX -- I changed the above line to the one below.
00875    // Passing 'true' as a parameter causes the menu 
00876    // to be recreated every time, which seems unnecessary. (mak)
00877    window(0)->_menu->menu();
00878    window(0)->_menu->move_local(XYpt(-1,0));
00879    window(0)->_menu->show();
00880    VIEW::peek()->set_focus();
00881    
00882 }
00883 
00884 /*!
00885  *  \copydoc BaseJOTapp::menu_is_shown()
00886  *
00887  */
00888 void
00889 BaseJOTapp::hide_menu()
00890 {
00891    
00892    if(window(0)->_menu)
00893       window(0)->_menu->hide();
00894    
00895 }
00896 
00897 /*!
00898  *  \copydoc BaseJOTapp::toggle_menu()
00899  *
00900  */
00901 void 
00902 BaseJOTapp::toggle_menu() 
00903 {
00904    if (menu_is_shown())
00905       hide_menu();
00906    else
00907       show_menu();
00908 }
00909 
00910 /* KeyMenu Callback Functions */
00911 
00912 
00913 int
00914 BaseJOTapp::cam_switch(const Event&, State *&)
00915 {
00916 
00917 //get window and start state
00918 WINDOW *win = (BaseJOTapp::instance()->window(0)); 
00919 State *start = &win->_start;
00920 
00921 
00922 int camNum,lastCam;
00923 
00924 
00925 //remove cam 3 and replace with cam 1
00926 if(BaseJOTapp::instance()->cam_num == 3)
00927    {
00928    cout << "Switching to UniCam" << endl;
00929    *start -= *win->_cam3->entry();
00930    *start += *win->_cam1->entry();
00931    BaseJOTapp::instance()->cam_num = 1;
00932    camNum=1;
00933    }
00934    //remove cam 2 and replace with cam 3
00935 else if(BaseJOTapp::instance()->cam_num == 2) 
00936    {
00937    cout << "Switching to Editing mode" << endl;
00938    *start -= *win->_cam2->entry();
00939    *start += *win->_cam3->entry();
00940    BaseJOTapp::instance()->cam_num = 3;
00941    camNum=3;
00942    }
00943 else //remove cam 1 and replace with cam 2
00944    {
00945    cout << "Switching to First Person Cam" << endl;
00946    *start -= *win->_cam1->entry();
00947    *start += *win->_cam2->entry();
00948    BaseJOTapp::instance()->cam_num = 2;
00949    camNum=2;
00950    }
00951 
00952 
00953 for(int i = 0; i < BaseJOTapp::instance()->_buttons.num(); i++)
00954     {
00955    if(camNum-1==0)lastCam=3; else lastCam=camNum-1;
00956     if(BaseJOTapp::instance()->_buttons[i]->cam_num() == camNum ||
00957       BaseJOTapp::instance()->_buttons[i]->cam_num() == lastCam )
00958        BaseJOTapp::instance()->_buttons[i]->toggle_suppress_draw();
00959 
00960    }
00961 
00962 
00963    return 0;
00964 }
00965 
00966 //toggles buttons to display or not display
00967 int
00968 BaseJOTapp::button_toggle(const Event&, State *&)
00969 {
00970    for(int i = 0; i < BaseJOTapp::instance()->_buttons.num(); i++)
00971       BaseJOTapp::instance()->_buttons[i]->toggle_hidden();
00972 
00973    return 0;
00974 }
00975 
00976 
00977 int
00978 BaseJOTapp::keymenu_help_cb(const Event&, State *&)
00979 {
00980    
00981    cout << "Help Menu: mapping of keys to their functions:" << endl;
00982    
00983    BaseJOTapp::instance()->_key_menu->display_menu(cout);
00984    
00985    return 0;
00986 }
00987 
00988 int
00989 BaseJOTapp::show_menu_cb(const Event&, State *&)
00990 {
00991    instance()->toggle_menu();
00992 
00993    return 0;
00994 }
00995 
00996 int
00997 BaseJOTapp::viewall(const Event&, State *&)
00998 {
00999    VIEW::peek()->viewall();
01000 
01001    return 0;
01002 }
01003 
01004 int
01005 BaseJOTapp::keymenu_quit_cb(const Event&, State *&)
01006 {
01007    
01008    if(Config::get_var_bool("DEBUG_STRPOOL",false))
01009       err_msg("strpool load factor: %f", STR::load_factor());
01010 
01011    WORLD::Quit();
01012 
01013    return 0;
01014 }
01015 
01016 // end of file base_jotapp.C

Generated on Mon Sep 18 11:39:28 2006 for jot by  doxygen 1.4.4