GroupObject.cpp

00001 #include "GroupObject.h"
00002 
00003 
00004 GroupObject::GroupObject () : GraphicalObject (NULL)
00005 {
00006         // nothing to do
00007 }
00008 
00009 GroupObject::~GroupObject ()
00010 {
00011         // nothing to do
00012 }
00013 
00014 void GroupObject::Draw (int time, Camera * camera, Camera * monitor, bool show_bounding_volume, int culling_mode, bool level_of_detail)
00015 {
00016         Position pos;
00017         ChildListElem * current_child;
00018         int     culling_result;
00019         bool rotation;
00020 
00021         // return if position is not defined for the current time
00022         if (!(position->IsDefined (time))) return;
00023 
00024         // retrieve actual position
00025         pos = position->GetPosition (time);
00026 
00027         // check if there is rotation
00028         rotation = position->HasStaticRotation ();
00029 
00030         // change modelview matrix
00031         ApplyTransformation (pos, rotation);
00032 
00033         // cull the actual object
00034         culling_result = CullObject (camera, monitor, culling_mode, show_bounding_volume);
00035 
00036         // if the object does not lie completely outside, ...
00037         if (culling_result != C_OUTSIDE)
00038         {
00039                 // ... , draw all children
00040                 current_child = first_child;
00041                 while (current_child != NULL)
00042                 {
00043                         // suppress further culling if the object lies completely inside the viewing frustum
00044                         if (culling_result == C_PARTIAL)
00045                         {current_child->object->Draw (time, camera, monitor, show_bounding_volume, culling_mode, level_of_detail);}
00046                         else
00047                         {current_child->object->Draw (time, camera, monitor, show_bounding_volume, C_NONE, level_of_detail);}
00048 
00049                         current_child = current_child->next;
00050                 }
00051         }
00052 
00053         // finally, undo the change to the modelview matrix
00054         UndoTransformation (pos, rotation);
00055 }
00056 
00057 void GroupObject::AddChild (GraphicalObject * child)
00058 {
00059         ChildListElem * current_child;
00060 
00061         if (first_child == NULL)
00062         {
00063                 first_child = new ChildListElem;
00064                 first_child->object = child;
00065                 first_child->next = NULL;
00066         }
00067         else
00068         {
00069                 current_child = first_child;
00070                 while (current_child->next != NULL) current_child = current_child->next;
00071                 
00072                 current_child->next = new ChildListElem;
00073                 current_child->next->next = NULL;
00074                 current_child->next->object = child;
00075         }
00076 
00077         UpdateBoundingRadius (false);
00078         UpdateBoundingBox (false);
00079 }
00080 
00081 void GroupObject::ComputeBoundingRadius ()
00082 {
00083         bounding_radius = 0.0;
00084 }
00085 
00086 void GroupObject::ComputeBoundingBox ()
00087 {
00088         bounding_box.xmax = 0.0f;
00089         bounding_box.xmin = 0.0f;
00090         bounding_box.ymax = 0.0f;
00091         bounding_box.ymin = 0.0f;
00092         bounding_box.zmax = 0.0f;
00093         bounding_box.zmin = 0.0f;
00094 }
00095 
00096 void GroupObject::PrintToConsole ()
00097 {
00098         Position pos = position->GetPosition (0);
00099         ChildListElem * current_object;
00100 
00101         printf ("GroupObject: {%g, %g, %g, %g, %g, %g}\n", pos.x, pos.y, pos.z, pos.roll, pos.pitch, pos.yaw);
00102         
00103         if (first_child != NULL)
00104         {
00105                 printf ("Printing Children: ----------------------------------\n");
00106                 current_object = first_child;
00107                 while (current_object != NULL)
00108                 {
00109                         current_object->object->PrintToConsole ();
00110                         current_object = current_object->next;
00111                 }
00112                 printf("End Printing Children: -------------------------------\n");
00113         }
00114         else
00115         {printf ("No Children detected\n");}
00116 }

Generated on Sun Jul 2 13:20:39 2006 for Demo by  doxygen 1.4.6-NO