~ubuntu-branches/ubuntu/trusty/3depict/trusty-proposed

« back to all changes in this revision

Viewing changes to src/scene.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru, D Haley, Sylvestre Ledru
  • Date: 2011-08-15 23:35:55 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110815233555-5c0j9oklfkrc733q
Tags: 0.0.7-1
[ D Haley ]
* Update to new upstream version 
* Include manual in tarball
* Include upstream patches for correcting density profile computation
  and refresh branch computation

[ Sylvestre Ledru ]
* Switch to dpkg-source 3.0 (quilt) format

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
                camToUse=cameras[activeCam];
133
133
        }
134
134
        //Inform text about current camera, so it can billboard if needed
135
 
        DrawGLText::setCurCamera(camToUse);
136
 
        DrawField3D::setCurCamera(camToUse);
137
 
        
 
135
        DrawableObj::setCurCamera(camToUse);
138
136
        Effect::setCurCam(camToUse);
139
137
 
140
138
 
182
180
                        if(useLighting)
183
181
                                glDisable(GL_LIGHTING);
184
182
                }
185
 
                //Draw the referenced objects
186
 
                for(unsigned int ui=0; ui<refObjects.size(); ui++)
187
 
                {
188
 
                        //overlays need to be drawn later
189
 
                        if(refObjects[ui]->isOverlay())
190
 
                                continue;
191
 
 
192
 
                        if(useLighting)
193
 
                        {
194
 
                                if(!refObjects[ui]->wantsLight && lightsOn)
195
 
                                {
196
 
                                        lightsOn=false;
197
 
                                        glDisable(GL_LIGHTING);
198
 
                                }
199
 
                                else if (refObjects[ui]->wantsLight && !lightsOn)
200
 
                                {
201
 
                                        glEnable(GL_LIGHTING);
202
 
                                        lightsOn=true;
203
 
                                }
204
 
                        }
205
 
 
206
 
                        refObjects[ui]->draw(); 
207
 
                }
208
 
 
209
 
                //Set up the objects
210
 
                for(unsigned int ui=0; ui<objects.size(); ui++)
211
 
                {
212
 
                        //overlays need to be drawn later
213
 
                        if(objects[ui]->isOverlay())
214
 
                                continue;
215
 
                        if(useLighting)
216
 
                        {       
217
 
                                if(!objects[ui]->wantsLight && lightsOn )
218
 
                                {
219
 
                                        //Object prefers doing its thing in the dark
220
 
                                        glDisable(GL_LIGHTING);
221
 
                                        lightsOn=false;
222
 
                                }
223
 
                                else if (objects[ui]->wantsLight && !lightsOn)
224
 
                                {
225
 
                                        glEnable(GL_LIGHTING);
226
 
                                        lightsOn=true;
227
 
                                }
228
 
                        }
229
 
 
230
 
                        //If we are in selection mode, draw the bounding box
231
 
                        //if the object is selected.
232
 
                        if(ui == lastSelected && selectionMode)
233
 
                        {
234
 
                                //May be required for selection box drawing
235
 
                                BoundCube bObject;
236
 
                                DrawRectPrism p;
237
 
                                //Get the bounding box for the object & draw it
238
 
                                objects[ui]->getBoundingBox(bObject);
239
 
                                p.setAxisAligned(bObject);
240
 
                                p.setColour(0,0.2,1,0.5); //blue-greenish
241
 
                                if(lightsOn)
242
 
                                        glDisable(GL_LIGHTING);
243
 
                                p.draw();
244
 
                                if(lightsOn)
245
 
                                        glEnable(GL_LIGHTING);
246
 
 
247
 
                        }
248
 
 
249
 
                        objects[ui]->draw();
250
 
                }
251
 
                
252
 
 
 
183
                
 
184
        
 
185
                //First sub-pass with opaque objects
 
186
                //-----------   
 
187
                //Draw the referenced objects
 
188
                drawObjectVector(refObjects,lightsOn,true);
 
189
                //Draw normal objects
 
190
                drawObjectVector(objects,lightsOn,true);
 
191
                //-----------   
 
192
                
 
193
                //Second pass with transparent objects
 
194
                //-----------   
 
195
                //Draw the referenced objects
 
196
                drawObjectVector(refObjects,lightsOn,false);
 
197
                //Draw normal objects
 
198
                drawObjectVector(objects,lightsOn,false);
 
199
                //-----------   
 
