Revision: 6816 http://playerstage.svn.sourceforge.net/playerstage/?rev=6816&view=rev Author: jeremy_asher Date: 2008-07-08 10:58:53 -0700 (Tue, 08 Jul 2008)
Log Message: ----------- Tweaked camera reset code to fix a few bugs and improve functionality Modified Paths: -------------- code/stage/trunk/libstage/canvas.cc code/stage/trunk/libstage/model.cc code/stage/trunk/libstage/stage.hh code/stage/trunk/worlds/fasr.world Modified: code/stage/trunk/libstage/canvas.cc =================================================================== --- code/stage/trunk/libstage/canvas.cc 2008-07-08 17:32:51 UTC (rev 6815) +++ code/stage/trunk/libstage/canvas.cc 2008-07-08 17:58:53 UTC (rev 6816) @@ -53,7 +53,7 @@ showTrailRise( "Trails/Rising blocks", "show_trailrise", "^r", false ), showTrails( "Trails/Fast", "show_trailfast", "^f", false ), showTree( "Debug/Tree", "show_tree", "^t", false ), - perspectiveCam( "Perspective camera", "pcam_on", "r", false ), + pCamOn( "Perspective camera", "pcam_on", "r", false ), visualizeAll( "Visualize All", "vis_all", "^v", true ) { end(); @@ -64,6 +64,7 @@ this->world = world; selected_models = NULL; last_selection = NULL; + wf = NULL; perspective_camera.setPose( 0.0, -4.0, 3.0 ); current_camera = &camera; @@ -244,7 +245,7 @@ switch(event) { case FL_MOUSEWHEEL: - if( perspectiveCam == true ) { + if( pCamOn == true ) { perspective_camera.scroll( Fl::event_dy() / 10.0 ); } else { @@ -263,13 +264,13 @@ int dx = Fl::event_x() - startx; int dy = Fl::event_y() - starty; - if( perspectiveCam == true ) { + if( pCamOn == true ) { perspective_camera.addYaw( -dx ); perspective_camera.addPitch( -dy ); } else { - camera.setPitch( - 0.5 * static_cast<double>( dy ) ); - camera.setYaw( - 0.5 * static_cast<double>( dx ) ); + camera.addPitch( - 0.5 * static_cast<double>( dy ) ); + camera.addYaw( - 0.5 * static_cast<double>( dx ) ); } invalidate(); redraw(); @@ -279,7 +280,7 @@ int dx = Fl::event_x() - startx; int dy = Fl::event_y() - starty; - if( perspectiveCam == true ) { + if( pCamOn == true ) { perspective_camera.move( -dx, dy, 0.0 ); } else { @@ -365,7 +366,7 @@ else { // started dragging on empty space or an // unselected model, move the canvas - if( perspectiveCam == true ) { + if( pCamOn == true ) { perspective_camera.move( -dx, dy, 0.0 ); } else { @@ -409,7 +410,9 @@ world->TogglePause(); break; case ' ': // space bar - camera.resetAngle(); + //current_camera->reset(); + if ( wf ) + current_camera->Load( wf, wf->LookupEntity( "window" ) ); //invalidate(); if( Fl::event_state( FL_CTRL ) ) { resetCamera(); @@ -417,16 +420,16 @@ redraw(); break; case FL_Left: - if( perspectiveCam == false ) { camera.move( -10, 0 ); } + if( pCamOn == false ) { camera.move( -10, 0 ); } else { perspective_camera.strafe( -0.5 ); } break; case FL_Right: - if( perspectiveCam == false ) {camera.move( 10, 0 ); } + if( pCamOn == false ) {camera.move( 10, 0 ); } else { perspective_camera.strafe( 0.5 ); } break; case FL_Down: - if( perspectiveCam == false ) {camera.move( 0, -10 ); } + if( pCamOn == false ) {camera.move( 0, -10 ); } else { perspective_camera.forward( -0.5 ); } break; case FL_Up: - if( perspectiveCam == false ) {camera.move( 0, 10 ); } + if( pCamOn == false ) {camera.move( 0, 10 ); } else { perspective_camera.forward( 0.5 ); } break; default: return 0; // keypress unhandled @@ -558,6 +561,8 @@ float scale_x = w() / (max_x - min_x) * 0.9; float scale_y = h() / (max_y - min_y) * 0.9; camera.setScale( scale_x < scale_y ? scale_x : scale_y ); + + //TODO reset perspective cam } void StgCanvas::renderFrame() @@ -827,7 +832,7 @@ void StgCanvas::perspectiveCb( Fl_Widget* w, void* p ) { StgCanvas* canvas = static_cast<StgCanvas*>( w ); - Option* opt = static_cast<Option*>( p ); // perspectiveCam + Option* opt = static_cast<Option*>( p ); // pCamOn if ( opt ) { // Perspective mode is on, change camera canvas->current_camera = &canvas->perspective_camera; @@ -851,8 +856,8 @@ showFootprints.createMenuItem( menu, path ); showGrid.createMenuItem( menu, path ); showStatus.createMenuItem( menu, path ); - perspectiveCam.createMenuItem( menu, path ); - perspectiveCam.menuCallback( perspectiveCb, this ); + pCamOn.createMenuItem( menu, path ); + pCamOn.menuCallback( perspectiveCb, this ); showOccupancy.createMenuItem( menu, path ); showTrailArrows.createMenuItem( menu, path ); showTrails.createMenuItem( menu, path ); @@ -864,6 +869,7 @@ void StgCanvas::Load( Worldfile* wf, int sec ) { + this->wf = wf; camera.Load( wf, sec ); perspective_camera.Load( wf, sec ); @@ -882,7 +888,7 @@ showTrails.Load( wf, sec ); showTree.Load( wf, sec ); showScreenshots.Load( wf, sec ); - perspectiveCam.Load( wf, sec ); + pCamOn.Load( wf, sec ); invalidate(); // we probably changed something } @@ -907,7 +913,7 @@ showTrails.Save( wf, sec ); showTree.Save( wf, sec ); showScreenshots.Save( wf, sec ); - perspectiveCam.Save( wf, sec ); + pCamOn.Save( wf, sec ); } @@ -916,7 +922,7 @@ static bool loaded_texture = false; //Enable the following to debug camera model - // if( loaded_texture == true && perspectiveCam == true ) + // if( loaded_texture == true && pCamOn == true ) // return; if (!valid() ) @@ -987,7 +993,7 @@ // install a font gl_font( FL_HELVETICA, 12 ); - if( perspectiveCam == true ) { + if( pCamOn == true ) { perspective_camera.setAspect( static_cast< float >( w() ) / static_cast< float >( h() ) ); perspective_camera.SetProjection(); current_camera = &perspective_camera; @@ -1005,7 +1011,7 @@ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } - if( perspectiveCam == true ) { + if( pCamOn == true ) { if( showFollow && last_selection ) { //Follow the selected robot stg_pose_t gpose = last_selection->GetGlobalPose(); Modified: code/stage/trunk/libstage/model.cc =================================================================== --- code/stage/trunk/libstage/model.cc 2008-07-08 17:32:51 UTC (rev 6815) +++ code/stage/trunk/libstage/model.cc 2008-07-08 17:58:53 UTC (rev 6816) @@ -1012,7 +1012,7 @@ { float stheta = dtor( canvas->current_camera->pitch() ); float sphi = - dtor( canvas->current_camera->yaw() ); - if( canvas->perspectiveCam == true ) { + if( canvas->pCamOn == true ) { sphi = atan2( ( pose.x - canvas->current_camera->x() ) , Modified: code/stage/trunk/libstage/stage.hh =================================================================== --- code/stage/trunk/libstage/stage.hh 2008-07-08 17:32:51 UTC (rev 6815) +++ code/stage/trunk/libstage/stage.hh 2008-07-08 17:58:53 UTC (rev 6816) @@ -1798,6 +1798,9 @@ inline float x( void ) const { return _x; } inline float y( void ) const { return _y; } inline float z( void ) const { return _z; } + + virtual void reset() = 0; + virtual void Load( Worldfile* wf, int sec ) = 0; //TODO data should be passed in somehow else. (at least min/max stuff) //virtual void SetProjection( float pixels_width, float pixels_height, float y_min, float y_max ) const = 0; @@ -1850,6 +1853,8 @@ inline float farClip( void ) const { return _z_far; } inline void setClip( float near, float far ) { _z_far = far; _z_near = near; } + inline void reset() { setPitch( 70 ); setYaw( 0 ); } + void Load( Worldfile* wf, int sec ); void Save( Worldfile* wf, int sec ); }; @@ -1871,8 +1876,10 @@ virtual void SetProjection( void ) const; void move( float x, float y ); - inline void setYaw( float yaw ) { _yaw += yaw; } - inline void setPitch( float pitch ) { + inline void setYaw( float yaw ) { _yaw = yaw; } + inline void setPitch( float pitch ) { _pitch = pitch; } + inline void addYaw( float yaw ) { _yaw += yaw; } + inline void addPitch( float pitch ) { _pitch += pitch; if( _pitch > 90 ) _pitch = 90; @@ -1884,7 +1891,7 @@ inline void setPose( float x, float y) { _x = x; _y = y; } void scale( float scale, float shift_x = 0, float h = 0, float shift_y = 0, float w = 0 ); - inline void resetAngle( void ) { _pitch = _yaw = 0; } + inline void reset( void ) { _pitch = _yaw = 0; } inline float scale() const { return _scale; } @@ -1904,7 +1911,8 @@ StgCamera* current_camera; StgOrthoCamera camera; StgPerspectiveCamera perspective_camera; - bool dirty_buffer; + bool dirty_buffer; + Worldfile* wf; int startx, starty; bool selectedModel; @@ -1939,7 +1947,7 @@ showTrailRise, showTrails, showTree, - perspectiveCam, + pCamOn, visualizeAll; public: Modified: code/stage/trunk/worlds/fasr.world =================================================================== --- code/stage/trunk/worlds/fasr.world 2008-07-08 17:32:51 UTC (rev 6815) +++ code/stage/trunk/worlds/fasr.world 2008-07-08 17:58:53 UTC (rev 6816) @@ -2,9 +2,9 @@ # Authors: Richard Vaughanwo # $Id: fasr.world,v 1.4 2008-04-01 23:57:41 rtv Exp $ -include "inc/pioneer.inc" -include "inc/map.inc" -include "inc/sick.inc" +include "pioneer.inc" +include "map.inc" +include "sick.inc" interval_sim 100 # simulation timestep in milliseconds interval_real 10 # real-time interval between simulation updates in milliseconds This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit