Skip to content

HTTPS clone URL

Subversion checkout URL

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