200
                
 
201
                
253
202
                glFlush();
254
203
                passNumber++;
255
204
        }
265
214
                        ui--;
266
215
                        effects[ui]->disable();
267
216
                }
268
 
                //glPopMatrix();
269
217
        }
270
218
 
271
219
 
278
226
 
279
227
}
280
228
 
 
229
void Scene::drawObjectVector(const vector<const DrawableObj*> &drawObjs, bool &lightsOn, bool drawOpaques) const
 
230
{
 
231
        for(unsigned int ui=0; ui<drawObjs.size(); ui++)
 
232
        {
 
233
                //FIXME: Use logical operator to simplify this.
 
234
                // its late, and i'm tired and can't think. Its very easy
 
235
                // when you can think. 
 
236
                if(drawOpaques)
 
237
                {
 
238
                        //Don't draw opaque drawObjs in this pass
 
239
                         if(drawObjs[ui]->needsDepthSorting())
 
240
                                continue;
 
241
                }
 
242
                else
 
243
                {
 
244
                        //Do draw opaque drawObjs in this pass
 
245
                         if(!drawObjs[ui]->needsDepthSorting())
 
246
                                continue;
 
247
                }
 
248
        
 
249
                //overlays need to be drawn later
 
250
                if(drawObjs[ui]->isOverlay())
 
251
                        continue;
 
252
                if(useLighting)
 
253
                {       
 
254
                        if(!drawObjs[ui]->wantsLight && lightsOn )
 
255
                        {
 
256
                                //Object prefers doing its thing in the dark
 
257
                                glDisable(GL_LIGHTING);
 
258
                                lightsOn=false;
 
259
                        }
 
260
                        else if (drawObjs[ui]->wantsLight && !lightsOn)
 
261
                        {
 
262
                                glEnable(GL_LIGHTING);
 
263
                                lightsOn=true;
 
264
                        }
 
265
                }
 
266
                
 
267
                //If we are in selection mode, draw the bounding box
 
268
                //if the object is selected.
 
269
                if(ui == lastSelected && selectionMode)
 
270
                {
 
271
                        //May be required for selection box drawing
 
272
                        BoundCube bObject;
 
273
                        DrawRectPrism p;
 
274
                        //Get the bounding box for the object & draw it
 
275
                        drawObjs[ui]->getBoundingBox(bObject);
 
276
                        p.setAxisAligned(bObject);
 
277
                        p.setColour(0,0.2,1,0.5); //blue-greenish
 
278
                        if(lightsOn)
 
279
                                glDisable(GL_LIGHTING);
 
280
                        p.draw();
 
281
                        if(lightsOn)
 
282
                                glEnable(GL_LIGHTING);
 
283
 
 
284
                }
 
285
                
 
286
                drawObjs[ui]->draw();
 
287
        }
 
288
}
 
289
 
281
290
void Scene::drawOverlays() const
282
291
{
283
292
 
306
315
 
307
316
        glDisable(GL_DEPTH_TEST);
308
317
 
 
318
 
309
319
        for(unsigned int ui=0;ui<refObjects.size();ui++)
310
320
        {
311
321
                if(refObjects[ui]->isOverlay())
472
482
        glEnable(GL_DEPTH_TEST);
473
483
}
474
484
 
 
485
 
475
486
void Scene::commitTempCam()
476
487
{
477
488
        ASSERT(tempCam);
502
513
        BoundCube bc;
503
514
        obj->getBoundingBox(bc);
504
515
 
505
 
        if(bc.isValid());
 
516
        if(bc.isValid())
506
517
                boundCube.expand(bc);
507
518
}
508
519
 
509
 
void Scene::addLight(Light const *light)
510
 
{
511
 
        lights.push_back(light);
512
 
}
513
 
 
514
520
void Scene::addRefDrawable(const DrawableObj *obj)
515
521
{
516
522
        refObjects.push_back(obj);
528
534
 
529
535
        clearObjs();
530
536
        clearRefObjs();
531
 
        clearLights();
532
537
        clearBindings();        
533
538
        clearCams();
534
539
}
547
552
        selectionDevices.clear();
548
553
}
549
554
 
550
 
void Scene::clearLights()
551
 
{
552
 
        for(unsigned int ui=0; ui<lights.size(); ui++)
553
 
                delete lights[ui];
554
 
        lights.clear();
555
 
}
556
555
 
557
556
void Scene::clearCams()
558
557
{