23 list<VART::SceneNode*>::const_iterator objItr;
24 list<const VART::Light*>::const_iterator lightItr;
27 for (objItr = objects.begin(); objItr != objects.end(); ++objItr)
29 (*objItr)->AutoDeleteChildren();
30 if ((*objItr)->autoDelete)
34 for (lightItr = lights.begin(); lightItr != lights.end(); ++lightItr)
36 if ((*lightItr)->autoDelete)
54 lights.push_back(newLight);
60 lights.push_back(lightPtr);
64 cameras.push_back( newCamera );
65 if (currentCamera == cameras.end())
66 currentCamera = cameras.begin();
70 objects.push_back( newObjectPtr );
75 list<SceneNode*>::iterator iter = objects.begin();
76 bool unfinished =
true;
80 if (*iter == sceneNodePtr)
88 unfinished = (iter != objects.end());
94 list<const VART::Light*>::const_iterator iter;
95 for (iter = lights.begin(); iter != lights.end(); ++iter) {
96 if( (*iter)->GetDescription() == lightName ) {
104 list<VART::Camera*>::const_iterator iter;
105 for (iter = cameras.begin(); iter != cameras.end(); ++iter) {
106 if( (*iter)->GetDescription() == cameraName ) {
114 list<Camera*>::const_iterator iter;
115 for (iter = cameras.begin(); iter != cameras.end(); ++iter) {
116 if( (*iter)->GetDescription() == cameraName ) {
117 currentCamera = iter;
123 list<VART::SceneNode*>::const_iterator iter;
125 assert(!objects.empty());
126 for (iter = objects.begin(); iter != objects.end(); ++iter) {
128 if( (*iter)->GetDescription() == objectName ) {
141 list<VART::SceneNode*>::const_iterator iter = objects.begin();
142 while ((iter != objects.end()) && (finder.NotFinished()))
144 (*iter)->LocateDepthFirst(&finder);
148 return const_cast<GraphicObj*
>(finder.GetResult());
153 list<VART::SceneNode*>::const_iterator iter;
154 for (iter = objects.begin(); iter != objects.end(); ++iter) {
155 if( (*iter)->GetDescription() == objectName )
183 assert(*currentCamera);
184 (*currentCamera)->DrawOGL();
192 list<VART::SceneNode*>::const_iterator iter;
193 for (iter = objects.begin(); iter != objects.end(); ++iter)
198 bBox.DrawInstanceOGL();
208 unsigned int lightID = 0;
209 list<const VART::Light*>::const_iterator iter;
210 for (iter = lights.begin(); iter != lights.end(); ++iter)
212 (*iter)->DrawOGL(lightID);
222 if (currentCamera == cameras.end())
225 return *currentCamera;
229 assert(!cameras.empty());
231 if (currentCamera == cameras.end())
232 currentCamera = cameras.begin();
233 return *currentCamera;
237 assert(!cameras.empty());
239 if (currentCamera == cameras.end())
241 return *currentCamera;
245 list<VART::Camera*>::iterator iter;
246 for (iter = cameras.begin(); iter != cameras.end(); ++iter) {
247 if( (*iter)->GetDescription() == cameraDescription ) {
248 (*iter)->SetAspectRatio(newAspectRatio);
255 list<VART::Camera*>::const_iterator iter;
256 for (iter = cameras.begin(); iter != cameras.end(); ++iter) {
257 (*iter)->SetAspectRatio(newAspectRatio);
262 list<VART::Camera*>::const_iterator iter = cameras.begin();
263 for (; iter != cameras.end(); ++iter) {
264 (*iter)->ScaleVisibleVolume(horScale, verScale);
270 bool initBBox =
false;
271 list<VART::SceneNode*>::const_iterator iter;
275 for (iter = objects.begin(); iter != objects.end(); ++iter) {
293 bBox.CopyGeometryFrom(box);
301 bBox.ProcessCenter();
329 double maxX,
double maxY,
double maxZ) {
330 bBox.SetBoundingBox(minX,minY,minZ,maxX,maxY,maxZ);
331 bBox.ProcessCenter();
336 assert(*currentCamera);
337 ComputeBoundingBox();
339 cout << bBox << endl;
340 (*currentCamera)->SetTarget(bBoxCenter);
342 double greaterEdgeBox = bBox.GetGreaterEdge();
343 (*currentCamera)->SetLocation(bBoxCenter+
VART::Point4D(0,greaterEdgeBox*1.2,greaterEdgeBox*1.2,0));
345 (*currentCamera)->SetFarPlaneDistance(greaterEdgeBox*2.4);
348 double edgeY = bBox.GetGreaterY();
350 (*currentCamera)->SetLocation(bBoxCenter+
VART::Point4D(0,edgeY,0,0));
352 (*currentCamera)->SetVisibleVolumeHeight( bBox.GetGreaterX()-bBox.GetSmallerX() );
360 cerr <<
"\aWarning: Scene::GetAllSceneJoints is deprecated. See documentation\n";
361 list<VART::SceneNode*> nodeList;
362 list<VART::SceneNode*>::const_iterator iter;
364 for (iter = objects.begin(); iter != objects.end(); ++iter)
372 cerr <<
"\aWarning: Scene::GetAllSceneTypeObject is deprecated. See documentation\n";
373 list<VART::SceneNode*> nodeList;
374 list<VART::SceneNode*>::const_iterator iter;
376 for (iter = objects.begin(); iter != objects.end(); ++iter)
377 (*iter)->GetNodeTypeList( type, nodeList);
385 const static int SELECTION_BUFFER_SIZE = 512;
387 resultListPtr->clear();
390 glGetIntegerv(GL_VIEWPORT, viewport);
392 GLuint selectBuf[SELECTION_BUFFER_SIZE];
393 glSelectBuffer(SELECTION_BUFFER_SIZE, selectBuf);
395 glRenderMode(GL_SELECT);
402 glMatrixMode(GL_PROJECTION);
404 gluPickMatrix(static_cast<GLdouble>(x),
405 viewport[3]-static_cast<GLdouble>(y),
407 (*currentCamera)->SetMatrices();
410 list<VART::SceneNode*>::const_iterator iter = objects.begin();
411 for (; iter != objects.end(); ++iter)
412 (*iter)->DrawForPicking();
422 GLint hits = glRenderMode(GL_RENDER);
423 GLuint* selectBufPtr = selectBuf;
425 unsigned int numNames;
426 unsigned int nameIndex;
429 numNames = selectBufPtr[0];
433 GLuint pickName = selectBufPtr[nameIndex];
435 pickPtr = GetObject(pickName);
439 resultListPtr->push_back(pickPtr);
446 selectBufPtr += nameIndex;
450 cerr <<
"Error: Scene::Pick is not implemented for your render engine!" << endl;
456 list<VART::SceneNode*>::const_iterator iter;
458 os <<
"<?xml version=\"1.0\"?>\n"
459 <<
"<!DOCTYPE scene SYSTEM \"vartScene.dtd\">\n"
460 <<
"<scene description=\"" << description <<
"\">\n";
461 for (iter = objects.begin(); iter != objects.end(); ++iter)
464 (*iter)->XmlPrintOn(os, 4);
SceneNode * GetObject(const std::string &objectName) const
Searches an object by its description.
SceneNode * GetObjectRec(const std::string &objectName) const
Recursively searches an object by its description.
Base class for objects that compose a scene graph.
std::list< SceneNode * > GetObjects()
Points and vectors using homogeneous coordinates.
Camera * GetCurrentCamera() const
Returns the current camera in the scene or NULL if no camera exists.
Header file for V-ART class "GraphicObj".
std::list< SceneNode * > GetAllSceneJoints()
Get all scenenodes of type 'joint' in the scene.
static const Point4D & Y()
The Y vector (0,1,0,0).
bool DrawLightsOGL() const
Set lights using OpenGL commands.
void SetAllCamerasAspectRatio(float newAspectRatio)
Set the aspect ratio of all cameras.
void ComputeRecursiveBoundingBox()
Computes the recursive bounding box.
const Camera * GetCamera(const std::string &cameraName)
Finds an camera by its description.
Header file for V-ART class "Scene".
RGBA color representation.
Axis aligned bounding box.
std::list< SceneNode * > GetAllSceneTypeObject(SceneNode::TypeID type)
Get all scenenodes of type 'type' in the scene.
const Camera * UsePreviousCamera()
const Color & GetBackgroundColor()
Returns the background color.
void SetColor(const Color &value)
Sets the bounding box color.
void AddCamera(Camera *newCamera)
Add a camera to the list of cameras.
void ChangeAllCamerasViewVolume(float horScale, float verScale)
Changes the view volume of all cameras.
virtual ~Scene()
Destructor.
void SetBoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
Sets the bounding box.
const Camera * UseNextCamera()
void AddLight(Light *newLight)
Adds a light to the list of lights.
const Light * GetLight(const std::string &lightName)
Finds a light by its name.
bool DrawOGL() const
Positions a camera using OpenGL commands.
std::list< Camera * > GetCameras()
Returns a list of cameras.
An scene node that is associated with a shape.
bool ComputeBoundingBox()
Computes the axis aligned bounding box of all objects.
static const Point4D & X()
The X vector (1,0,0,0).
Header file for V-ART class "PickNameLocator".
void AddObject(SceneNode *newObjectPtr)
Add a object to the scene.
void XmlPrintOn(std::ostream &os) const
Outputs XML representation of the scene.
void Pick(int x, int y, std::list< GraphicObj * > *resultListPtr)
Picks objects from viewport coordinates.
SceneNode * FindChildByName(const std::string &name) const
Recusively searches its children for a given name.
virtual bool DrawOGL(Camera *cameraPtr=NULL) const
Sets projection and draws graphics objects using OpenGL commands.
void MakeCameraViewAll()
Fits the whole scene to drawing region.
void SetCamerasAspectRatio(const std::string &cameraDescription, float newAspectRatio)
Set the aspect ratio of camera by its description.
void SetCamera(const std::string &cameraName)
Sets the current camera by its description.
void SetBackgroundColor(Color color)
Sets the background color.
static const Color & WHITE()
White opaque color.
const BoundingBox & GetRecursiveBoundingBox() const
Returns the recursive bounding box.
std::list< const Light * > GetLights()
void Unreference(const SceneNode *sceneNodePtr)
Removes an object from scene graph.
Represents a light source.