Skip to content
This repository
Newer
Older
100644 518 lines (422 sloc) 11.813 kb
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
1
ec56d041 »
2009-01-22 header clean up
2 #include "region.hh"
3 #include "worldfile.hh"
ec218885 »
2008-02-01 removed world size limitation
4
ec56d041 »
2009-01-22 header clean up
5 using namespace Stg;
ec218885 »
2008-02-01 removed world size limitation
6
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
7 /** Create a new block. A model's body is a list of these
cfa70a3d »
2009-03-20 experimenting with wavefront planner
8 blocks. The point data is copied, so pts can safely be freed
9 after calling this.*/
9efe76f6 »
2009-05-09 fixing some memory leaks
10 Block::Block( Model* mod,
11 stg_point_t* pts,
80cdf194 »
2009-04-11 cleaning up code
12 size_t pt_count,
13 stg_meters_t zmin,
14 stg_meters_t zmax,
15 stg_color_t color,
16 bool inherit_color
17 ) :
89dcdaf1 »
2008-11-15 major changes for 3.1
18 mod( mod ),
80cdf194 »
2009-04-11 cleaning up code
19 mpts(NULL),
89dcdaf1 »
2008-11-15 major changes for 3.1
20 pt_count( pt_count ),
21 pts( (stg_point_t*)g_memdup( pts, pt_count * sizeof(stg_point_t)) ),
22 color( color ),
23 inherit_color( inherit_color ),
8aab383b »
2009-05-22 moved bit to STL
24 rendered_cells( new std::vector<Cell*> ),
25 candidate_cells( new std::vector<Cell*> )
89dcdaf1 »
2008-11-15 major changes for 3.1
26 {
27 assert( mod );
28 assert( pt_count > 0 );
29 assert( pts );
30
31 local_z.min = zmin;
32 local_z.max = zmax;
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
33 }
34
89dcdaf1 »
2008-11-15 major changes for 3.1
35 /** A from-file constructor */
9efe76f6 »
2009-05-09 fixing some memory leaks
36 Block::Block( Model* mod,
37 Worldfile* wf,
38 int entity)
89dcdaf1 »
2008-11-15 major changes for 3.1
39 : mod( mod ),
80cdf194 »
2009-04-11 cleaning up code
40 mpts(NULL),
9efe76f6 »
2009-05-09 fixing some memory leaks
41 pt_count(0),
42 pts(NULL),
cfa70a3d »
2009-03-20 experimenting with wavefront planner
43 color(0),
44 inherit_color(true),
8aab383b »
2009-05-22 moved bit to STL
45 rendered_cells( new std::vector<Cell*> ),
46 candidate_cells( new std::vector<Cell*> )
89dcdaf1 »
2008-11-15 major changes for 3.1
47 {
48 assert(mod);
49 assert(wf);
50 assert(entity);
9efe76f6 »
2009-05-09 fixing some memory leaks
51
89dcdaf1 »
2008-11-15 major changes for 3.1
52 Load( wf, entity );
53 }
54
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
55 Block::~Block()
9efe76f6 »
2009-05-09 fixing some memory leaks
56 {
89dcdaf1 »
2008-11-15 major changes for 3.1
57 if( mapped ) UnMap();
9efe76f6 »
2009-05-09 fixing some memory leaks
58
83e6bb14 »
2009-04-11 spring cleaning
59 if( pts ) delete[] pts;
9efe76f6 »
2009-05-09 fixing some memory leaks
60 InvalidateModelPointCache();
61
8aab383b »
2009-05-22 moved bit to STL
62 delete rendered_cells;
63 delete candidate_cells;
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
64 }
65
41a7d4a7 »
2009-02-13 grippers partially implemented. they don't lift anything yet
66 void Block::Translate( double x, double y )
67 {
68 for( unsigned int p=0; p<pt_count; p++)
cfa70a3d »
2009-03-20 experimenting with wavefront planner
69 {
70 pts[p].x += x;
71 pts[p].y += y;
72 }
9efe76f6 »
2009-05-09 fixing some memory leaks
73
41a7d4a7 »
2009-02-13 grippers partially implemented. they don't lift anything yet
74 mod->blockgroup.BuildDisplayList( mod );
75 }
76
77 double Block::CenterY()
78 {
79 double min = billion;
80 double max = -billion;
9efe76f6 »
2009-05-09 fixing some memory leaks
81
41a7d4a7 »
2009-02-13 grippers partially implemented. they don't lift anything yet
82 for( unsigned int p=0; p<pt_count; p++)
cfa70a3d »
2009-03-20 experimenting with wavefront planner
83 {
84 if( pts[p].y > max ) max = pts[p].y;
85 if( pts[p].y < min ) min = pts[p].y;
86 }
9efe76f6 »
2009-05-09 fixing some memory leaks
87
41a7d4a7 »
2009-02-13 grippers partially implemented. they don't lift anything yet
88 // return the value half way between max and min
89 return( min + (max - min)/2.0 );
90 }
91
92 double Block::CenterX()
93 {
94 double min = billion;
95 double max = -billion;
9efe76f6 »
2009-05-09 fixing some memory leaks
96
41a7d4a7 »
2009-02-13 grippers partially implemented. they don't lift anything yet
97 for( unsigned int p=0; p<pt_count; p++)
cfa70a3d »
2009-03-20 experimenting with wavefront planner
98 {
99 if( pts[p].x > max ) max = pts[p].x;
100 if( pts[p].x < min ) min = pts[p].x;
101 }
9efe76f6 »
2009-05-09 fixing some memory leaks
102
41a7d4a7 »
2009-02-13 grippers partially implemented. they don't lift anything yet
103 // return the value half way between maxx and min
104 return( min + (max - min)/2.0 );
105 }
106
107 void Block::SetCenter( double x, double y )
108 {
109 // move the block by the distance required to bring its center to
110 // the requested position
111 Translate( x-CenterX(), y-CenterY() );
112 }
113
114 void Block::SetCenterY( double y )
115 {
116 // move the block by the distance required to bring its center to
117 // the requested position
118 Translate( 0, y-CenterY() );
119 }
120
121 void Block::SetCenterX( double x )
122 {
123 // move the block by the distance required to bring its center to
124 // the requested position
125 Translate( x-CenterX(), 0 );
126 }
127
128 void Block::SetZ( double min, double max )
129 {
130 local_z.min = min;
131 local_z.max = max;
132
133 // force redraw
134 mod->blockgroup.BuildDisplayList( mod );
135 }
136
137
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
138 stg_color_t Block::GetColor()
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
139 {
89dcdaf1 »
2008-11-15 major changes for 3.1
140 return( inherit_color ? mod->color : color );
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
141 }
142
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
143 GList* Block::AppendTouchingModels( GList* l )
ff0dbdd6 »
2009-02-07 working on charging model and demo
144 {
145 // for every cell we are rendered into
8aab383b »
2009-05-22 moved bit to STL
146 for( unsigned int i=0; i<rendered_cells->size(); i++ )
cfa70a3d »
2009-03-20 experimenting with wavefront planner
147 {
8aab383b »
2009-05-22 moved bit to STL
148 //Cell* c = (Cell*)g_ptr_array_index( rendered_cells, i);
149 Cell* c = (*rendered_cells)[i];
9efe76f6 »
2009-05-09 fixing some memory leaks
150
cfa70a3d »
2009-03-20 experimenting with wavefront planner
151 // for every block rendered into that cell
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
152 for( std::list<Block*>::iterator it = c->blocks.begin();
153 it != c->blocks.end();
9efe76f6 »
2009-05-09 fixing some memory leaks
154 ++it )
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
155 {
156 //Block* testblock = *it;
157 Model* testmod = (*it)->mod;
9efe76f6 »
2009-05-09 fixing some memory leaks
158
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
159 if( !mod->IsRelated( testmod ))
160 if( ! g_list_find( l, testmod ) )
161 l = g_list_append( l, testmod );
162 }
cfa70a3d »
2009-03-20 experimenting with wavefront planner
163 }
9efe76f6 »
2009-05-09 fixing some memory leaks
164
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
165 return l;
ff0dbdd6 »
2009-02-07 working on charging model and demo
166 }
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
167
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
168 Model* Block::TestCollision()
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
169 {
89dcdaf1 »
2008-11-15 major changes for 3.1
170 //printf( "model %s block %p test collision...\n", mod->Token(), this );
171
172 // find the set of cells we would render into given the current global pose
173 GenerateCandidateCells();
9efe76f6 »
2009-05-09 fixing some memory leaks
174
ff0dbdd6 »
2009-02-07 working on charging model and demo
175 if( mod->vis.obstacle_return )
cfa70a3d »
2009-03-20 experimenting with wavefront planner
176 // for every cell we may be rendered into
8aab383b »
2009-05-22 moved bit to STL
177 for( unsigned int i=0; i<candidate_cells->size(); i++ )
cfa70a3d »
2009-03-20 experimenting with wavefront planner
178 {
8aab383b »
2009-05-22 moved bit to STL
179 //Cell* c = (Cell*)g_ptr_array_index(candidate_cells, i);
180 Cell* c = (*candidate_cells)[i];
181
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
182 // for every rendered into that cell
183 for( std::list<Block*>::iterator it = c->blocks.begin();
184 it != c->blocks.end();
9efe76f6 »
2009-05-09 fixing some memory leaks
185 ++it )
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
186 {
187 Model* testmod = (*it)->mod;
9efe76f6 »
2009-05-09 fixing some memory leaks
188
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
189 //printf( " testing block %p of model %s\n", testblock, testmod->Token() );
9efe76f6 »
2009-05-09 fixing some memory leaks
190
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
191 // if the tested model is an obstacle and it's not attached to this model
9efe76f6 »
2009-05-09 fixing some memory leaks
192 if( (testmod != this->mod) &&
193 testmod->vis.obstacle_return &&
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
194 !mod->IsRelated( testmod ))
195 {
196 //puts( "HIT");
197 return testmod; // bail immediately with the bad news
9efe76f6 »
2009-05-09 fixing some memory leaks
198 }
16fedf33 »
2009-04-23 changed from GSList to std::list in raytracing
199 }
cfa70a3d »
2009-03-20 experimenting with wavefront planner
200 }
9efe76f6 »
2009-05-09 fixing some memory leaks
201
89dcdaf1 »
2008-11-15 major changes for 3.1
202 //printf( "model %s block %p collision done. no hits.\n", mod->Token(), this );
203 return NULL; // no hit
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
204 }
205
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
206
c68a660f »
2008-05-23 more vertex arrays
207
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
208
89dcdaf1 »
2008-11-15 major changes for 3.1
209 // used as a callback to gather an array of cells in a polygon
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
210 void AddBlockToCell( Cell* c, Block* block )
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
211 {
89dcdaf1 »
2008-11-15 major changes for 3.1
212 c->AddBlock( block );
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
213 }
214
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
215 void Block::Map()
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
216 {
89dcdaf1 »
2008-11-15 major changes for 3.1
217 // TODO - if called often, we may not need to generate each time
218 GenerateCandidateCells();
219 SwitchToTestedCells();
220 return;
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
221
89dcdaf1 »
2008-11-15 major changes for 3.1
222 mapped = true;
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
223 }
224
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
225 void Block::UnMap()
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
226 {
89dcdaf1 »
2008-11-15 major changes for 3.1
227 RemoveFromCellArray( rendered_cells );
9efe76f6 »
2009-05-09 fixing some memory leaks
228
8aab383b »
2009-05-22 moved bit to STL
229 //g_ptr_array_set_size( rendered_cells, 0 );
230 rendered_cells->clear();
89dcdaf1 »
2008-11-15 major changes for 3.1
231 mapped = false;
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
232 }
233
8aab383b »
2009-05-22 moved bit to STL
234 void Block::RemoveFromCellArray( std::vector<Cell*> * cells )
235 {
236 for( std::vector<Cell*>::iterator it = cells->begin();
237 it != cells->end();
238 ++it )
239 (*it)->RemoveBlock( this);
240 }
241
242 void Block::AddToCellArray( std::vector<Cell*> * cells )
243 {
244 for( std::vector<Cell*>::iterator it = cells->begin();
245 it != cells->end();
246 ++it )
247 (*it)->AddBlock( this);
248 }
249
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
250 void Block::SwitchToTestedCells()
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
251 {
89dcdaf1 »
2008-11-15 major changes for 3.1
252 RemoveFromCellArray( rendered_cells );
253 AddToCellArray( candidate_cells );
9efe76f6 »
2009-05-09 fixing some memory leaks
254
89dcdaf1 »
2008-11-15 major changes for 3.1
255 // switch current and candidate cell pointers
8aab383b »
2009-05-22 moved bit to STL
256 std::vector<Cell*> * tmp = rendered_cells;
89dcdaf1 »
2008-11-15 major changes for 3.1
257 rendered_cells = candidate_cells;
258 candidate_cells = tmp;
259
260 mapped = true;
261 }
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
262
80cdf194 »
2009-04-11 cleaning up code
263 inline stg_point_t Block::BlockPointToModelMeters( const stg_point_t& bpt )
750e0489 »
2009-04-11 fixed raserizer scaling bug
264 {
265 Size bgsize = mod->blockgroup.GetSize();
266 stg_point3_t bgoffset = mod->blockgroup.GetOffset();
9efe76f6 »
2009-05-09 fixing some memory leaks
267
80cdf194 »
2009-04-11 cleaning up code
268 return stg_point_t( (bpt.x - bgoffset.x) * (mod->geom.size.x/bgsize.x),
269 (bpt.y - bgoffset.y) * (mod->geom.size.y/bgsize.y));
750e0489 »
2009-04-11 fixed raserizer scaling bug
270 }
271
80cdf194 »
2009-04-11 cleaning up code
272 stg_point_t* Block::GetPointsInModelCoords()
89dcdaf1 »
2008-11-15 major changes for 3.1
273 {
80cdf194 »
2009-04-11 cleaning up code
274 if( ! mpts )
275 {
276 // no valid cache of model coord points, so generate them
277 mpts = new stg_point_t[pt_count];
9efe76f6 »
2009-05-09 fixing some memory leaks
278
80cdf194 »
2009-04-11 cleaning up code
279 for( unsigned int i=0; i<pt_count; i++ )
280 mpts[i] = BlockPointToModelMeters( pts[i] );
281 }
9efe76f6 »
2009-05-09 fixing some memory leaks
282
80cdf194 »
2009-04-11 cleaning up code
283 return mpts;
284 }
89dcdaf1 »
2008-11-15 major changes for 3.1
285
80cdf194 »
2009-04-11 cleaning up code
286 void Block::InvalidateModelPointCache()
287 {
288 // this doesn't happen often, so this simple strategy isn't too wasteful
289 if( mpts )
9efe76f6 »
2009-05-09 fixing some memory leaks
290 {
80cdf194 »
2009-04-11 cleaning up code
291 delete[] mpts;
292 mpts = NULL;
293 }
294 }
eaba4cb0 »
2008-11-19 geometry fixes & graphics tweaks
295
8aab383b »
2009-05-22 moved bit to STL
296 // callback used below
297 static void AppendCellToVector( Cell* c, std::vector<Cell*> * a )
298 {
299 a->push_back( c );
300 }
301
80cdf194 »
2009-04-11 cleaning up code
302 void Block::GenerateCandidateCells()
303 {
304 stg_point_t* mpts = GetPointsInModelCoords();
9efe76f6 »
2009-05-09 fixing some memory leaks
305
80cdf194 »
2009-04-11 cleaning up code
306 // convert the mpts in model coords into global coords
307 stg_point_t* gpts = new stg_point_t[pt_count];
308 for( unsigned int i=0; i<pt_count; i++ )
309 gpts[i] = mod->LocalToGlobal( mpts[i] );
03e148ec »
2008-12-05 code tidying - eliminated all -Wall warnings
310
8aab383b »
2009-05-22 moved bit to STL
311 //g_ptr_array_set_size( candidate_cells, 0 );
312 candidate_cells->clear();
03e148ec »
2008-12-05 code tidying - eliminated all -Wall warnings
313
80cdf194 »
2009-04-11 cleaning up code
314 mod->world->
315 ForEachCellInPolygon( gpts, pt_count,
8aab383b »
2009-05-22 moved bit to STL
316 (stg_cell_callback_t)AppendCellToVector,
80cdf194 »
2009-04-11 cleaning up code
317 candidate_cells );
318 delete[] gpts;
89dcdaf1 »
2008-11-15 major changes for 3.1
319
80cdf194 »
2009-04-11 cleaning up code
320 // set global Z
321 Pose gpose = mod->GetGlobalPose();
322 gpose.z += mod->geom.pose.z;
323 double scalez = mod->geom.size.z / mod->blockgroup.GetSize().z;
324 stg_meters_t z = gpose.z - mod->blockgroup.GetOffset().z;
9efe76f6 »
2009-05-09 fixing some memory leaks
325
89dcdaf1 »
2008-11-15 major changes for 3.1
326 // store the block's absolute z bounds at this rendering
80cdf194 »
2009-04-11 cleaning up code
327 global_z.min = (scalez * local_z.min) + z;
9efe76f6 »
2009-05-09 fixing some memory leaks
328 global_z.max = (scalez * local_z.max) + z;
329
89dcdaf1 »
2008-11-15 major changes for 3.1
330 mapped = true;
331 }
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
332
750e0489 »
2009-04-11 fixed raserizer scaling bug
333 void swap( int& a, int& b )
e96a997c »
2009-04-04 added model rasterization
334 {
750e0489 »
2009-04-11 fixed raserizer scaling bug
335 int tmp = a;
336 a = b;
337 b = tmp;
e96a997c »
2009-04-04 added model rasterization
338 }
339
9efe76f6 »
2009-05-09 fixing some memory leaks
340 void Block::Rasterize( uint8_t* data,
341 unsigned int width,
342 unsigned int height,
750e0489 »
2009-04-11 fixed raserizer scaling bug
343 stg_meters_t cellwidth,
344 stg_meters_t cellheight )
345 {
346 //printf( "rasterize block %p : w: %u h: %u scale %.2f %.2f offset %.2f %.2f\n",
347 // this, width, height, scalex, scaley, offsetx, offsety );
14345cb8 »
2009-04-07 removed a malloc
348
750e0489 »
2009-04-11 fixed raserizer scaling bug
349 for( unsigned int i=0; i<pt_count; i++ )
350 {
351 // convert points from local to model coords
352 stg_point_t mpt1 = BlockPointToModelMeters( pts[i] );
353 stg_point_t mpt2 = BlockPointToModelMeters( pts[(i+1)%pt_count] );
9efe76f6 »
2009-05-09 fixing some memory leaks
354
750e0489 »
2009-04-11 fixed raserizer scaling bug
355 // record for debug visualization
356 mod->rastervis.AddPoint( mpt1.x, mpt1.y );
9efe76f6 »
2009-05-09 fixing some memory leaks
357
750e0489 »
2009-04-11 fixed raserizer scaling bug
358 // shift to the bottom left of the model
359 mpt1.x += mod->geom.size.x/2.0;
360 mpt1.y += mod->geom.size.y/2.0;
361 mpt2.x += mod->geom.size.x/2.0;
362 mpt2.y += mod->geom.size.y/2.0;
9efe76f6 »
2009-05-09 fixing some memory leaks
363
750e0489 »
2009-04-11 fixed raserizer scaling bug
364 // convert from meters to cells
83e6bb14 »
2009-04-11 spring cleaning
365 stg_point_int_t a( floor( mpt1.x / cellwidth ),
366 floor( mpt1.y / cellheight ));
367 stg_point_int_t b( floor( mpt2.x / cellwidth ),
368 floor( mpt2.y / cellheight ) );
9efe76f6 »
2009-05-09 fixing some memory leaks
369
83e6bb14 »
2009-04-11 spring cleaning
370 bool steep = abs( b.y-a.y ) > abs( b.x-a.x );
59d66b44 »
2009-04-07 debugging rasterization
371 if( steep )
372 {
83e6bb14 »
2009-04-11 spring cleaning
373 swap( a.x, a.y );
374 swap( b.x, b.y );
59d66b44 »
2009-04-07 debugging rasterization
375 }
9efe76f6 »
2009-05-09 fixing some memory leaks
376
83e6bb14 »
2009-04-11 spring cleaning
377 if( a.x > b.x )
e96a997c »
2009-04-04 added model rasterization
378 {
83e6bb14 »
2009-04-11 spring cleaning
379 swap( a.x, b.x );
380 swap( a.y, b.y );
e96a997c »
2009-04-04 added model rasterization
381 }
9efe76f6 »
2009-05-09 fixing some memory leaks
382
83e6bb14 »
2009-04-11 spring cleaning
383 double dydx = (double) (b.y - a.y) / (double) (b.x - a.x);
384 double y = a.y;
9efe76f6 »
2009-05-09 fixing some memory leaks
385 for(int x=a.x; x<=b.x; x++)
e96a997c »
2009-04-04 added model rasterization
386 {
750e0489 »
2009-04-11 fixed raserizer scaling bug
387 if( steep )
388 {
389 if( ! (floor(y) >= 0) ) continue;
390 if( ! (floor(y) < (int)width) ) continue;
391 if( ! (x >= 0) ) continue;
392 if( ! (x < (int)height) ) continue;
393 }
394 else
395 {
396 if( ! (x >= 0) ) continue;
397 if( ! (x < (int)width) ) continue;
398 if( ! (floor(y) >= 0) ) continue;
399 if( ! (floor(y) < (int)height) ) continue;
400 }
9efe76f6 »
2009-05-09 fixing some memory leaks
401
e96a997c »
2009-04-04 added model rasterization
402 if( steep )
9efe76f6 »
2009-05-09 fixing some memory leaks
403 data[ (int)floor(y) + (x * width)] = 1;
e96a997c »
2009-04-04 added model rasterization
404 else
59d66b44 »
2009-04-07 debugging rasterization
405 data[ x + ((int)floor(y) * width)] = 1;
406 y += dydx;
e96a997c »
2009-04-04 added model rasterization
407 }
408 }
409 }
410
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
411 void Block::DrawTop()
89dcdaf1 »
2008-11-15 major changes for 3.1
412 {
413 // draw the top of the block - a polygon at the highest vertical
414 // extent
415 glBegin( GL_POLYGON);
03e148ec »
2008-12-05 code tidying - eliminated all -Wall warnings
416 for( unsigned int i=0; i<pt_count; i++ )
cfa70a3d »
2009-03-20 experimenting with wavefront planner
417 glVertex3f( pts[i].x, pts[i].y, local_z.max );
89dcdaf1 »
2008-11-15 major changes for 3.1
418 glEnd();
9efe76f6 »
2009-05-09 fixing some memory leaks
419 }
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
420
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
421 void Block::DrawSides()
89dcdaf1 »
2008-11-15 major changes for 3.1
422 {
9efe76f6 »
2009-05-09 fixing some memory leaks
423 // construct a strip that wraps around the polygon
89dcdaf1 »
2008-11-15 major changes for 3.1
424 glBegin(GL_QUAD_STRIP);
425 for( unsigned int p=0; p<pt_count; p++)
cfa70a3d »
2009-03-20 experimenting with wavefront planner
426 {
427 glVertex3f( pts[p].x, pts[p].y, local_z.max );
428 glVertex3f( pts[p].x, pts[p].y, local_z.min );
429 }
89dcdaf1 »
2008-11-15 major changes for 3.1
430 // close the strip
431 glVertex3f( pts[0].x, pts[0].y, local_z.max );
432 glVertex3f( pts[0].x, pts[0].y, local_z.min );
433 glEnd();
434 }
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
435
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
436 void Block::DrawFootPrint()
89dcdaf1 »
2008-11-15 major changes for 3.1
437 {
438 glBegin(GL_POLYGON);
439 for( unsigned int p=0; p<pt_count; p++ )
cfa70a3d »
2009-03-20 experimenting with wavefront planner
440 glVertex2f( pts[p].x, pts[p].y );
89dcdaf1 »
2008-11-15 major changes for 3.1
441 glEnd();
442 }
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
443
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
444 void Block::Draw( Model* mod )
89dcdaf1 »
2008-11-15 major changes for 3.1
445 {
9efe76f6 »
2009-05-09 fixing some memory leaks
446 // draw filled color polygons
447 stg_color_t col = inherit_color ? mod->color : color;
448
ffcdb6b5 »
2009-04-09 fixed threadpool bug
449 mod->PushColor( col );
450 glEnable(GL_POLYGON_OFFSET_FILL);
451 glPolygonOffset(1.0, 1.0);
452 DrawSides();
453 DrawTop();
454 glDisable(GL_POLYGON_OFFSET_FILL);
9efe76f6 »
2009-05-09 fixing some memory leaks
455
89dcdaf1 »
2008-11-15 major changes for 3.1
456 // // draw the block outline in a darker version of the same color
457 double r,g,b,a;
458 stg_color_unpack( col, &r, &g, &b, &a );
459 mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
9efe76f6 »
2009-05-09 fixing some memory leaks
460
89dcdaf1 »
2008-11-15 major changes for 3.1
461 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
462 glDepthMask(GL_FALSE);
463 DrawTop();
464 DrawSides();
465 glDepthMask(GL_TRUE);
466 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
9efe76f6 »
2009-05-09 fixing some memory leaks
467
89dcdaf1 »
2008-11-15 major changes for 3.1
468 mod->PopColor();
469 mod->PopColor();
470 }
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
471
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
472 void Block::DrawSolid()
89dcdaf1 »
2008-11-15 major changes for 3.1
473 {
474 DrawSides();
475 DrawTop();
476 }
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
477
478
89dcdaf1 »
2008-11-15 major changes for 3.1
479 //#define DEBUG 1
22a1279c »
2008-06-10 fixed indentation issues (converted to tabs)
480
481
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
482 void Block::Load( Worldfile* wf, int entity )
89dcdaf1 »
2008-11-15 major changes for 3.1
483 {
3680786b »
2009-01-05 API changes! removed the Stg prefix from all class names, and renamed…
484 //printf( "Block::Load entity %d\n", entity );
9efe76f6 »
2009-05-09 fixing some memory leaks
485
89dcdaf1 »
2008-11-15 major changes for 3.1
486 if( pts )
83e6bb14 »
2009-04-11 spring cleaning
487 delete[] pts;
9efe76f6 »
2009-05-09 fixing some memory leaks
488
89dcdaf1 »
2008-11-15 major changes for 3.1
489 pt_count = wf->ReadInt( entity, "points", 0);
83e6bb14 »
2009-04-11 spring cleaning
490 pts = new stg_point_t[ pt_count ];
9efe76f6 »
2009-05-09 fixing some memory leaks
491
89dcdaf1 »
2008-11-15 major changes for 3.1
492 //printf( "reading %d points\n",
493 // pt_count );
9efe76f6 »
2009-05-09 fixing some memory leaks
494
495 char key[128];
03e148ec »
2008-12-05 code tidying - eliminated all -Wall warnings
496 for( unsigned int p=0; p<pt_count; p++ ) {
cfa70a3d »
2009-03-20 experimenting with wavefront planner
497 snprintf(key, sizeof(key), "point[%d]", p );
9efe76f6 »
2009-05-09 fixing some memory leaks
498
cfa70a3d »
2009-03-20 experimenting with wavefront planner
499 pts[p].x = wf->ReadTupleLength(entity, key, 0, 0);
500 pts[p].y = wf->ReadTupleLength(entity, key, 1, 0);
89dcdaf1 »
2008-11-15 major changes for 3.1
501 }
9efe76f6 »
2009-05-09 fixing some memory leaks
502
89dcdaf1 »
2008-11-15 major changes for 3.1
503 local_z.min = wf->ReadTupleLength( entity, "z", 0, 0.0 );
504 local_z.max = wf->ReadTupleLength( entity, "z", 1, 1.0 );
9efe76f6 »
2009-05-09 fixing some memory leaks
505
89dcdaf1 »
2008-11-15 major changes for 3.1
506 const char* colorstr = wf->ReadString( entity, "color", NULL );
507 if( colorstr )
cfa70a3d »
2009-03-20 experimenting with wavefront planner
508 {
509 color = stg_lookup_color( colorstr );
510 inherit_color = false;
511 }
d60514d7 »
2008-12-02 geometry & graphics fixes. added normalization of blocks to fit insid…
512 else
cfa70a3d »
2009-03-20 experimenting with wavefront planner
513 inherit_color = true;
36bfbdb6 »
2008-01-15 first commit since shifting the Stage-3.0 development branch (opengl)…
514 }
515
9efe76f6 »
2009-05-09 fixing some memory leaks
516
517
Something went wrong with that request. Please try again.