00001 /********************************************************************* 00002 * lescegra * 00003 * * 00004 * http://geeky.kicks-ass.org/projects/lescegra.html * 00005 * * 00006 * Copyright 2003 by Enno Cramer <uebergeek@web.de> * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Library General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Library General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Library General Public * 00019 * License along with this library; if not, write to the Free * 00020 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00021 *********************************************************************/ 00022 00023 #ifndef LSG_NODE_H 00024 #define LSG_NODE_H 1 00025 00026 /** 00027 * \file node.h 00028 * \brief Scene graph hierarchy base class 00029 */ 00030 00031 #include <lescegra/util/object.h> 00032 00033 #include <lescegra/util/vertex.h> 00034 #include <lescegra/util/frustum.h> 00035 #include <lescegra/util/bbox.h> 00036 00037 typedef struct LsgNode LsgNode; 00038 00039 /** 00040 * \brief Scene graph hierarchy base class 00041 * 00042 * Abstract base class for the scene graph class hierarchy. 00043 */ 00044 struct LsgNode { 00045 LsgObject super; 00046 LsgBBox* bbox; 00047 /** 00048 * Flag to indicate a changed boundig box. Parents should check this flag 00049 * after calling update and update their own bounding boxes if necessary. 00050 */ 00051 int dirty; 00052 /** 00053 * Mark this node as having any changes processed. Call after running 00054 * update to ensure later calls to update don't have process to reevaluate 00055 * unchanged nodes. 00056 * @param self The instance variable 00057 */ 00058 void (*clean)(LsgNode* self); 00059 /** 00060 * Update this node to accommodate to passingtime. 00061 * @param self The instance variable 00062 * @param now The current time 00063 */ 00064 void (*update)(LsgNode* self, float now); 00065 /** 00066 * Display this node. 00067 * @param self The instance variable 00068 * @param frustum The viewing frustum transformed to the local 00069 * coordinate system 00070 */ 00071 void (*display)(LsgNode* self, LsgFrustum* frustum); 00072 /** 00073 * Check for collision and calculate nearest vertex if asked for. 00074 * @param self The instance variable 00075 * @param v Some vertex 00076 * @param nearest The buffer to store the vertex nearest to v that would 00077 * cause a collision. May be NULL to indicate that the 00078 * computation is not neccessary. 00079 * @return 1 if the vertex v collides with the node, 0 otherwise 00080 */ 00081 int (*collide)(LsgNode* self, Vertex v, Vertex nearest); 00082 }; 00083 00084 /** 00085 * \relates LsgNode 00086 * Constructor for LsgNode. Initially clear the bounding box and set the dirty flag 00087 * to make the first call to update recompute the complete bounding box tree. 00088 * @param self The instance variable 00089 */ 00090 void LsgNode_init(LsgNode* self); 00091 00092 /** 00093 * \relates LsgNode 00094 * Clean the node by unsetting the dirty flag. 00095 * @param self The instance variable 00096 */ 00097 void LsgNode_clean(LsgNode* self); 00098 00099 /** 00100 * \relates LsgNode 00101 * Update the node. Does nothing at all. 00102 * @param self The instance variable 00103 */ 00104 void LsgNode_update(LsgNode* self, float now); 00105 00106 /** 00107 * \relates LsgNode 00108 * Display this node. Does nothing at all. 00109 * @param self The instance variable 00110 * @param frustum The view frustum transformed to the local coordinat system 00111 */ 00112 void LsgNode_display(LsgNode* self, LsgFrustum* frustum); 00113 00114 /** 00115 * \relates LsgNode 00116 * Check collision with this node. Delegate collision detection to bounding box 00117 * if it is valid. Otherwise always return 0. The value of nearest is not defined 00118 * if the bounding box is not valid. 00119 * @param self The instance variable 00120 * @param v Some vertex 00121 * @param nearest The buffer to store the vertex nearest to v that would 00122 * cause a collision. May be NULL to indicate that the 00123 * computation is not neccessary. 00124 * @return 0 if bounding box is not valid, otherwise the return value of 00125 * bbox_collide with the same vertex. 00126 */ 00127 int LsgNode_collide(LsgNode* self, Vertex v, Vertex nearest); 00128 00129 /** 00130 * \relates LsgNode 00131 * Destructor for LsgNode. Destroy the bounding box. 00132 * @param self The instance variable 00133 */ 00134 void LsgNode_destroy(LsgNode* self); 00135 00136 #endif