Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 515 lines (430 sloc) 12.095 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,
6b5f2c7 @rtv minor clean ups and speed ups
authored
14 const std::vector<point_t>& pts,
15 meters_t zmin,
16 meters_t zmax,
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 ),
6dd2b05 @rtv working on double-buffered bitmap for threaded move + raytrace - part…
authored
26 wheel(wheel),
c57874b @rtv cleaning up
authored
27 rendered_cells()
89dcdaf major changes for 3.1
rtv authored
28 {
29 assert( mod );
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
30 canonicalize_winding(this->pts);
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
31 }
32
89dcdaf major changes for 3.1
rtv authored
33 /** A from-file constructor */
9efe76f fixing some memory leaks
thjc authored
34 Block::Block( Model* mod,
6b5f2c7 @rtv minor clean ups and speed ups
authored
35 Worldfile* wf,
36 int entity)
89dcdaf major changes for 3.1
rtv authored
37 : mod( mod ),
1ce2551 cleaning up
rtv authored
38 mpts(),
17f2908 cleaning up Block class
rtv authored
39 pts(),
6b5f2c7 @rtv minor clean ups and speed ups
authored
40 local_z(),
996c281 replaced some c-strings with std::strings
rtv authored
41 color(),
cfa70a3 experimenting with wavefront planner
rtv authored
42 inherit_color(true),
6b5f2c7 @rtv minor clean ups and speed ups
authored
43 wheel(),
c57874b @rtv cleaning up
authored
44 rendered_cells()
89dcdaf major changes for 3.1
rtv authored
45 {
46 assert(mod);
47 assert(wf);
48 assert(entity);
ff51521 cleaning up and STLization of BlockGroup
rtv authored
49
89dcdaf major changes for 3.1
rtv authored
50 Load( wf, entity );
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
51 canonicalize_winding(this->pts);
89dcdaf major changes for 3.1
rtv authored
52 }
53
3680786 API changes! removed the Stg prefix from all class names, and renamed…
rtv authored
54 Block::~Block()
9efe76f fixing some memory leaks
thjc authored
55 {
ac35755 @rtv double-buffered multithread working
authored
56 if( mapped )
6b5f2c7 @rtv minor clean ups and speed ups
authored
57 {
58 UnMap(0);
59 UnMap(1);
60 }
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
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 {
6b5f2c7 @rtv minor clean ups and speed ups
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
6b5f2c7 @rtv minor clean ups and speed ups
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
6b5f2c7 @rtv minor clean ups and speed ups
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 …
rtv authored
134 const Color& Block::GetColor()
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
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)…
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 {
6dd2b05 @rtv working on double-buffered bitmap for threaded move + raytrace - part…
authored
141 unsigned int layer = mod->world->updates % 2;
142
ff0dbdd working on charging model and demo
rtv authored
143 // for every cell we are rendered into
6dd2b05 @rtv working on double-buffered bitmap for threaded move + raytrace - part…
authored
144 FOR_EACH( cell_it, rendered_cells[layer] )
6b5f2c7 @rtv minor clean ups and speed ups
authored
145 // for every block rendered into that cell
146 FOR_EACH( block_it, (*cell_it)->GetBlocks(layer) )
147 {
148 if( !mod->IsRelated( (*block_it)->mod ))
149 touchers.insert( (*block_it)->mod );
150 }
ff0dbdd working on charging model and demo
rtv authored
151 }
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
152
3680786 API changes! removed the Stg prefix from all class names, and renamed…
rtv authored
153 Model* Block::TestCollision()
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
154 {
89dcdaf major changes for 3.1
rtv authored
155 //printf( "model %s block %p test collision...\n", mod->Token(), this );
156
157 // 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
158 //GenerateCandidateCells();
ff51521 cleaning up and STLization of BlockGroup
rtv authored
159
ff0dbdd working on charging model and demo
rtv authored
160 if( mod->vis.obstacle_return )
6b5f2c7 @rtv minor clean ups and speed ups
authored
161 {
162 if ( global_z.min < 0 )
163 return mod->world->GetGround();
0e620eb added collision with ground (z=0 plane) using patch #2929553 from RAZOR
rtv authored
164
6b5f2c7 @rtv minor clean ups and speed ups
authored
165 unsigned int layer = mod->world->updates % 2;
166
167 // for every cell we may be rendered into
168 FOR_EACH( cell_it, rendered_cells[layer] )
169 {
170 // for every block rendered into that cell
171 FOR_EACH( block_it, (*cell_it)->GetBlocks(layer) )
172 {
173 Block* testblock = *block_it;
174 Model* testmod = testblock->mod;
712d746 fixed Z collision detection for blocks
rtv authored
175
6b5f2c7 @rtv minor clean ups and speed ups
authored
176 //printf( " testing block %p of model %s\n", testblock, testmod->Token() );
712d746 fixed Z collision detection for blocks
rtv authored
177
6b5f2c7 @rtv minor clean ups and speed ups
authored
178 // if the tested model is an obstacle and it's not attached to this model
179 if( (testmod != this->mod) &&
180 testmod->vis.obstacle_return &&
181 (!mod->IsRelated( testmod )) &&
182 // also must intersect in the Z range
183 testblock->global_z.min <= global_z.max &&
184 testblock->global_z.max >= global_z.min )
185 {
186 //puts( "HIT");
187 return testmod; // bail immediately with the bad news
712d746 fixed Z collision detection for blocks
rtv authored
188 }
6b5f2c7 @rtv minor clean ups and speed ups
authored
189 }
190 }
191 }
712d746 fixed Z collision detection for blocks
rtv authored
192
89dcdaf major changes for 3.1
rtv authored
193 //printf( "model %s block %p collision done. no hits.\n", mod->Token(), this );
194 return NULL; // no hit
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
195 }
196
047355a @rtv threaded double-buffer with raytracing and moving happening in differ…
authored
197 void Block::Map( unsigned int layer )
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
198 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
199 // calculate the local coords of the block vertices
200 const size_t pt_count(pts.size());
047355a @rtv threaded double-buffer with raytracing and moving happening in differ…
authored
201
55b9c56 @rtv simplified bitmap rendering (back to the old days) for speed and to a…
authored
202 if( mpts.size() == 0 )
6b5f2c7 @rtv minor clean ups and speed ups
authored
203 {
204 // no valid cache of model coord points, so generate them
205 mpts.resize( pts.size() );
55b9c56 @rtv simplified bitmap rendering (back to the old days) for speed and to a…
authored
206
6b5f2c7 @rtv minor clean ups and speed ups
authored
207 for( size_t i=0; i<pt_count; ++i )
208 mpts[i] = BlockPointToModelMeters( pts[i] );
209 }
55b9c56 @rtv simplified bitmap rendering (back to the old days) for speed and to a…
authored
210
6b5f2c7 @rtv minor clean ups and speed ups
authored
211 // now calculate the global pixel coords of the block vertices
c57874b @rtv cleaning up
authored
212 PointIntVec gpts;
55b9c56 @rtv simplified bitmap rendering (back to the old days) for speed and to a…
authored
213 mod->LocalToPixels( mpts, gpts );
edbf437 @rtv small optimizations
authored
214
6b5f2c7 @rtv minor clean ups and speed ups
authored
215 // and render this block's polygon into the world
216 mod->world->MapPoly( gpts, this, layer );
55b9c56 @rtv simplified bitmap rendering (back to the old days) for speed and to a…
authored
217
218 // update the block's absolute z bounds at this rendering
edbf437 @rtv small optimizations
authored
219 Pose gpose( mod->GetGlobalPose() );
55b9c56 @rtv simplified bitmap rendering (back to the old days) for speed and to a…
authored
220 gpose.z += mod->geom.pose.z;
edbf437 @rtv small optimizations
authored
221 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
222 meters_t z = gpose.z - mod->blockgroup.GetOffset().z;
223 global_z.min = (scalez * local_z.min) + z;
224 global_z.max = (scalez * local_z.max) + z;
225
226 mapped = true;
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
227 }
228
0a5ba1d @rtv optmized FOR_EACH macro to assume container is not modified. other sm…
authored
229 #include <algorithm>
230 #include <functional>
231
047355a @rtv threaded double-buffer with raytracing and moving happening in differ…
authored
232 void Block::UnMap( unsigned int layer )
8aab383 moved bit to STL
rtv authored
233 {
6dd2b05 @rtv working on double-buffered bitmap for threaded move + raytrace - part…
authored
234 FOR_EACH( it, rendered_cells[layer] )
6b5f2c7 @rtv minor clean ups and speed ups
authored
235 (*it)->RemoveBlock(this, layer );
6dd2b05 @rtv working on double-buffered bitmap for threaded move + raytrace - part…
authored
236
237 rendered_cells[layer].clear();
65dcf8c @rtv working on threaded pose support
authored
238 mapped = false;
89dcdaf major changes for 3.1
rtv authored
239 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
240
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
241 inline point_t Block::BlockPointToModelMeters( const point_t& bpt )
750e048 fixed raserizer scaling bug
rtv authored
242 {
243 Size bgsize = mod->blockgroup.GetSize();
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
244 point3_t bgoffset = mod->blockgroup.GetOffset();
9efe76f fixing some memory leaks
thjc authored
245
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
246 return point_t( (bpt.x - bgoffset.x) * (mod->geom.size.x/bgsize.x),
6b5f2c7 @rtv minor clean ups and speed ups
authored
247 (bpt.y - bgoffset.y) * (mod->geom.size.y/bgsize.y));
750e048 fixed raserizer scaling bug
rtv authored
248 }
249
80cdf19 cleaning up code
rtv authored
250 void Block::InvalidateModelPointCache()
251 {
ff51521 cleaning up and STLization of BlockGroup
rtv authored
252 // this doesn't happen often, so this simple strategy isn't too wasteful
253 mpts.clear();
80cdf19 cleaning up code
rtv authored
254 }
eaba4cb geometry fixes & graphics tweaks
rtv authored
255
750e048 fixed raserizer scaling bug
rtv authored
256 void swap( int& a, int& b )
e96a997 added model rasterization
rtv authored
257 {
750e048 fixed raserizer scaling bug
rtv authored
258 int tmp = a;
259 a = b;
260 b = tmp;
e96a997 added model rasterization
rtv authored
261 }
262
9efe76f fixing some memory leaks
thjc authored
263 void Block::Rasterize( uint8_t* data,
6b5f2c7 @rtv minor clean ups and speed ups
authored
264 unsigned int width,
265 unsigned int height,
266 meters_t cellwidth,
267 meters_t cellheight )
750e048 fixed raserizer scaling bug
rtv authored
268 {
269 //printf( "rasterize block %p : w: %u h: %u scale %.2f %.2f offset %.2f %.2f\n",
270 // this, width, height, scalex, scaley, offsetx, offsety );
e8d54f8 replacing some C style arrays with vectors and strings, for consistency
Richard Vaughan authored
271
6b5f2c7 @rtv minor clean ups and speed ups
authored
272 const size_t pt_count = pts.size();
edbf437 @rtv small optimizations
authored
273 for( size_t i=0; i<pt_count; ++i )
750e048 fixed raserizer scaling bug
rtv authored
274 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
275 // convert points from local to model coords
276 point_t mpt1 = BlockPointToModelMeters( pts[i] );
277 point_t mpt2 = BlockPointToModelMeters( pts[(i+1)%pt_count] );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
278
6b5f2c7 @rtv minor clean ups and speed ups
authored
279 // record for debug visualization
280 mod->rastervis.AddPoint( mpt1.x, mpt1.y );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
281
6b5f2c7 @rtv minor clean ups and speed ups
authored
282 // shift to the bottom left of the model
283 mpt1.x += mod->geom.size.x/2.0;
284 mpt1.y += mod->geom.size.y/2.0;
285 mpt2.x += mod->geom.size.x/2.0;
286 mpt2.y += mod->geom.size.y/2.0;
ff51521 cleaning up and STLization of BlockGroup
rtv authored
287
6b5f2c7 @rtv minor clean ups and speed ups
authored
288 // convert from meters to cells
289 point_int_t a( floor( mpt1.x / cellwidth ),
290 floor( mpt1.y / cellheight ));
291 point_int_t b( floor( mpt2.x / cellwidth ),
292 floor( mpt2.y / cellheight ) );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
293
6b5f2c7 @rtv minor clean ups and speed ups
authored
294 bool steep = abs( b.y-a.y ) > abs( b.x-a.x );
295 if( steep )
296 {
297 swap( a.x, a.y );
298 swap( b.x, b.y );
299 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
300
6b5f2c7 @rtv minor clean ups and speed ups
authored
301 if( a.x > b.x )
302 {
303 swap( a.x, b.x );
304 swap( a.y, b.y );
305 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
306
6b5f2c7 @rtv minor clean ups and speed ups
authored
307 double dydx = (double) (b.y - a.y) / (double) (b.x - a.x);
308 double y = a.y;
309 for(int x=a.x; x<=b.x; ++x)
310 {
311 if( steep )
312 {
313 if( ! (floor(y) >= 0) ) continue;
314 if( ! (floor(y) < (int)width) ) continue;
315 if( ! (x >= 0) ) continue;
316 if( ! (x < (int)height) ) continue;
317 }
318 else
319 {
320 if( ! (x >= 0) ) continue;
321 if( ! (x < (int)width) ) continue;
322 if( ! (floor(y) >= 0) ) continue;
323 if( ! (floor(y) < (int)height) ) continue;
324 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
325
6b5f2c7 @rtv minor clean ups and speed ups
authored
326 if( steep )
327 data[ (int)floor(y) + (x * width)] = 1;
328 else
329 data[ x + ((int)floor(y) * width)] = 1;
330 y += dydx;
331 }
332 }
e96a997 added model rasterization
rtv authored
333 }
334
3680786 API changes! removed the Stg prefix from all class names, and renamed…
rtv authored
335 void Block::DrawTop()
89dcdaf major changes for 3.1
rtv authored
336 {
337 // draw the top of the block - a polygon at the highest vertical
338 // extent
339 glBegin( GL_POLYGON);
31e71c9 cleaning up
rtv authored
340 FOR_EACH( it, pts )
6b5f2c7 @rtv minor clean ups and speed ups
authored
341 glVertex3f( it->x, it->y, local_z.max );
89dcdaf major changes for 3.1
rtv authored
342 glEnd();
9efe76f fixing some memory leaks
thjc authored
343 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
344
3680786 API changes! removed the Stg prefix from all class names, and renamed…
rtv authored
345 void Block::DrawSides()
89dcdaf major changes for 3.1
rtv authored
346 {
9efe76f fixing some memory leaks
thjc authored
347 // construct a strip that wraps around the polygon
89dcdaf major changes for 3.1
rtv authored
348 glBegin(GL_QUAD_STRIP);
fec2ad5 cleaning up
rtv authored
349
31e71c9 cleaning up
rtv authored
350 FOR_EACH( it, pts )
6b5f2c7 @rtv minor clean ups and speed ups
authored
351 {
fec2ad5 cleaning up
rtv authored
352 glVertex3f( it->x, it->y, local_z.max );
353 glVertex3f( it->x, it->y, local_z.min );
6b5f2c7 @rtv minor clean ups and speed ups
authored
354 }
89dcdaf major changes for 3.1
rtv authored
355 // close the strip
356 glVertex3f( pts[0].x, pts[0].y, local_z.max );
357 glVertex3f( pts[0].x, pts[0].y, local_z.min );
358 glEnd();
359 }
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
360
3680786 API changes! removed the Stg prefix from all class names, and renamed…
rtv authored
361 void Block::DrawFootPrint()
89dcdaf major changes for 3.1
rtv authored
362 {
fec2ad5 cleaning up
rtv authored
363 glBegin(GL_POLYGON);
31e71c9 cleaning up
rtv authored
364 FOR_EACH( it, pts )
6b5f2c7 @rtv minor clean ups and speed ups
authored
365 glVertex2f( it->x, it->y );
89dcdaf major changes for 3.1
rtv authored
366 glEnd();
367 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
368
ac35755 @rtv double-buffered multithread working
authored
369 void Block::DrawSolid( bool topview )
89dcdaf major changes for 3.1
rtv authored
370 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
371 // if( wheel )x
ac35755 @rtv double-buffered multithread working
authored
372 // {
6b5f2c7 @rtv minor clean ups and speed ups
authored
373 // glPushMatrix();
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
374
6b5f2c7 @rtv minor clean ups and speed ups
authored
375 // glRotatef( 90,0,1,0 );
376 // glRotatef( 90,1,0,0 );
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
377
6b5f2c7 @rtv minor clean ups and speed ups
authored
378 // glTranslatef( -local_z.max /2.0, 0, 0 );
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
379
380
6b5f2c7 @rtv minor clean ups and speed ups
authored
381 // GLUquadric* quadric = gluNewQuadric();
382 // gluQuadricDrawStyle( quadric, GLU_FILL );
383 // gluCylinder( quadric, local_z.max, local_z.max, size.x, 16, 16 );
384 // gluDeleteQuadric( quadric );
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
385
6b5f2c7 @rtv minor clean ups and speed ups
authored
386 // glPopMatrix();
387 // }
388 // else
ac35755 @rtv double-buffered multithread working
authored
389 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
390 if( ! topview )
391 DrawSides();
ac35755 @rtv double-buffered multithread working
authored
392
6b5f2c7 @rtv minor clean ups and speed ups
authored
393 DrawTop();
ac35755 @rtv double-buffered multithread working
authored
394 }
89dcdaf major changes for 3.1
rtv authored
395 }
22a1279 fixed indentation issues (converted to tabs)
alexcb authored
396
3680786 API changes! removed the Stg prefix from all class names, and renamed…
rtv authored
397 void Block::Load( Worldfile* wf, int entity )
89dcdaf major changes for 3.1
rtv authored
398 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
399 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
400
9efe76f fixing some memory leaks
thjc authored
401 char key[128];
edbf437 @rtv small optimizations
authored
402 for( size_t p=0; p<pt_count; ++p )
6b5f2c7 @rtv minor clean ups and speed ups
authored
403 {
404 snprintf(key, sizeof(key), "point[%d]", (int)p );
31e71c9 cleaning up
rtv authored
405
6b5f2c7 @rtv minor clean ups and speed ups
authored
406 pts.push_back( point_t( wf->ReadTupleLength(entity, key, 0, 0),
407 wf->ReadTupleLength(entity, key, 1, 0) ));
408 }
ff51521 cleaning up and STLization of BlockGroup
rtv authored
409
89dcdaf major changes for 3.1
rtv authored
410 local_z.min = wf->ReadTupleLength( entity, "z", 0, 0.0 );
411 local_z.max = wf->ReadTupleLength( entity, "z", 1, 1.0 );
ff51521 cleaning up and STLization of BlockGroup
rtv authored
412
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
413 const std::string& colorstr = wf->ReadString( entity, "color", "" );
414
996c281 replaced some c-strings with std::strings
rtv authored
415 if( colorstr != "" )
cfa70a3 experimenting with wavefront planner
rtv authored
416 {
4ccc5cd replaced stg_color_t with Color class and added static named construc…
rtv authored
417 color = Color( colorstr );
cfa70a3 experimenting with wavefront planner
rtv authored
418 inherit_color = false;
419 }
d60514d geometry & graphics fixes. added normalization of blocks to fit insid…
rtv authored
420 else
08e31b0 added option to prevent stacking of models, based on patch #2919630 f…
rtv authored
421 inherit_color = true;
6ec6357 merged Apple/Linux conditional build from Rich via Jenny
Richard Vaughan authored
422
6b5f2c7 @rtv minor clean ups and speed ups
authored
423 wheel = wf->ReadInt( entity, "wheel", wheel );
36bfbdb first commit since shifting the Stage-3.0 development branch (opengl)…
rtv authored
424 }
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
425
08e31b0 added option to prevent stacking of models, based on patch #2919630 f…
rtv authored
426 /////////////////////////////////////////////////////////////////////////////////////////
427 // utility functions to ensure block winding is consistent and matches OpenGL's default
428
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
429 static
430 /// util; puts angle into [0, 2pi)
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
431 void positivize(radians_t& angle)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
432 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
433 while (angle < 0) angle += 2 * M_PI;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
434 }
435
436 static
437 /// util; puts angle into -pi/2, pi/2
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
438 void pi_ize(radians_t& angle)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
439 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
440 while (angle < -M_PI) angle += 2 * M_PI;
441 while (M_PI < angle) angle -= 2 * M_PI;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
442 }
443
444 static
445 /// util; How much was v1 rotated to get to v2?
65dcf8c @rtv working on threaded pose support
authored
446 radians_t angle_change(point_t v1, point_t v2)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
447 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
448 radians_t a1 = atan2(v1.y, v1.x);
449 positivize(a1);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
450
6b5f2c7 @rtv minor clean ups and speed ups
authored
451 radians_t a2 = atan2(v2.y, v2.x);
452 positivize(a2);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
453
6b5f2c7 @rtv minor clean ups and speed ups
authored
454 radians_t angle_change = a2 - a1;
455 pi_ize(angle_change);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
456
6b5f2c7 @rtv minor clean ups and speed ups
authored
457 return angle_change;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
458 }
459
460 static
461 /// util; find vectors between adjacent points, pts[next] - pts[cur]
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
462 vector<point_t> find_vectors(vector<point_t> const& pts)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
463 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
464 vector<point_t> vs;
465 assert(2 <= pts.size());
466 for (unsigned i = 0, n = pts.size(); i < n; ++i)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
467 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
468 unsigned j = (i + 1) % n;
469 vs.push_back(point_t(pts[j].x - pts[i].x, pts[j].y - pts[i].y));
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
470 }
6b5f2c7 @rtv minor clean ups and speed ups
authored
471 assert(vs.size() == pts.size());
472 return vs;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
473 }
474
475 static
476 /// util; finds sum of angle changes, from each vertex to the
477 /// next one (in current ordering), wrapping around.
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
478 radians_t angles_sum(vector<point_t> const& vs)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
479 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
480 radians_t angle_sum = 0;
481 for (unsigned i = 0, n = vs.size(); i < n; ++i)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
482 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
483 unsigned j = (i + 1) % n;
484 angle_sum += angle_change(vs[i], vs[j]);
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
485 }
6b5f2c7 @rtv minor clean ups and speed ups
authored
486 return angle_sum;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
487 }
488
489 static
490 /// Util
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
491 bool is_canonical_winding(vector<point_t> const& ps)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
492 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
493 // reuse point_t as vector
494 vector<point_t> vs = find_vectors(ps);
495 radians_t sum = angles_sum(vs);
496 bool bCanon = 0 < sum;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
497
6b5f2c7 @rtv minor clean ups and speed ups
authored
498 return bCanon;
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
499 }
500
501 static
502 /// util; sums angle changes to see whether it's 2pi or -2pi.
503 /// 2pi is counter-clockwise winding (which OpenGL requires),
504 /// -2pi is clockwise. Reverses <pts> when winding is clockwise.
505 // Note that a simple line that doubles back on itself has an
506 // angle sum of 0, but that's intrinsic to a line - its winding could
507 // be either way.
e45b70c combined laser and ranger functionality into ranger - still buggy
Richard Vaughan authored
508 void canonicalize_winding(vector<point_t>& ps)
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
509 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
510 if (not is_canonical_winding(ps))
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
511 {
6b5f2c7 @rtv minor clean ups and speed ups
authored
512 std::reverse(ps.begin(), ps.end());
e5a483c removing unused code. applied polygon winding patch from Jeff Donner
rtv authored
513 }
514 }
Something went wrong with that request. Please try again.