Revision: 6488
http://playerstage.svn.sourceforge.net/playerstage/?rev=6488&view=rev
Author: alexcb
Date: 2008-06-06 18:15:39 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
created camera class, and changed zoom and rotating behaviour to be local to
the center of the screen (NOT world)
Modified Paths:
--------------
code/stage/trunk/libstage/CMakeLists.txt
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/texture_manager.cc
code/stage/trunk/libstage/worldgui.cc
Added Paths:
-----------
code/stage/trunk/libstage/camera.cc
Modified: code/stage/trunk/libstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt 2008-06-07 00:44:46 UTC (rev
6487)
+++ code/stage/trunk/libstage/CMakeLists.txt 2008-06-07 01:15:39 UTC (rev
6488)
@@ -3,6 +3,7 @@
ancestor.cc
block.cc
canvas.cc
+ camera.cc
gl.cc
glcolorstack.cc
model.cc
Added: code/stage/trunk/libstage/camera.cc
===================================================================
--- code/stage/trunk/libstage/camera.cc (rev 0)
+++ code/stage/trunk/libstage/camera.cc 2008-06-07 01:15:39 UTC (rev 6488)
@@ -0,0 +1,39 @@
+/*
+ * camera.cc
+ * Stage
+ *
+ * Created by Alex Couture-Beil on 06/06/08.
+ * Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+
+#include "stage_internal.hh"
+
+#include <iostream>
+
+void StgCamera::Draw( void )
+{
+ static float i = 0;
+ i += 1;
+// glRotatef( rtod(-_stheta), fabs(cos(_sphi)), 0, 0 );
+// glRotatef( rtod(_sphi), 0,0,1 ); // rotate about z - yaw
+//
+// glTranslatef( -_panx, -_pany, 0 );
+// glScalef( _scale, _scale, _scale );
+
+
+ glRotatef( _pitch, 1.0, 0.0, 0.0 );
+ glRotatef( _yaw, 0.0, 0.0, 1.0 );
+
+ //both of these are handled in the glOrtho call
+// glScalef( _scale, _scale, _scale );
+ glTranslatef( - _x * _scale, - _y * _scale, 0.0 );
+ glScalef( _scale, _scale, _scale );
+
+// glRotatef( 60.0, 1.0, 0.0, 0.0 );
+
+ //glRotatef( 60, 0.0, 1.0, 0.0 );
+// glRotatef( i, 0.0, 0.0, 1.0 );
+
+}
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-07 00:44:46 UTC (rev 6487)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-07 01:15:39 UTC (rev 6488)
@@ -32,8 +32,8 @@
last_selection = NULL;
startx = starty = 0;
- panx = pany = stheta = sphi = 0.0;
- scale = 15.0;
+ //panx = pany = stheta = sphi = 0.0;
+ //scale = 15.0;
interval = 50; //msec between redraws
graphics = true;
@@ -169,11 +169,7 @@
}
else
{
- //scale -= 0.5 * (double)Fl::event_dy();
- scale -= 0.5 * (double)Fl::event_dy();
- if( scale < 1 )
- scale = 1;
-
+ camera.scale( Fl::event_dy() );
invalidate();
}
return 1;
@@ -184,18 +180,17 @@
int dx = Fl::event_x() - startx;
int dy = Fl::event_y() - starty;
- stheta -= 0.01 * (double)dy;
- sphi += 0.01 * (double)dx;
- stheta = constrain( stheta, 0, M_PI/2.0 );
+ camera.pitch( 0.5 * static_cast<double>( dy ) );
+ camera.yaw( 0.5 * static_cast<double>( dx ) );
+
invalidate();
}
else if( Fl::event_state( FL_ALT ) )
- {
+ {
int dx = Fl::event_x() - startx;
int dy = Fl::event_y() - starty;
- panx -= dx;
- pany += dy;
+ camera.move( -dx, dy );
invalidate();
}
@@ -256,8 +251,7 @@
}
else
{
- panx -= dx;
- pany += dy;
+ camera.move( -dx, dy );
invalidate(); // so the projection gets updated
}
break;
@@ -304,13 +298,14 @@
world->TogglePause();
break;
case ' ': // space bar
- sphi = stheta = 0.0;
+
+ camera.resetAngle();
invalidate();
break;
- case FL_Left: panx += 10; break;
- case FL_Right: panx -= 10; break;
- case FL_Down: pany += 10; break;
- case FL_Up: pany -= 10; break;
+ case FL_Left: camera.move( -10, 0 ); break;
+ case FL_Right: camera.move( 10, 0 );; break;
+ case FL_Down: camera.move( 0, -10 );; break;
+ case FL_Up: camera.move( 0, 10 );; break;
default:
return 0; // keypress unhandled
}
@@ -390,22 +385,29 @@
stg_bounds3d_t extent = world->GetExtent();
- glOrtho( -pixels_width/2.0, pixels_width/2.0,
- -pixels_height/2.0, pixels_height/2.0,
- extent.y.min*scale, extent.y.max*scale );
+// glFrustum( -pixels_width/2.0, pixels_width/2.0,
+// -pixels_height/2.0, pixels_height/2.0,
+// extent.y.min, extent.y.max );
+// glOrtho( -pixels_width/2.0, pixels_width/2.0,
+// -pixels_height/2.0, pixels_height/2.0,
+// extent.y.min*scale, extent.y.max*scale );
// set the modelview matrix
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
- // move the next two lines...
- glTranslatef( -panx, -pany, 0 );
- glScalef( scale, scale, scale );
- // .. from here
+ //TODO insert a camera class here
+
+ camera.Draw();
+
+// // move the next two lines...
+// glTranslatef( -panx, -pany, 0 );
+// glScalef( scale, scale, scale );
+// // .. from here
+//
+// glRotatef( rtod(-stheta), fabs(cos(sphi)), 0, 0 );
+// glRotatef( rtod(sphi), 0,0,1 ); // rotate about z - yaw
- glRotatef( rtod(-stheta), fabs(cos(sphi)), 0, 0 );
- glRotatef( rtod(sphi), 0,0,1 ); // rotate about z - yaw
-
// ... to here to get rotation about the center of the window (but
broken panning)
// enable vertex arrays
@@ -415,6 +417,27 @@
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+
+
+ stg_bounds3d_t extent = world->GetExtent();
+ double pixels_width = w();
+ double pixels_height = h();
+
+// gluPerspective( 60, pixels_width / pixels_height, 0.01, 1000 );
+
+
+
+ glOrtho( -pixels_width/2.0 / camera.getScale(), pixels_width/2.0 /
camera.getScale(),
+ -pixels_height/2.0 / camera.getScale(),
pixels_height/2.0 / camera.getScale(),
+ extent.y.min * camera.getScale() * 2, extent.y.max *
camera.getScale() * 2 );
+
+ //draw camera
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+ camera.Draw();
+
if( ! (showflags & STG_SHOW_TRAILS) )
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@@ -422,12 +445,12 @@
if( (showflags & STG_SHOW_FOLLOW) && last_selection )
{
glLoadIdentity ();
- double zclip = 20 * scale; //hypot(world->Width(), world->Height()) *
scale;
+ double zclip = 20 * camera.getScale(); //hypot(world->Width(),
world->Height()) * camera.getScale();
glTranslatef( 0,0,
-zclip / 2.0 );
// meter scale
- glScalef ( scale, scale, scale ); // zoom
+ glScalef ( camera.getScale(), camera.getScale(), camera.getScale() ); //
zoom
stg_pose_t gpose = last_selection->GetGlobalPose();
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2008-06-07 00:44:46 UTC (rev 6487)
+++ code/stage/trunk/libstage/model.cc 2008-06-07 01:15:39 UTC (rev 6488)
@@ -910,8 +910,8 @@
void StgModel::DrawImage( uint32_t texture_id, Stg::StgCanvas* canvas, float
alpha )
{
- double sphi = canvas->sphi;
- double stheta = canvas->stheta;
+ float stheta = -dtor( canvas->camera.getPitch() );
+ float sphi = dtor( canvas->camera.getYaw() );
glBindTexture( GL_TEXTURE_2D, 1 );
@@ -969,19 +969,23 @@
// draw speech bubble
if( this->say_string )
{
+ float stheta = -dtor( canvas->camera.getPitch() );
+ float sphi = dtor( canvas->camera.getYaw() );
+ float scale = canvas->camera.getScale(); //TODO FIX THIS
glPushMatrix();
// move above the robot
glTranslatef( 0, 0, 0.5 );
-
+
// rotate to face screen
- glRotatef( -rtod(global_pose.a + canvas->sphi), 0,0,1 );
- glRotatef( rtod(canvas->stheta), 1,0,0 );
+ glRotatef( -rtod(global_pose.a + sphi), 0,0,1 );
+ glRotatef( rtod(stheta), 1,0,0 );
- const float m = 4 / canvas->scale; // margin
- float w = gl_width( this->say_string ) / canvas->scale; // scaled text
width
- float h = gl_height() / canvas->scale; // scaled text height
+ const float m = 4 / scale; // margin
+ float w = gl_width( this->say_string ) / scale; // scaled text width
+ float h = gl_height() / scale; // scaled text height
+
// draw inside of bubble
PushColor( STG_BUBBLE_FILL );
glPushAttrib( GL_POLYGON_BIT | GL_LINE_BIT );
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-06-07 00:44:46 UTC (rev 6487)
+++ code/stage/trunk/libstage/stage.hh 2008-06-07 01:15:39 UTC (rev 6488)
@@ -53,6 +53,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <iostream>
// we use GLib's data structures extensively. Perhaps we'll move to
// C++ STL types to lose this dependency one day.
@@ -1696,6 +1697,62 @@
#include <FL/gl.h> // FLTK takes care of platform-specific GL stuff
#include <FL/glut.H>
+class StgCamera
+{
+private:
+ float _x, _y, _z;
+ float _pitch; //left-right (about y)
+ float _yaw; //up-down (about x)
+ float _scale;
+
+public:
+ StgCamera( void ) : _x( 0 ), _y( 0 ), _z( 0 ), _pitch( 0 ), _yaw( 0 ),
_scale( 15 ) { }
+ void Draw();
+
+ void move( float x, float y ) {
+ x = x / ( _scale * _scale );
+ y = y / ( _scale * _scale );
+
+ std::cout << _scale << std::endl;
+
+ _x += cos( dtor( _yaw ) ) * x;
+ _y += -sin( dtor( _yaw ) ) * x;
+
+ _x += sin( dtor( _yaw ) ) * y;
+ _y += cos( dtor( _yaw ) ) * y;
+ }
+ void yaw( float yaw ) {
+ _yaw += yaw;
+ }
+ void pitch( float pitch ) {
+ _pitch += pitch;
+ if( _pitch < -90 )
+ _pitch = -90;
+ else if( _pitch > 0 )
+ _pitch = 0;
+ }
+ inline float getYaw( void ) { return _yaw; }
+ inline float getPitch( void ) { return _pitch; }
+
+ inline void setYaw( float yaw ) { _yaw = yaw; }
+ inline void setPitch( float pitch ) { _pitch = pitch; }
+ inline void setScale( float scale ) { _scale = scale; }
+ inline void setPose( float x, float y) { _x = x; _y = y; }
+
+
+
+ void scale( float scale ) { _scale -= 0.5 * scale;
+ if( _scale < 1 ) _scale = 1;
+
+ }
+
+ inline void resetAngle( void ) { _pitch = _yaw = 0; }
+
+ inline float getScale() { return _scale; }
+ inline float getX() { return _x; }
+ inline float getY() { return _y; }
+};
+
class StgCanvas : public Fl_Gl_Window
{
friend class StgWorldGui; // allow access to private members
@@ -1703,8 +1760,9 @@
private:
GlColorStack colorstack;
- double scale;
- double panx, pany, stheta, sphi;
+
+ StgCamera camera;
+
int startx, starty;
bool dragging;
bool rotating;
Modified: code/stage/trunk/libstage/texture_manager.cc
===================================================================
--- code/stage/trunk/libstage/texture_manager.cc 2008-06-07 00:44:46 UTC
(rev 6487)
+++ code/stage/trunk/libstage/texture_manager.cc 2008-06-07 01:15:39 UTC
(rev 6488)
@@ -16,6 +16,7 @@
if( filename[ 0 ] == '/' || filename[ 0 ] == '~' )
return Fl_Shared_Image::get( filename );
+ //TODO move this somewhere else, and include STAGE_PATH, and path
relative to user supplied world file
const char* prefixes[] = {
".",
INSTALL_PREFIX "/share/stage",
@@ -28,7 +29,6 @@
std::ostringstream oss;
oss << prefixes[ i ] << "/" << filename;
img = Fl_Shared_Image::get( oss.str().c_str() );
- std::cout << "loading from: " << oss.str() << std::endl;
i++;
}
return img;
@@ -39,13 +39,13 @@
GLuint texName;
Fl_Shared_Image *img = loadImage( filename );
if( img == NULL ) {
- printf( "unable to open image: %s\n", filename );
+ fprintf( stderr, "unable to open image: %s\n", filename );
return 0;
}
//TODO display an error for incorrect depths
if( img->d() != 3 && img->d() != 4 ) {
- printf( "unable to open image: %s - incorrect depth - should be
3 or 4\n", filename );
+ fprintf( stderr, "unable to open image: %s - incorrect depth -
should be 3 or 4\n", filename );
return 0;
}
@@ -64,7 +64,6 @@
//create room for texture
glGenTextures(1, &texName);
- std::cout << "loading image to: " << texName << std::endl;
glBindTexture(GL_TEXTURE_2D, texName);
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-06-07 00:44:46 UTC (rev
6487)
+++ code/stage/trunk/libstage/worldgui.cc 2008-06-07 01:15:39 UTC (rev
6488)
@@ -243,12 +243,14 @@
//larger than this size.
size( width,height );
- canvas->panx = wf->ReadTupleFloat(wf_section, "center", 0, canvas->panx );
- canvas->pany = wf->ReadTupleFloat(wf_section, "center", 1, canvas->pany );
- canvas->stheta = wf->ReadTupleFloat( wf_section, "rotate", 0, canvas->stheta
);
- canvas->sphi = wf->ReadTupleFloat( wf_section, "rotate", 1, canvas->sphi );
- canvas->scale = wf->ReadFloat(wf_section, "scale", canvas->scale );
- canvas->interval = wf->ReadInt(wf_section, "interval", canvas->interval );
+ float x = wf->ReadTupleFloat(wf_section, "center", 0, 0 );
+ float y = wf->ReadTupleFloat(wf_section, "center", 1, 0 );
+ canvas->camera.setPose( x, y );
+
+ canvas->camera.setPitch( wf->ReadTupleFloat( wf_section, "rotate", 0, 0
) );
+ canvas->camera.setYaw( wf->ReadTupleFloat( wf_section, "rotate", 1, 0 )
);
+ canvas->camera.setScale( wf->ReadFloat(wf_section, "scale",
canvas->camera.getScale() ) );
+ canvas->interval = wf->ReadInt(wf_section, "interval", canvas->interval
);
// set the canvas visibilty flags
uint32_t flags = canvas->GetShowFlags();
@@ -305,14 +307,14 @@
wf->WriteTupleFloat( wf_section, "size", 0, w() );
wf->WriteTupleFloat( wf_section, "size", 1, h() );
- wf->WriteFloat( wf_section, "scale", canvas->scale );
+// wf->WriteFloat( wf_section, "scale", canvas->scale );
+//
+// wf->WriteTupleFloat( wf_section, "center", 0, canvas->panx );
+// wf->WriteTupleFloat( wf_section, "center", 1, canvas->pany );
+//
+// wf->WriteTupleFloat( wf_section, "rotate", 0, canvas->stheta );
+// wf->WriteTupleFloat( wf_section, "rotate", 1, canvas->sphi );
- wf->WriteTupleFloat( wf_section, "center", 0, canvas->panx );
- wf->WriteTupleFloat( wf_section, "center", 1, canvas->pany );
-
- wf->WriteTupleFloat( wf_section, "rotate", 0, canvas->stheta );
- wf->WriteTupleFloat( wf_section, "rotate", 1, canvas->sphi );
-
uint32_t flags = canvas->GetShowFlags();
wf->WriteInt( wf_section, "show_blocks", flags & STG_SHOW_BLOCKS );
wf->WriteInt( wf_section, "show_grid", flags & STG_SHOW_GRID );
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit