Revision: 6497
http://playerstage.svn.sourceforge.net/playerstage/?rev=6497&view=rev
Author: alexcb
Date: 2008-06-09 17:09:22 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
created camera model class
Modified Paths:
--------------
code/stage/trunk/libstage/CMakeLists.txt
code/stage/trunk/libstage/camera.cc
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/typetable.cc
Added Paths:
-----------
code/stage/trunk/libstage/model_camera.cc
Modified: code/stage/trunk/libstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt 2008-06-09 22:32:57 UTC (rev
6496)
+++ code/stage/trunk/libstage/CMakeLists.txt 2008-06-10 00:09:22 UTC (rev
6497)
@@ -10,6 +10,7 @@
model_blinkenlight.cc
model_blobfinder.cc
model_callbacks.cc
+ model_camera.cc
model_fiducial.cc
model_laser.cc
model_load.cc
Modified: code/stage/trunk/libstage/camera.cc
===================================================================
--- code/stage/trunk/libstage/camera.cc 2008-06-09 22:32:57 UTC (rev 6496)
+++ code/stage/trunk/libstage/camera.cc 2008-06-10 00:09:22 UTC (rev 6497)
@@ -12,11 +12,56 @@
#include <iostream>
-void StgCamera::Draw( void ) const
+//perspective camera
+//perspective camera
+void StgPerspectiveCamera::Draw( void ) const
{
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
+ glRotatef( - _pitch, 1.0, 0.0, 0.0 );
+ glRotatef( - _yaw, 0.0, 0.0, 1.0 );
+
+ std::cout << "y: " << _z << std::endl;
+ glTranslatef( - _x, - _y, - _z );
+ //zooming needs to happen in the Projection code (don't use glScale for
zoom)
+
+}
+
+void StgPerspectiveCamera::SetProjection( float pixels_width, float
pixels_height, float y_min, float y_max ) const
+{
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+
+ gluPerspective( 60.0, pixels_width/pixels_height, 0.01, 100 );
+
+ glMatrixMode (GL_MODELVIEW);
+}
+
+void StgPerspectiveCamera::update( void )
+{
+// _x = 0;
+// _y = 0;
+// _z = i;
+ _pitch = 90.0;
+// _yaw = 90.0;
+}
+
+
+
+
+
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//Ortho camera
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void StgOrthoCamera::Draw( void ) const
+{
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+
glRotatef( _pitch, 1.0, 0.0, 0.0 );
glRotatef( _yaw, 0.0, 0.0, 1.0 );
@@ -25,7 +70,7 @@
}
-void StgCamera::SetProjection( float pixels_width, float pixels_height, float
y_min, float y_max ) const
+void StgOrthoCamera::SetProjection( float pixels_width, float pixels_height,
float y_min, float y_max ) const
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@@ -38,7 +83,7 @@
}
//TODO re-evaluate the way the camera is shifted when the mouse zooms - it
might be possible to simplify
-void StgCamera::scale( float scale, float shift_x, float w, float shift_y,
float h )
+void StgOrthoCamera::scale( float scale, float shift_x, float w, float
shift_y, float h )
{
float to_scale = -scale;
const float old_scale = _scale;
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-09 22:32:57 UTC (rev 6496)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-10 00:09:22 UTC (rev 6497)
@@ -335,7 +335,180 @@
PopColor();
}
-void StgCanvas::draw()
+void StgCanvas::renderFrame()
+{
+
+ if( ! (showflags & STG_SHOW_TRAILS) )
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ // if following selected, shift the view to above the selected robot
+ if( (showflags & STG_SHOW_FOLLOW) && last_selection )
+ {
+ glLoadIdentity ();
+ double zclip = 20 * camera.getScale(); //hypot(world->Width(),
world->Height()) * camera.getScale();
+ glTranslatef( 0,0,
+ -zclip / 2.0 );
+
+ // meter scale
+ glScalef ( camera.getScale(), camera.getScale(),
camera.getScale() ); // zoom
+
+ stg_pose_t gpose = last_selection->GetGlobalPose();
+
+ // and put it in the center of the window
+ //glRotatef( -rtod(gpose.a), 0,0,1 );
+ glTranslatef( -gpose.x, -gpose.y, 0 );
+ }
+
+ glPushMatrix();
+
+ // draw the world size rectangle in white, using the polygon offset
+ // so it doesn't z-fight with the models
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(2.0, 2.0);
+
+ glScalef( 1.0/world->Resolution(), 1.0/world->Resolution(), 0 );
+ ((StgWorldGui*)world)->DrawFloor();
+
+ glDisable(GL_POLYGON_OFFSET_FILL);
+
+ if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY)
)
+ {
+ glDisable( GL_LINE_SMOOTH );
+ glLineWidth( 1 );
+ glPolygonMode( GL_FRONT, GL_LINE );
+ colorstack.Push(1,0,0);
+
+ if( showflags & STG_SHOW_OCCUPANCY )
+ ((StgWorldGui*)world)->DrawTree( false );
+
+ if( showflags & STG_SHOW_QUADTREE )
+ ((StgWorldGui*)world)->DrawTree( true );
+
+ colorstack.Pop();
+
+ glEnable( GL_LINE_SMOOTH );
+ }
+
+ glPopMatrix();
+
+ if( showflags & STG_SHOW_GRID )
+ DrawGlobalGrid();
+
+ for( GList* it=selected_models; it; it=it->next )
+ ((StgModel*)it->data)->DrawSelected();
+
+ // draw the models
+ if( showflags ) // if any bits are set there's something to draw
+ {
+ if( showflags & STG_SHOW_FOOTPRINT )
+ {
+ glDisable( GL_DEPTH_TEST );
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
+
+ for( GList* it=world->children; it; it=it->next )
+ {
+ ((StgModel*)it->data)->DrawTrailFootprint();
+ }
+ glEnable( GL_DEPTH_TEST );
+ }
+
+ if( showflags & STG_SHOW_TRAILRISE )
+ {
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
+
+ for( GList* it=world->children; it; it=it->next )
+ {
+ ((StgModel*)it->data)->DrawTrailBlocks();
+ }
+ }
+
+ if( showflags & STG_SHOW_ARROWS )
+ {
+ glEnable( GL_DEPTH_TEST );
+ for( GList* it=world->children; it; it=it->next )
+ {
+ ((StgModel*)it->data)->DrawTrailArrows();
+ }
+ }
+
+ if( showflags & STG_SHOW_BLOCKS )
+ {
+ for( GList* it=world->children; it; it=it->next )
+ {
+ StgModel* mod = ((StgModel*)it->data);
+
+ if( mod->displaylist == 0 )
+ {
+ mod->displaylist = glGenLists(1);
+ mod->BuildDisplayList( showflags ); //
ready to be rendered
+ }
+
+ // move into this model's local coordinate frame
+ glPushMatrix();
+ gl_pose_shift( &mod->pose );
+ gl_pose_shift( &mod->geom.pose );
+
+ // render the pre-recorded graphics for this
model and
+ // its children
+ glCallList( mod->displaylist );
+
+ glPopMatrix();
+ }
+ }
+
+ //mod->Draw( showflags ); // draw the stuff that changes every
update
+ // draw everything else
+ for( GList* it=world->children; it; it=it->next )
+ ((StgModel*)it->data)->Draw( showflags, this );
+ }
+
+ if( world->GetRayList() )
+ {
+ glDisable( GL_DEPTH_TEST );
+ PushColor( 0,0,0,0.5 );
+ for( GList* it = world->GetRayList(); it; it=it->next )
+ {
+ float* pts = (float*)it->data;
+ glBegin( GL_LINES );
+ glVertex2f( pts[0], pts[1] );
+ glVertex2f( pts[2], pts[3] );
+ glEnd();
+ }
+ PopColor();
+ glEnable( GL_DEPTH_TEST );
+
+ world->ClearRays();
+ }
+
+ if( showflags & STG_SHOW_CLOCK )
+ {
+ glPushMatrix();
+ glLoadIdentity();
+ glDisable( GL_DEPTH_TEST );
+
+ // if trails are on, we need to clear the clock background
+
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ colorstack.Push( 0.8,0.8,1.0 ); // pale blue
+ glRectf( -w()/2, -h()/2, -w()/2 +120, -h()/2+20 );
+ colorstack.Pop();
+
+ char clockstr[50];
+ world->ClockString( clockstr, 50 );
+
+ colorstack.Push( 0,0,0 ); // black
+ gl_draw_string( -w()/2+4, -h()/2+4, 5, clockstr );
+ colorstack.Pop();
+
+ glEnable( GL_DEPTH_TEST );
+ glPopMatrix();
+ }
+
+}
+
+void StgCanvas::draw()
{
static bool loaded_texture = false;
// static int centerx = 0, centery = 0;
@@ -388,176 +561,7 @@
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
-
-
-
- if( ! (showflags & STG_SHOW_TRAILS) )
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- // if following selected, shift the view to above the selected robot
- if( (showflags & STG_SHOW_FOLLOW) && last_selection )
- {
- glLoadIdentity ();
- double zclip = 20 * camera.getScale(); //hypot(world->Width(),
world->Height()) * camera.getScale();
- glTranslatef( 0,0,
- -zclip / 2.0 );
-
- // meter scale
- glScalef ( camera.getScale(), camera.getScale(), camera.getScale() ); //
zoom
-
- stg_pose_t gpose = last_selection->GetGlobalPose();
-
- // and put it in the center of the window
- //glRotatef( -rtod(gpose.a), 0,0,1 );
- glTranslatef( -gpose.x, -gpose.y, 0 );
- }
-
- glPushMatrix();
-
- // draw the world size rectangle in white, using the polygon offset
- // so it doesn't z-fight with the models
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(2.0, 2.0);
-
- glScalef( 1.0/world->Resolution(), 1.0/world->Resolution(), 0 );
- ((StgWorldGui*)world)->DrawFloor();
-
- glDisable(GL_POLYGON_OFFSET_FILL);
-
- if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) )
- {
- glDisable( GL_LINE_SMOOTH );
- glLineWidth( 1 );
- glPolygonMode( GL_FRONT, GL_LINE );
- colorstack.Push(1,0,0);
-
- if( showflags & STG_SHOW_OCCUPANCY )
- ((StgWorldGui*)world)->DrawTree( false );
-
- if( showflags & STG_SHOW_QUADTREE )
- ((StgWorldGui*)world)->DrawTree( true );
-
- colorstack.Pop();
-
- glEnable( GL_LINE_SMOOTH );
- }
-
- glPopMatrix();
-
- if( showflags & STG_SHOW_GRID )
- DrawGlobalGrid();
-
- for( GList* it=selected_models; it; it=it->next )
- ((StgModel*)it->data)->DrawSelected();
-
- // draw the models
- if( showflags ) // if any bits are set there's something to draw
- {
- if( showflags & STG_SHOW_FOOTPRINT )
- {
- glDisable( GL_DEPTH_TEST );
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
-
- for( GList* it=world->children; it; it=it->next )
- {
- ((StgModel*)it->data)->DrawTrailFootprint();
- }
- glEnable( GL_DEPTH_TEST );
- }
-
- if( showflags & STG_SHOW_TRAILRISE )
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
-
- for( GList* it=world->children; it; it=it->next )
- {
- ((StgModel*)it->data)->DrawTrailBlocks();
- }
- }
-
- if( showflags & STG_SHOW_ARROWS )
- {
- glEnable( GL_DEPTH_TEST );
- for( GList* it=world->children; it; it=it->next )
- {
- ((StgModel*)it->data)->DrawTrailArrows();
- }
- }
-
- if( showflags & STG_SHOW_BLOCKS )
- {
- for( GList* it=world->children; it; it=it->next )
- {
- StgModel* mod = ((StgModel*)it->data);
-
- if( mod->displaylist == 0 )
- {
- mod->displaylist = glGenLists(1);
- mod->BuildDisplayList( showflags ); // ready to be rendered
- }
-
- // move into this model's local coordinate frame
- glPushMatrix();
- gl_pose_shift( &mod->pose );
- gl_pose_shift( &mod->geom.pose );
-
- // render the pre-recorded graphics for this model and
- // its children
- glCallList( mod->displaylist );
-
- glPopMatrix();
- }
- }
-
- //mod->Draw( showflags ); // draw the stuff that changes every update
- // draw everything else
- for( GList* it=world->children; it; it=it->next )
- ((StgModel*)it->data)->Draw( showflags, this );
- }
-
- if( world->GetRayList() )
- {
- glDisable( GL_DEPTH_TEST );
- PushColor( 0,0,0,0.5 );
- for( GList* it = world->GetRayList(); it; it=it->next )
- {
- float* pts = (float*)it->data;
- glBegin( GL_LINES );
- glVertex2f( pts[0], pts[1] );
- glVertex2f( pts[2], pts[3] );
- glEnd();
- }
- PopColor();
- glEnable( GL_DEPTH_TEST );
-
- world->ClearRays();
- }
-
- if( showflags & STG_SHOW_CLOCK )
- {
- glPushMatrix();
- glLoadIdentity();
- glDisable( GL_DEPTH_TEST );
-
- // if trails are on, we need to clear the clock background
-
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
- colorstack.Push( 0.8,0.8,1.0 ); // pale blue
- glRectf( -w()/2, -h()/2, -w()/2 +120, -h()/2+20 );
- colorstack.Pop();
-
- char clockstr[50];
- world->ClockString( clockstr, 50 );
-
- colorstack.Push( 0,0,0 ); // black
- gl_draw_string( -w()/2+4, -h()/2+4, 5, clockstr );
- colorstack.Pop();
-
- glEnable( GL_DEPTH_TEST );
- glPopMatrix();
- }
+ renderFrame();
}
void StgCanvas::resize(int X,int Y,int W,int H)
Added: code/stage/trunk/libstage/model_camera.cc
===================================================================
--- code/stage/trunk/libstage/model_camera.cc (rev 0)
+++ code/stage/trunk/libstage/model_camera.cc 2008-06-10 00:09:22 UTC (rev
6497)
@@ -0,0 +1,70 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// File: model_camera.cc
+// Author: Alex Couture-Beil
+// Date: 09 June 2008
+//
+// CVS info:
+//
+///////////////////////////////////////////////////////////////////////////
+
+
+//#define DEBUG 1
+#include "stage_internal.hh"
+
+StgModelCamera::StgModelCamera( StgWorld* world,
+
StgModel* parent,
+
stg_id_t id,
+
char* typestr )
+: StgModel( world, parent, id, typestr )
+{
+ PRINT_DEBUG2( "Constructing StgModelCamera %d (%s)\n",
+ id, typestr );
+
+ // Set up sensible defaults
+
+ this->SetColor( stg_lookup_color( "green" ) );
+
+
+ stg_geom_t geom;
+ memset( &geom, 0, sizeof(geom)); // no size
+ geom.size.x = 0.02;
+ geom.size.y = 0.02;
+ geom.size.z = 0.02;
+ this->SetGeom( geom );
+
+ this->Startup();
+}
+
+StgModelCamera::~StgModelCamera()
+{
+}
+
+void StgModelCamera::Load( void )
+{
+ StgModel::Load();
+ Worldfile* wf = world->GetWorldFile();
+
+}
+
+
+void StgModelCamera::Update( void )
+{
+ StgModel::Update();
+ static StgPerspectiveCamera camera;
+ camera.update();
+ camera.SetProjection( 400, 300, 0.01, 200.0 );
+ camera.setPose( parent->GetGlobalPose().x, parent->GetGlobalPose().y,
0.1 );
+ camera.setYaw( rtod( parent->GetGlobalPose().a ) - 90.0 );
+ //camera.setPose( 0.1, 0.1, 0.1 );
+ camera.Draw();
+ std::cout << "updated" << std::endl;
+ std::cout << parent->GetGlobalPose().x << std::endl;
+}
+
+
+void StgModelCamera::Draw( uint32_t flags, StgCanvas* canvas )
+{
+ StgModel::Draw( flags, canvas );
+}
+
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-06-09 22:32:57 UTC (rev 6496)
+++ code/stage/trunk/libstage/stage.hh 2008-06-10 00:09:22 UTC (rev 6497)
@@ -1699,16 +1699,44 @@
class StgCamera
{
+public:
+ StgCamera() { }
+ virtual ~StgCamera() { }
+
+ virtual void Draw() const = 0;
+ virtual void SetProjection( float pixels_width, float pixels_height,
float y_min, float y_max ) const = 0;
+};
+
+class StgPerspectiveCamera : public StgCamera
+{
private:
float _x, _y, _z;
float _pitch; //left-right (about y)
float _yaw; //up-down (about x)
+
+public:
+ StgPerspectiveCamera( void ) : _x( 0 ), _y( 0 ), _z( 0 ), _pitch( 0 ),
_yaw( 0 ) { }
+
+ virtual void Draw() const;
+ virtual void SetProjection( float pixels_width, float pixels_height,
float y_min, float y_max ) const;
+ void update( void );
+
+ inline void setPose( float x, float y, float z ) { _x = x; _y = y; _z =
z; }
+ inline void setYaw( float yaw ) { _yaw = yaw; }
+};
+
+class StgOrthoCamera : public 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() const;
- void SetProjection( float pixels_width, float pixels_height, float
y_min, float y_max ) const;
+ StgOrthoCamera( void ) : _x( 0 ), _y( 0 ), _z( 0 ), _pitch( 0 ), _yaw(
0 ), _scale( 15 ) { }
+ virtual void Draw() const;
+ virtual void SetProjection( float pixels_width, float pixels_height,
float y_min, float y_max ) const;
inline void move( float x, float y ) {
@@ -1765,7 +1793,7 @@
private:
GlColorStack colorstack;
- StgCamera camera;
+ StgOrthoCamera camera;
int startx, starty;
bool dragging;
@@ -1791,6 +1819,7 @@
StgWorld* world;
void FixViewport(int W,int H);
+ virtual void renderFrame();
virtual void draw();
virtual int handle( int event );
void resize(int X,int Y,int W,int H);
@@ -2307,6 +2336,33 @@
}
};
+ // CAMERA MODEL ----------------------------------------------------
+ class StgModelCamera : public StgModel
+ {
+ public:
+
+ StgModelCamera( StgWorld* world,
+ StgModel*
parent,
+ stg_id_t id,
+ char* typestr
);
+
+ ~StgModelCamera();
+
+ virtual void Load();
+ virtual void Update();
+ virtual void Draw( uint32_t flags, StgCanvas* canvas );
+
+ // static wrapper for the constructor - all models must
implement
+ // this method and add an entry in typetable.cc
+ static StgModel* Create( StgWorld* world,
+
StgModel* parent,
+
stg_id_t id,
+ char*
typestr )
+ {
+ return (StgModel*)new StgModelCamera( world,
parent, id, typestr );
+ }
+ };
+
// POSITION MODEL --------------------------------------------------------
/** Define a position control method */
Modified: code/stage/trunk/libstage/typetable.cc
===================================================================
--- code/stage/trunk/libstage/typetable.cc 2008-06-09 22:32:57 UTC (rev
6496)
+++ code/stage/trunk/libstage/typetable.cc 2008-06-10 00:09:22 UTC (rev
6497)
@@ -12,6 +12,7 @@
{ "fiducial", StgModelFiducial::Create },
{ "blobfinder", StgModelBlobfinder::Create },
{ "blinkenlight", StgModelBlinkenlight::Create },
+ { "camera", StgModelCamera::Create },
{ NULL, NULL } // this must be the last entry
};
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