Revision: 6452
http://playerstage.svn.sourceforge.net/playerstage/?rev=6452&view=rev
Author: rtv
Date: 2008-05-22 18:34:45 -0700 (Thu, 22 May 2008)
Log Message:
-----------
more vertex arrays
Modified Paths:
--------------
code/stage/trunk/libstage/block.cc
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_laser.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/world.cc
code/stage/trunk/libstage/worldgui.cc
code/stage/trunk/worlds/fasr.world
Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc 2008-05-21 13:36:13 UTC (rev 6451)
+++ code/stage/trunk/libstage/block.cc 2008-05-23 01:34:45 UTC (rev 6452)
@@ -25,7 +25,9 @@
this->pt_count = pt_count;
this->pts = (stg_point_t*)g_memdup( pts, pt_count * sizeof(stg_point_t));
// allocate space for the integer version of the block vertices
- this->pts_global = new stg_point_int_t[pt_count];
+ this->pts_global_pixels = new stg_point_int_t[pt_count];
+ this->global_vertices = new stg_vertex_t[2*pt_count+2];
+
this->zmin = zmin;
this->zmax = zmax;
this->color = color;
@@ -36,6 +38,18 @@
// flag these as unset until StgBlock::Map() is called.
this->global_zmin = -1;
this->global_zmax = -1;
+
+ this->edge_indices = new GLubyte[ 6 * pt_count ];
+ for( int i=0; i<pt_count; i++ )
+ {
+ this->edge_indices[6*i] = 2*i;
+ this->edge_indices[6*i+1] = 2*i+1;
+ this->edge_indices[6*i+2] = 2*i;
+ this->edge_indices[6*i+3] = 2*i+2;
+ this->edge_indices[6*i+4] = 2*i+1;
+ this->edge_indices[6*i+5] = 2*i+3;
+ }
+
}
StgBlock::~StgBlock()
@@ -43,6 +57,8 @@
this->UnMap();
g_free( pts );
g_array_free( rendered_points, TRUE );
+
+ delete[] edge_indices;
}
void Stg::stg_block_list_destroy( GList* list )
@@ -57,18 +73,16 @@
void StgBlock::DrawTop()
{
// draw a top that fits over the side strip
- glBegin(GL_POLYGON);
-
- for( unsigned int p=0; p<pt_count; p++ )
- glVertex3f( pts[p].x, pts[p].y, zmax );
-
- glEnd();
+ glPushMatrix();
+ glTranslatef( 0,0,zmax);
+ glVertexPointer( 2, GL_DOUBLE, 0, pts );
+ glDrawArrays( GL_POLYGON, 0, pt_count );
+ glPopMatrix();
}
void StgBlock::DrawSides()
{
- // construct a strip that wraps around the polygon
-
+ // construct a strip that wraps around the polygon
glBegin(GL_QUAD_STRIP);
for( unsigned int p=0; p<pt_count; p++)
{
@@ -91,6 +105,7 @@
glEnd();
}
+
void StgBlock::Draw()
{
// draw filled color polygons
@@ -119,6 +134,45 @@
PopColor();
}
+void StgBlock::DrawGlobal()
+{
+ // draw filled color polygons
+ stg_color_t color = Color();
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
+ PushColor( color );
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(1.0, 1.0);
+
+ // glColorPointer(3, GL_UNSIGNED_BYTE, 0, colors );
+
+ // top - we skip every 2nd vertex
+ glVertexPointer( 3, GL_FLOAT, 6*sizeof(GLfloat), global_vertices );
+ glDrawArrays( GL_TRIANGLE_FAN, 0, pt_count );
+
+ // sides - we use all vertices
+ glVertexPointer( 3, GL_FLOAT, 0, global_vertices );
+ glDrawArrays( GL_TRIANGLE_STRIP, 0, pt_count*2+2 );
+
+ glDisable(GL_POLYGON_OFFSET_FILL);
+
+ // draw the block outline in a darker version of the same color
+ double r,g,b,a;
+ stg_color_unpack( color, &r, &g, &b, &a );
+ PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE );
+ glDepthMask(GL_FALSE);
+
+ // we use the array of vertices
+ glDrawElements( GL_LINES, pt_count*6, GL_UNSIGNED_BYTE, edge_indices );
+
+ glDepthMask(GL_TRUE);
+
+ PopColor();
+ PopColor();
+}
+
void StgBlock::Draw2D()
{
// draw filled color polygons
@@ -175,19 +229,35 @@
local.z = zmin;
global = mod->LocalToGlobal( local );
-
- pts_global[p].x = (int32_t)floor(global.x*ppm);
- pts_global[p].y = (int32_t)floor(global.y*ppm);
+ // top surface vertex
+ global_vertices[2*p].x = global.x;
+ global_vertices[2*p].y = global.y;
+ global_vertices[2*p].z = global.z + zmax;
+
+ // bottom surface vertex
+ global_vertices[2*p+1].x = global.x;
+ global_vertices[2*p+1].y = global.y;
+ global_vertices[2*p+1].z = global.z;
+
+ pts_global_pixels[p].x = (int32_t)floor(global.x*ppm);
+ pts_global_pixels[p].y = (int32_t)floor(global.y*ppm);
+
PRINT_DEBUG2("loc [%.2f %.2f]",
pts[p].x,
pts[p].y );
PRINT_DEBUG2("glb [%d %d]",
- pts_global[p].x,
- pts_global[p].y );
+ pts_global_pixels[p].x,
+ pts_global_pixels[p].y );
}
-
+
+ // close the strip
+ // top surface vertex
+ global_vertices[2*pt_count] = global_vertices[0];
+ global_vertices[2*pt_count+1] = global_vertices[1];
+
+
// store the block's global vertical bounds for inspection by the
// raytracer
global_zmin = global.z;
@@ -197,7 +267,7 @@
render_info.world = mod->GetWorld();
render_info.block = this;
- stg_polygon_3d( pts_global, pt_count,
+ stg_polygon_3d( pts_global_pixels, pt_count,
(stg_line3d_func_t)StgWorld::AddBlockPixel,
(void*)&render_info );
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-05-21 13:36:13 UTC (rev 6451)
+++ code/stage/trunk/libstage/canvas.cc 2008-05-23 01:34:45 UTC (rev 6452)
@@ -27,7 +27,7 @@
selected_models = NULL;
last_selection = NULL;
- startx = starty = 0;
+ startx = starty = 0;
panx = pany = stheta = sphi = 0.0;
scale = 15.0;
interval = 100; //msec between redraws
@@ -389,8 +389,13 @@
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
+ glEnableClientState( GL_VERTEX_ARRAY );
+ //glEnableClientState( GL_COLOR_ARRAY );
}
+
// Clear screen to bg color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@@ -459,18 +464,18 @@
{
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_TRAILS )
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
-
+
for( GList* it=world->children; it; it=it->next )
{
((StgModel*)it->data)->DrawTrailBlocks();
@@ -487,15 +492,14 @@
}
if( showflags & STG_SHOW_BLOCKS )
- for( GList* it=world->children; it; it=it->next )
{
- uint32_t flags = showflags;
-
- if( (stheta == 0) && (sphi == 0) )
- flags |= STG_SHOW_BLOCKS_2D;
-
- ((StgModel*)it->data)->Draw( flags );
+ for( GList* it=world->children; it; it=it->next )
+ ((StgModel*)it->data)->DrawBlocks();
}
+
+ // draw everything else
+ for( GList* it=world->children; it; it=it->next )
+ ((StgModel*)it->data)->Draw( showflags );
}
if( world->GetRayList() )
@@ -532,9 +536,6 @@
glEnable( GL_DEPTH_TEST );
glPopMatrix();
}
-
- // find all the flags
- //GList* flags = NULL;
}
void StgCanvas::resize(int X,int Y,int W,int H)
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2008-05-21 13:36:13 UTC (rev 6451)
+++ code/stage/trunk/libstage/model.cc 2008-05-23 01:34:45 UTC (rev 6452)
@@ -878,7 +878,20 @@
}
+void StgModel::DrawBlocks( )
+{
+ LISTMETHOD( this->children, StgModel*, DrawBlocks );
+ LISTMETHOD( this->blocks, StgBlock*, DrawGlobal );
+}
+
+void StgModel::DrawBlocks( gpointer dummykey,
+ StgModel* mod, void* dummyarg )
+{
+ mod->DrawBlocks();
+
+}
+
void StgModel::Draw( uint32_t flags )
{
//PRINT_DEBUG1( "Drawing %s", token );
@@ -889,17 +902,6 @@
gl_pose_shift( &this->pose );
gl_pose_shift( &this->geom.pose );
- // draw all the blocks
- if( flags & STG_SHOW_BLOCKS_2D )
- {
- LISTMETHOD( this->blocks, StgBlock*, Draw2D );
- }
- else if( flags & STG_SHOW_BLOCKS )
- {
- LISTMETHOD( this->blocks, StgBlock*, Draw );
- }
- //else
-
//if( this->say_string )
// gl_speech_bubble( 0,0,0, this->say_string );
Modified: code/stage/trunk/libstage/model_laser.cc
===================================================================
--- code/stage/trunk/libstage/model_laser.cc 2008-05-21 13:36:13 UTC (rev
6451)
+++ code/stage/trunk/libstage/model_laser.cc 2008-05-23 01:34:45 UTC (rev
6452)
@@ -299,6 +299,7 @@
this->data_dirty = true;
}
+
void StgModelLaser::DataVisualize( void )
{
if( ! (samples && sample_count) )
@@ -316,6 +317,10 @@
PushColor( 0, 0, 1, 0.5 );
+ glPointSize( 4.0 );
+
+ glVertexPointer( 2, GL_FLOAT, 0, pts );
+
for( unsigned int s=0; s<sample_count; s++ )
{
double ray_angle = (s * (fov / (sample_count-1))) - fov/2.0;
@@ -325,24 +330,23 @@
// if the sample is unusually bright, draw a little blob
if( samples[s].reflectance > 0 )
{
- glPointSize( 4.0 );
glBegin( GL_POINTS );
- glVertex2f( pts[2*s+2], pts[2*s+3] );
+ glVertex2f( pts[2*s+2], pts[2*s+3] );
glEnd();
+
+ // why doesn't this work?
+ //glDrawArrays( GL_POINTS, 2*s+2, 1 );
}
}
PopColor();
-
-
- glEnableClientState( GL_VERTEX_ARRAY );
- glVertexPointer( 2, GL_FLOAT, 0, pts );
-
+
glDepthMask( GL_FALSE );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
// draw the filled polygon in transparent blue
PushColor( 0, 0, 1, 0.1 );
+
glDrawArrays( GL_POLYGON, 0, sample_count+1 );
// draw the beam strike points in black
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-05-21 13:36:13 UTC (rev 6451)
+++ code/stage/trunk/libstage/stage.hh 2008-05-23 01:34:45 UTC (rev 6452)
@@ -312,6 +312,18 @@
/** define a point in 3d space */
typedef struct
{
+ float x, y, z;
+ } stg_vertex_t;
+
+ /** define vertex and its color */
+ typedef struct
+ {
+ float x, y, z, r, g, b, a;
+ } stg_colorvertex_t;
+
+ /** define a point in 3d space */
+ typedef struct
+ {
stg_meters_t x, y, z;
} stg_point3_t;
@@ -1016,6 +1028,9 @@
/** Enlarge the bounding volume to include this point */
void Extend( stg_point3_t pt );
+
+ //GHashTable* blocks;
+ GArray lines;
public:
@@ -1033,9 +1048,13 @@
stg_usec_t RealTimeSinceStart(void);
void PauseUntilNextUpdateTime(void);
void IdleUntilNextUpdateTime( int (*idler)(void) );
+
+ void AddBlock( StgBlock* block );
+ void RemoveBlock( StgBlock* block );
stg_usec_t GetSimInterval(){ return interval_sim; };
-
+
+
Worldfile* GetWorldFile(){ return wf; };
virtual void Load( const char* worldfile_path );
@@ -1225,6 +1244,14 @@
virtual void Update();
virtual void UpdatePose();
virtual void Draw( uint32_t flags );
+
+ virtual void DrawBlocks();
+
+ // static wrapper for DrawBlocks()
+ static void DrawBlocks( gpointer dummykey,
+ StgModel* mod,
+ void* arg );
+
virtual void DrawPicker();
virtual void DataVisualize();
@@ -1572,6 +1599,7 @@
void Map();
void UnMap(); // draw the block into the world
+ void DrawGlobal(); // draw the block in OpenGL using pts_global coords
void Draw(); // draw the block in OpenGL
void Draw2D(); // draw the block in OpenGL
void DrawSolid(); // draw the block in OpenGL as a solid single color
@@ -1601,9 +1629,12 @@
stg_meters_t global_zmax;
StgModel* mod; //< model to which this block belongs
- stg_point_int_t* pts_global; //< points defining a polygon in global coords
-
+ stg_point_int_t* pts_global_pixels; //< points defining a polygon in
global coords
+ stg_vertex_t* global_vertices; //< points defining a polygon in global
coords
+ //GLubyte* colors;
+ GLubyte* edge_indices;
+
stg_color_t color;
bool inherit_color;
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2008-05-21 13:36:13 UTC (rev 6451)
+++ code/stage/trunk/libstage/world.cc 2008-05-23 01:34:45 UTC (rev 6452)
@@ -147,6 +147,10 @@
this->paused = false;
this->destroy = false;
+ // store a global table of all blocks, so they can be rendered all
+ // at once.
+ //this->blocks = g_hash_table_new( NULL, NULL );
+
bzero( &this->extent, sizeof(this->extent));
for( unsigned int i=0; i<INTERVAL_LOG_LEN; i++ )
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-05-21 13:36:13 UTC (rev
6451)
+++ code/stage/trunk/libstage/worldgui.cc 2008-05-23 01:34:45 UTC (rev
6452)
@@ -350,4 +350,3 @@
g_hash_table_foreach( superregions, (GHFunc)SuperRegion::Floor_cb, NULL );
PopColor();
}
-
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2008-05-21 13:36:13 UTC (rev 6451)
+++ code/stage/trunk/worlds/fasr.world 2008-05-23 01:34:45 UTC (rev 6452)
@@ -18,7 +18,7 @@
resolution 0.02
interval_sim 100 # simulation timestep in milliseconds
-interval_real 10 # real-time interval between simulation updates in
milliseconds
+interval_real 0 # real-time interval between simulation updates in
milliseconds
paused 1
# configure the GUI window
@@ -59,7 +59,7 @@
define autorob pioneer2dx
(
color "red"
- sicklaser(pose [ 0.040 0.000 0.000 ] samples 32 )
+ sicklaser(pose [ 0.040 0.000 0.000 ] samples 32 range_max 5 laser_return 2 )
ctrl "fasr"
)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit