Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 574 lines (474 sloc) 13.453 kb
ec56d04 header clean up
rtv authored
1 #include "region.hh"
2 #include "worldfile.hh"
ec21888 removed world size limitation
rtv authored
3
ec56d04 header clean up
rtv authored
4 using namespace Stg;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
5 using std::vector;
6
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
7 static void canonicalize_winding(vector<point_t>& pts);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
8
ec21888 removed world size limitation
rtv authored
9
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
10 /** Create a new block. A model's body is a list of these
cfa70a3 experimenting with wavefront planner
rtv authored
11 blocks. The point data is copied, so pts can safely be freed
12 after calling this.*/
9efe76f fixing some memory leaks
thjc authored
13 Block::Block( Model* mod,
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
14 const std::vector<point_t>& pts,
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
15 meters_t zmin,
16 meters_t zmax,
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
17 Color color,
18 bool inherit_color,
19 bool wheel ) :
89dcdaf major changes for 3.1
rtv authored
20 mod( mod ),
17f2908 cleaning up Block class
rtv authored
21 mpts(),
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
22 pts(pts),
ff51521 cleaning up and STLization of BlockGroup
rtv authored
23 local_z( zmin, zmax ),
89dcdaf major changes for 3.1
rtv authored
24 color( color ),
25 inherit_color( inherit_color ),
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
26 wheel(wheel),
ff51521 cleaning up and STLization of BlockGroup
rtv authored
27 rendered_cells( new CellPtrVec ),
28 candidate_cells( new CellPtrVec ),
29 gpts()
89dcdaf major changes for 3.1
rtv authored
30 {
31 assert( mod );
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
32 canonicalize_winding(this->pts);
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
33 }
34
89dcdaf major changes for 3.1
rtv authored
35 /** A from-file constructor */
9efe76f fixing some memory leaks
thjc authored
36 Block::Block( Model* mod,
31e71c9 cleaning up
rtv authored
37 Worldfile* wf,
38 int entity)
89dcdaf major changes for 3.1
rtv authored
39 : mod( mod ),
1ce2551 cleaning up
rtv authored
40 mpts(),
17f2908 cleaning up Block class
rtv authored
41 pts(),
996c281 replaced some c-strings with std::strings
rtv authored
42 color(),
cfa70a3 experimenting with wavefront planner
rtv authored
43 inherit_color(true),
1ce2551 cleaning up
rtv authored
44 rendered_cells( new CellPtrVec ),
45 candidate_cells( new CellPtrVec )
89dcdaf major changes for 3.1
rtv authored
46 {
47 assert(mod);
48 assert(wf);
49 assert(entity);
ff51521 cleaning up and STLization of BlockGroup
rtv authored
50
89dcdaf major changes for 3.1
rtv authored
51 Load( wf, entity );
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
52 canonicalize_winding(this->pts);
89dcdaf major changes for 3.1
rtv authored
53 }
54
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
55 Block::~Block()
9efe76f fixing some memory leaks
thjc authored
56 {
89dcdaf major changes for 3.1
rtv authored
57 if( mapped ) UnMap();
ff51521 cleaning up and STLization of BlockGroup
rtv authored
58
59 delete rendered_cells;
8aab383 moved bit to STL
rtv authored
60 delete candidate_cells;
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
61 }
62
41a7d4a grippers partially implemented. they don't lift anything yet
rtv authored
63 void Block::Translate( double x, double y )
64 {
aa783ff block refactoring
rtv authored
65 FOR_EACH( it, pts )
cfa70a3 experimenting with wavefront planner
rtv authored
66 {
aa783ff block refactoring
rtv authored
67 it->x += x;
68 it->y += y;
cfa70a3 experimenting with wavefront planner
rtv authored
69 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
70
41a7d4a grippers partially implemented. they don't lift anything yet
rtv authored
71 mod->blockgroup.BuildDisplayList( mod );
72 }
73
74 double Block::CenterY()
75 {
76 double min = billion;
77 double max = -billion;
ff51521 cleaning up and STLization of BlockGroup
rtv authored
78
aa783ff block refactoring
rtv authored
79 FOR_EACH( it, pts )
cfa70a3 experimenting with wavefront planner
rtv authored
80 {
aa783ff block refactoring
rtv authored
81 if( it->y > max ) max = it->y;
82 if( it->y < min ) min = it->y;
cfa70a3 experimenting with wavefront planner
rtv authored
83 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
84
41a7d4a grippers partially implemented. they don't lift anything yet
rtv authored
85 // return the value half way between max and min
86 return( min + (max - min)/2.0 );
87 }
88
89 double Block::CenterX()
90 {
91 double min = billion;
92 double max = -billion;
ff51521 cleaning up and STLization of BlockGroup
rtv authored
93
aa783ff block refactoring
rtv authored
94 FOR_EACH( it, pts )
cfa70a3 experimenting with wavefront planner
rtv authored
95 {
aa783ff block refactoring
rtv authored
96 if( it->x > max ) max = it->x;
97 if( it->x < min ) min = it->x;
cfa70a3 experimenting with wavefront planner
rtv authored
98 }
9efe76f fixing some memory leaks
thjc authored
99
41a7d4a grippers partially implemented. they don't lift anything yet
rtv authored
100 // return the value half way between maxx and min
101 return( min + (max - min)/2.0 );
102 }
103
104 void Block::SetCenter( double x, double y )
105 {
106 // move the block by the distance required to bring its center to
107 // the requested position
108 Translate( x-CenterX(), y-CenterY() );
109 }
110
111 void Block::SetCenterY( double y )
112 {
113 // move the block by the distance required to bring its center to
114 // the requested position
115 Translate( 0, y-CenterY() );
116 }
117
118 void Block::SetCenterX( double x )
119 {
120 // move the block by the distance required to bring its center to
121 // the requested position
122 Translate( x-CenterX(), 0 );
123 }
124
125 void Block::SetZ( double min, double max )
126 {
127 local_z.min = min;
128 local_z.max = max;
129
130 // force redraw
131 mod->blockgroup.BuildDisplayList( mod );
132 }
133
c5247e1 fixed alwayson and model property bugs. Fixed stage.pc to include GL and...
rtv authored
134 const Color& Block::GetColor()
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
135 {
89dcdaf major changes for 3.1
rtv authored
136 return( inherit_color ? mod->color : color );
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
137 }
138
ff51521 cleaning up and STLization of BlockGroup
rtv authored
139 void Block::AppendTouchingModels( ModelPtrSet& touchers )
ff0dbdd working on charging model and demo
rtv authored
140 {
141 // for every cell we are rendered into
ff51521 cleaning up and STLization of BlockGroup
rtv authored
142 FOR_EACH( cell_it, *rendered_cells )
31e71c9 cleaning up
rtv authored
143 // for every block rendered into that cell
144 FOR_EACH( block_it, (*cell_it)->blocks )
145 {
146 if( !mod->IsRelated( (*block_it)->mod ))
147 touchers.insert( (*block_it)->mod );
148 }
ff0dbdd working on charging model and demo
rtv authored
149 }
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
150
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
151 Model* Block::TestCollision()
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
152 {
89dcdaf major changes for 3.1
rtv authored
153 //printf( "model %s block %p test collision...\n", mod->Token(), this );
154
155 // find the set of cells we would render into given the current global pose
156 GenerateCandidateCells();
ff51521 cleaning up and STLization of BlockGroup
rtv authored
157
ff0dbdd working on charging model and demo
rtv authored
158 if( mod->vis.obstacle_return )
0e620eb added collision with ground (z=0 plane) using patch #2929553 from RAZOR
rtv authored
159 {
160 if ( global_z.min < 0 )
161 return this->mod->world->GetGround();
162
cfa70a3 experimenting with wavefront planner
rtv authored
163 // for every cell we may be rendered into
712d746 fixed Z collision detection for blocks
rtv authored
164 FOR_EACH( cell_it, *candidate_cells )
cfa70a3 experimenting with wavefront planner
rtv authored
165 {
712d746 fixed Z collision detection for blocks
rtv authored
166 // for every block rendered into that cell
167 FOR_EACH( block_it, (*cell_it)->blocks )
168 {
169 Block* testblock = *block_it;
170 Model* testmod = testblock->mod;
171
172 //printf( " testing block %p of model %s\n", testblock, testmod->Token() );
173
174 // if the tested model is an obstacle and it's not attached to this model
175 if( (testmod != this->mod) &&
176 testmod->vis.obstacle_return &&
177 (!mod->IsRelated( testmod )) &&
178 // also must intersect in the Z range
179 testblock->global_z.min <= global_z.max &&
180 testblock->global_z.max >= global_z.min )
181 {
182 //puts( "HIT");
183 return testmod; // bail immediately with the bad news
184 }
185 }
186 }
0e620eb added collision with ground (z=0 plane) using patch #2929553 from RAZOR
rtv authored
187 }
712d746 fixed Z collision detection for blocks
rtv authored
188
89dcdaf major changes for 3.1
rtv authored
189 //printf( "model %s block %p collision done. no hits.\n", mod->Token(), this );
190 return NULL; // no hit
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
191 }
192
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
193 void Block::Map()
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
194 {
89dcdaf major changes for 3.1
rtv authored
195 // TODO - if called often, we may not need to generate each time
196 GenerateCandidateCells();
197 SwitchToTestedCells();
198 mapped = true;
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
199 }
200
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
201 void Block::UnMap()
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
202 {
89dcdaf major changes for 3.1
rtv authored
203 RemoveFromCellArray( rendered_cells );
8aab383 moved bit to STL
rtv authored
204 rendered_cells->clear();
89dcdaf major changes for 3.1
rtv authored
205 mapped = false;
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
206 }
207
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
208 #include <algorithm>
209 #include <functional>
210
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
211 inline void Block::RemoveFromCellArray( CellPtrVec *cells )
8aab383 moved bit to STL
rtv authored
212 {
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
213 // FOR_EACH( it, *cells )
214 // (*it)->RemoveBlock(this);
215
216 // this is equivalent to the above commented code - experimenting
217 // with optimizations
218 std::for_each( cells->begin(),
219 cells->end(),
220 std::bind2nd( std::mem_fun(&Cell::RemoveBlock), this));
250c54e performance tweaks
rtv authored
221
31e71c9 cleaning up
rtv authored
222 //printf( "%d %d %.2f\n", count1, countmore, ((float)count1)/float(countmore));
8aab383 moved bit to STL
rtv authored
223 }
224
0075eb0 attempted bugfix in Player fiducials (untested)
rtv authored
225 void Block::SwitchToTestedCells()
8aab383 moved bit to STL
rtv authored
226 {
31e71c9 cleaning up
rtv authored
227 // todo:
250c54e performance tweaks
rtv authored
228
31e71c9 cleaning up
rtv authored
229 // 1. find the set of cells in rendered but not candidate and remove
230 // them
250c54e performance tweaks
rtv authored
231
31e71c9 cleaning up
rtv authored
232 // 2. find the set of cells in candidate but not rendered and insert
233 // them
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
234
31e71c9 cleaning up
rtv authored
235 // .. and see if that is faster than the current method
250c54e performance tweaks
rtv authored
236
56f0f6d small optimization in Block::RemoveFromCellArray
Richard Vaughan authored
237 //printf( "rendered_cells %lu\n", rendered_cells->size() );
238 //printf( "candidate_cells %lu\n\n", candidate_cells->size() );
239
0075eb0 attempted bugfix in Player fiducials (untested)
rtv authored
240 RemoveFromCellArray( rendered_cells );
241
31e71c9 cleaning up
rtv authored
242 // render the block into each of the candidate cells
0075eb0 attempted bugfix in Player fiducials (untested)
rtv authored
243 FOR_EACH( it, *candidate_cells )
64249e4 more STLing and type safety to hopefully reduce bugs
rtv authored
244 {
245 Cell* cell = *it;
246 // record that I am rendered in this cell
247 rendered_cells->push_back( cell );
248 // store me in the cell
249 cell->blocks.push_back( this );
250c54e performance tweaks
rtv authored
250
64249e4 more STLing and type safety to hopefully reduce bugs
rtv authored
251 ++cell->region->count;
252 ++cell->region->superregion->count;
253 }
9efe76f fixing some memory leaks
thjc authored
254
89dcdaf major changes for 3.1
rtv authored
255 // switch current and candidate cell pointers
ff51521 cleaning up and STLization of BlockGroup
rtv authored
256 CellPtrVec *tmp = rendered_cells;
89dcdaf major changes for 3.1
rtv authored
257 rendered_cells = candidate_cells;
258 candidate_cells = tmp;
259
260 mapped = true;
261 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
262
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
263 inline point_t Block::BlockPointToModelMeters( const point_t& bpt )
750e048 fixed raserizer scaling bug
rtv authored
264 {
265 Size bgsize = mod->blockgroup.GetSize();
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
266 point3_t bgoffset = mod->blockgroup.GetOffset();
9efe76f fixing some memory leaks
thjc authored
267
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
268 return point_t( (bpt.x - bgoffset.x) * (mod->geom.size.x/bgsize.x),
31e71c9 cleaning up
rtv authored
269 (bpt.y - bgoffset.y) * (mod->geom.size.y/bgsize.y));
750e048 fixed raserizer scaling bug
rtv authored
270 }
271
80cdf19 cleaning up code
rtv authored
272 void Block::InvalidateModelPointCache()
273 {
ff51521 cleaning up and STLization of BlockGroup
rtv authored
274 // this doesn't happen often, so this simple strategy isn't too wasteful
275 mpts.clear();
80cdf19 cleaning up code
rtv authored
276 }
eaba4cb geometry fixes & graphics tweaks
rtv authored
277
80cdf19 cleaning up code
rtv authored
278 void Block::GenerateCandidateCells()
279 {
8aab383 moved bit to STL
rtv authored
280 candidate_cells->clear();
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
281
282 const unsigned int pt_count = pts.size();
283
17f2908 cleaning up Block class
rtv authored
284 if( mpts.size() == 0 )
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
285 {
31e71c9 cleaning up
rtv authored
286 // no valid cache of model coord points, so generate them
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
287 mpts.resize( pts.size() );
288
289
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
290 for( unsigned int i=0; i<pt_count; ++i )
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
291 mpts[i] = BlockPointToModelMeters( pts[i] );
292 }
31e71c9 cleaning up
rtv authored
293
294 gpts.clear();
295 mod->LocalToPixels( mpts, gpts );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
296
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
297 for( unsigned int i=0; i<pt_count; ++i )
56f0f6d small optimization in Block::RemoveFromCellArray
Richard Vaughan authored
298 mod->world->ForEachCellInLine( gpts[i],
299 gpts[(i+1)%pt_count],
300 *candidate_cells );
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
301
80cdf19 cleaning up code
rtv authored
302 // set global Z
303 Pose gpose = mod->GetGlobalPose();
304 gpose.z += mod->geom.pose.z;
305 double scalez = mod->geom.size.z / mod->blockgroup.GetSize().z;
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
306 meters_t z = gpose.z - mod->blockgroup.GetOffset().z;
ff51521 cleaning up and STLization of BlockGroup
rtv authored
307
89dcdaf major changes for 3.1
rtv authored
308 // store the block's absolute z bounds at this rendering
80cdf19 cleaning up code
rtv authored
309 global_z.min = (scalez * local_z.min) + z;
9efe76f fixing some memory leaks
thjc authored
310 global_z.max = (scalez * local_z.max) + z;
ff51521 cleaning up and STLization of BlockGroup
rtv authored
311
89dcdaf major changes for 3.1
rtv authored
312 mapped = true;
313 }
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
314
750e048 fixed raserizer scaling bug
rtv authored
315 void swap( int& a, int& b )
e96a997 added model rasterization
rtv authored
316 {
750e048 fixed raserizer scaling bug
rtv authored
317 int tmp = a;
318 a = b;
319 b = tmp;
e96a997 added model rasterization
rtv authored
320 }
321
9efe76f fixing some memory leaks
thjc authored
322 void Block::Rasterize( uint8_t* data,
31e71c9 cleaning up
rtv authored
323 unsigned int width,
324 unsigned int height,
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
325 meters_t cellwidth,
326 meters_t cellheight )
750e048 fixed raserizer scaling bug
rtv authored
327 {
328 //printf( "rasterize block %p : w: %u h: %u scale %.2f %.2f offset %.2f %.2f\n",
329 // this, width, height, scalex, scaley, offsetx, offsety );
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
330
331 const unsigned int pt_count = pts.size();
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
332 for( unsigned int i=0; i<pt_count; ++i )
750e048 fixed raserizer scaling bug
rtv authored
333 {
31e71c9 cleaning up
rtv authored
334 // convert points from local to model coords
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
335 point_t mpt1 = BlockPointToModelMeters( pts[i] );
336 point_t mpt2 = BlockPointToModelMeters( pts[(i+1)%pt_count] );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
337
31e71c9 cleaning up
rtv authored
338 // record for debug visualization
339 mod->rastervis.AddPoint( mpt1.x, mpt1.y );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
340
31e71c9 cleaning up
rtv authored
341 // shift to the bottom left of the model
342 mpt1.x += mod->geom.size.x/2.0;
343 mpt1.y += mod->geom.size.y/2.0;
344 mpt2.x += mod->geom.size.x/2.0;
345 mpt2.y += mod->geom.size.y/2.0;
ff51521 cleaning up and STLization of BlockGroup
rtv authored
346
31e71c9 cleaning up
rtv authored
347 // convert from meters to cells
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
348 point_int_t a( floor( mpt1.x / cellwidth ),
31e71c9 cleaning up
rtv authored
349 floor( mpt1.y / cellheight ));
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
350 point_int_t b( floor( mpt2.x / cellwidth ),
31e71c9 cleaning up
rtv authored
351 floor( mpt2.y / cellheight ) );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
352
31e71c9 cleaning up
rtv authored
353 bool steep = abs( b.y-a.y ) > abs( b.x-a.x );
354 if( steep )
355 {
356 swap( a.x, a.y );
357 swap( b.x, b.y );
358 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
359
31e71c9 cleaning up
rtv authored
360 if( a.x > b.x )
361 {
362 swap( a.x, b.x );
363 swap( a.y, b.y );
364 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
365
31e71c9 cleaning up
rtv authored
366 double dydx = (double) (b.y - a.y) / (double) (b.x - a.x);
367 double y = a.y;
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
368 for(int x=a.x; x<=b.x; ++x)
31e71c9 cleaning up
rtv authored
369 {
370 if( steep )
371 {
372 if( ! (floor(y) >= 0) ) continue;
373 if( ! (floor(y) < (int)width) ) continue;
374 if( ! (x >= 0) ) continue;
375 if( ! (x < (int)height) ) continue;
376 }
377 else
378 {
379 if( ! (x >= 0) ) continue;
380 if( ! (x < (int)width) ) continue;
381 if( ! (floor(y) >= 0) ) continue;
382 if( ! (floor(y) < (int)height) ) continue;
383 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
384
31e71c9 cleaning up
rtv authored
385 if( steep )
386 data[ (int)floor(y) + (x * width)] = 1;
387 else
388 data[ x + ((int)floor(y) * width)] = 1;
389 y += dydx;
390 }
391 }
e96a997 added model rasterization
rtv authored
392 }
393
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
394 void Block::DrawTop()
89dcdaf major changes for 3.1
rtv authored
395 {
396 // draw the top of the block - a polygon at the highest vertical
397 // extent
398 glBegin( GL_POLYGON);
31e71c9 cleaning up
rtv authored
399 FOR_EACH( it, pts )
400 glVertex3f( it->x, it->y, local_z.max );
89dcdaf major changes for 3.1
rtv authored
401 glEnd();
9efe76f fixing some memory leaks
thjc authored
402 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
403
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
404 void Block::DrawSides()
89dcdaf major changes for 3.1
rtv authored
405 {
9efe76f fixing some memory leaks
thjc authored
406 // construct a strip that wraps around the polygon
89dcdaf major changes for 3.1
rtv authored
407 glBegin(GL_QUAD_STRIP);
fec2ad5 cleaning up
rtv authored
408
31e71c9 cleaning up
rtv authored
409 FOR_EACH( it, pts )
410 {
fec2ad5 cleaning up
rtv authored
411 glVertex3f( it->x, it->y, local_z.max );
412 glVertex3f( it->x, it->y, local_z.min );
31e71c9 cleaning up
rtv authored
413 }
89dcdaf major changes for 3.1
rtv authored
414 // close the strip
415 glVertex3f( pts[0].x, pts[0].y, local_z.max );
416 glVertex3f( pts[0].x, pts[0].y, local_z.min );
417 glEnd();
418 }
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
419
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
420 void Block::DrawFootPrint()
89dcdaf major changes for 3.1
rtv authored
421 {
fec2ad5 cleaning up
rtv authored
422 glBegin(GL_POLYGON);
31e71c9 cleaning up
rtv authored
423 FOR_EACH( it, pts )
424 glVertex2f( it->x, it->y );
89dcdaf major changes for 3.1
rtv authored
425 glEnd();
426 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
427
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
428 void Block::DrawSolid()
89dcdaf major changes for 3.1
rtv authored
429 {
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
430 // if( wheel )
431 // {
432 // glPushMatrix();
433
434 // glRotatef( 90,0,1,0 );
435 // glRotatef( 90,1,0,0 );
436
437 // glTranslatef( -local_z.max /2.0, 0, 0 );
438
439
440 // GLUquadric* quadric = gluNewQuadric();
441 // gluQuadricDrawStyle( quadric, GLU_FILL );
442 // gluCylinder( quadric, local_z.max, local_z.max, size.x, 16, 16 );
443 // gluDeleteQuadric( quadric );
444
445 // glPopMatrix();
446 // }
447 // else
448 {
449 DrawSides();
450 DrawTop();
451 }
89dcdaf major changes for 3.1
rtv authored
452 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
453
3680786 API changes! removed the Stg prefix from all class names, and renamed so...
rtv authored
454 void Block::Load( Worldfile* wf, int entity )
89dcdaf major changes for 3.1
rtv authored
455 {
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
456 const unsigned int pt_count = wf->ReadInt( entity, "points", 0);
457
9efe76f fixing some memory leaks
thjc authored
458 char key[128];
0a5ba1d Richard Vaughan optmized FOR_EACH macro to assume container is not modified. other small...
authored
459 for( unsigned int p=0; p<pt_count; ++p )
31e71c9 cleaning up
rtv authored
460 {
461 snprintf(key, sizeof(key), "point[%d]", p );
462
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
463 pts.push_back( point_t( wf->ReadTupleLength(entity, key, 0, 0),
464 wf->ReadTupleLength(entity, key, 1, 0) ));
31e71c9 cleaning up
rtv authored
465 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
466
89dcdaf major changes for 3.1
rtv authored
467 local_z.min = wf->ReadTupleLength( entity, "z", 0, 0.0 );
468 local_z.max = wf->ReadTupleLength( entity, "z", 1, 1.0 );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
469
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
470 const std::string& colorstr = wf->ReadString( entity, "color", "" );
471
996c281 replaced some c-strings with std::strings
rtv authored
472 if( colorstr != "" )
cfa70a3 experimenting with wavefront planner
rtv authored
473 {
4ccc5cd replaced stg_color_t with Color class and added static named constructor...
rtv authored
474 color = Color( colorstr );
cfa70a3 experimenting with wavefront planner
rtv authored
475 inherit_color = false;
476 }
d60514d geometry & graphics fixes. added normalization of blocks to fit inside m...
rtv authored
477 else
08e31b0 added option to prevent stacking of models, based on patch #2919630 from...
rtv authored
478 inherit_color = true;
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
479
480 wheel = wf->ReadInt( entity, "wheel", wheel );
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl) to...
rtv authored
481 }
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
482
08e31b0 added option to prevent stacking of models, based on patch #2919630 from...
rtv authored
483 /////////////////////////////////////////////////////////////////////////////////////////
484 // utility functions to ensure block winding is consistent and matches OpenGL's default
485
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
486 static
487 /// util; puts angle into [0, 2pi)
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
488 void positivize(radians_t& angle)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
489 {
490 while (angle < 0) angle += 2 * M_PI;
491 }
492
493 static
494 /// util; puts angle into -pi/2, pi/2
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
495 void pi_ize(radians_t& angle)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
496 {
497 while (angle < -M_PI) angle += 2 * M_PI;
498 while (M_PI < angle) angle -= 2 * M_PI;
499 }
500
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
501 typedef point_t V2;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
502
503 static
504 /// util; How much was v1 rotated to get to v2?
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
505 radians_t angle_change(V2 v1, V2 v2)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
506 {
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
507 radians_t a1 = atan2(v1.y, v1.x);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
508 positivize(a1);
509
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
510 radians_t a2 = atan2(v2.y, v2.x);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
511 positivize(a2);
512
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
513 radians_t angle_change = a2 - a1;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
514 pi_ize(angle_change);
515
516 return angle_change;
517 }
518
519 static
520 /// util; find vectors between adjacent points, pts[next] - pts[cur]
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
521 vector<point_t> find_vectors(vector<point_t> const& pts)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
522 {
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
523 vector<point_t> vs;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
524 assert(2 <= pts.size());
525 for (unsigned i = 0, n = pts.size(); i < n; ++i)
526 {
527 unsigned j = (i + 1) % n;
528 vs.push_back(V2(pts[j].x - pts[i].x, pts[j].y - pts[i].y));
529 }
530 assert(vs.size() == pts.size());
531 return vs;
532 }
533
534 static
535 /// util; finds sum of angle changes, from each vertex to the
536 /// next one (in current ordering), wrapping around.
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
537 radians_t angles_sum(vector<point_t> const& vs)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
538 {
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
539 radians_t angle_sum = 0;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
540 for (unsigned i = 0, n = vs.size(); i < n; ++i)
541 {
542 unsigned j = (i + 1) % n;
543 angle_sum += angle_change(vs[i], vs[j]);
544 }
545 return angle_sum;
546 }
547
548 static
549 /// Util
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
550 bool is_canonical_winding(vector<point_t> const& ps)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
551 {
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
552 // reuse point_t as vector
553 vector<point_t> vs = find_vectors(ps);
554 radians_t sum = angles_sum(vs);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
555 bool bCanon = 0 < sum;
556
557 return bCanon;
558 }
559
560 static
561 /// util; sums angle changes to see whether it's 2pi or -2pi.
562 /// 2pi is counter-clockwise winding (which OpenGL requires),
563 /// -2pi is clockwise. Reverses <pts> when winding is clockwise.
564 // Note that a simple line that doubles back on itself has an
565 // angle sum of 0, but that's intrinsic to a line - its winding could
566 // be either way.
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
567 void canonicalize_winding(vector<point_t>& ps)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
568 {
569 if (not is_canonical_winding(ps))
570 {
571 std::reverse(ps.begin(), ps.end());
572 }
573 }
Something went wrong with that request. Please try again.