Changeset 2551 in orxonox.OLD for orxonox/trunk/src/world.cc
- Timestamp:
- Oct 11, 2004, 12:53:43 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world.cc
r2190 r2551 27 27 28 28 /** 29 \brief create a new World30 31 This creates a new empty world!29 \brief create a new World 30 31 This creates a new empty world! 32 32 */ 33 33 World::World () 34 34 { 35 36 } 37 38 /** 39 \brief remove the World from memory35 entities = new List<WorldEntity>(); 36 } 37 38 /** 39 \brief remove the World from memory 40 40 */ 41 41 World::~World () 42 42 { 43 unload (); 44 delete entities; 45 } 46 47 /** 48 \brief checks for collisions 49 50 This method runs through all WorldEntities known to the world and checks for collisions between them. 51 In case of collisions the collide() method of the corresponding entities is called. 43 unload (); 44 delete entities; 45 } 46 47 /** 48 \brief checks for collisions 49 50 This method runs through all WorldEntities known to the world and checks for collisions 51 between them. In case of collisions the collide() method of the corresponding entities 52 is called. 52 53 */ 53 54 void World::collide () 54 55 { 55 List<WorldEntity> *a, *b; 56 WorldEntity *aobj, *bobj; 57 58 a = entities->get_next(); 59 60 while( a != NULL) 61 { 62 aobj = a->get_object(); 63 if( aobj->bCollide && aobj->collisioncluster != NULL) 56 List<WorldEntity> *a, *b; 57 WorldEntity *aobj, *bobj; 58 59 a = entities->get_next(); 60 61 while( a != NULL) 62 { 63 aobj = a->get_object(); 64 if( aobj->bCollide && aobj->collisioncluster != NULL) 65 { 66 b = a->get_next(); 67 while( b != NULL ) 68 { 69 bobj = b->get_object(); 70 if( bobj->bCollide && bobj->collisioncluster != NULL ) 64 71 { 65 b = a->get_next(); 66 while( b != NULL) 67 { 68 bobj = b->get_object(); 69 if( bobj->bCollide && bobj->collisioncluster != NULL) 70 { 71 unsigned long ahitflg, bhitflg; 72 if( check_collision ( &aobj->place, aobj->collisioncluster, &ahitflg, &bobj->place, bobj->collisioncluster, &bhitflg)); 73 { 74 aobj->collide (bobj, ahitflg, bhitflg); 75 bobj->collide (aobj, bhitflg, ahitflg); 76 } 77 } 78 b = b->get_next(); 79 } 72 unsigned long ahitflg, bhitflg; 73 if( check_collision ( &aobj->place, aobj->collisioncluster, 74 &ahitflg, &bobj->place, bobj->collisioncluster, 75 &bhitflg) ); 76 { 77 aobj->collide (bobj, ahitflg, bhitflg); 78 bobj->collide (aobj, bhitflg, ahitflg); 79 } 80 80 } 81 a = a->get_next(); 82 } 83 } 84 85 /** 86 \brief runs through all entities calling their draw() methods 81 b = b->get_next(); 82 } 83 } 84 a = a->get_next(); 85 } 86 } 87 88 /** 89 \brief runs through all entities calling their draw() methods 87 90 */ 88 91 void World::draw () 89 92 { 90 // draw geometry 91 92 // draw entities 93 List<WorldEntity> *l; 94 WorldEntity* entity; 95 96 l = entities->get_next(); 97 while( l != NULL) 98 { 99 entity = l->get_object(); 100 if( entity->bDraw) entity->draw(); 101 l = l->get_next(); 102 } 103 104 // draw debug coord system 105 glLoadIdentity(); 106 glBegin(GL_LINES); 107 for( float x = -128.0; x < 128.0; x += 25.0) 108 { 109 for( float y = -128.0; y < 128.0; y += 25.0) 93 // draw geometry 94 95 // draw entities 96 List<WorldEntity> *l; 97 WorldEntity* entity; 98 99 l = entities->get_next(); 100 while( l != NULL ) 101 { 102 entity = l->get_object(); 103 if( entity->bDraw ) entity->draw(); 104 l = l->get_next(); 105 } 106 107 108 // draw debug coord system 109 glLoadIdentity(); 110 111 112 glBegin(GL_LINES); 113 114 for( float x = -128.0; x < 128.0; x += 25.0) 115 { 116 for( float y = -128.0; y < 128.0; y += 25.0) 117 { 118 glColor3f(1,0,0); 119 glVertex3f(x,y,-128.0); 120 glVertex3f(x,y,0.0); 121 glColor3f(0.5,0,0); 122 glVertex3f(x,y,0.0); 123 glVertex3f(x,y,128.0); 124 } 125 } 126 for( float y = -128.0; y < 128.0; y += 25.0) 127 { 128 for( float z = -128.0; z < 128.0; z += 25.0) 129 { 130 glColor3f(0,1,0); 131 glVertex3f(-128.0,y,z); 132 glVertex3f(0.0,y,z); 133 glColor3f(0,0.5,0); 134 glVertex3f(0.0,y,z); 135 glVertex3f(128.0,y,z); 136 } 137 } 138 for( float x = -128.0; x < 128.0; x += 25.0) 139 { 140 for( float z = -128.0; z < 128.0; z += 25.0) 141 { 142 glColor3f(0,0,1); 143 glVertex3f(x,-128.0,z); 144 glVertex3f(x,0.0,z); 145 glColor3f(0,0,0.5); 146 glVertex3f(x,0.0,z); 147 glVertex3f(x,128.0,z); 148 } 149 150 } 151 152 //draw track 153 glColor3f(0,1,1); 154 for( int i = 0; i < tracklen; i++) 155 { 156 glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z); 157 glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z); 158 } 159 glEnd(); 160 } 161 162 /** 163 \brief updates Placements and notifies entities when they left the 164 world 165 166 This runs trough all WorldEntities and maps Locations to Placements 167 if they are bound, checks whether they left the level boundaries 168 and calls appropriate functions. 169 */ 170 void World::update () 171 { 172 List<WorldEntity> *l; 173 WorldEntity* entity; 174 Location* loc; 175 Placement* plc; 176 Uint32 t; 177 178 l = entities->get_next(); 179 while( l != NULL ) 180 { 181 entity = l->get_object(); 182 183 if( !entity->isFree() ) 184 { 185 loc = entity->get_location(); 186 plc = entity->get_placement(); 187 t = loc->part; 188 189 /* check if entity has still a legal track-id */ 190 if( t >= tracklen ) 191 { 192 printf("An entity is out of the game area\n"); 193 entity->left_world (); 194 } 195 else 196 { 197 while( track[t].map_coords( loc, plc) ) 110 198 { 111 glColor3f(1,0,0); 112 glVertex3f(x,y,-128.0); 113 glVertex3f(x,y,0.0); 114 glColor3f(0.5,0,0); 115 glVertex3f(x,y,0.0); 116 glVertex3f(x,y,128.0); 199 track[t].post_leave (entity); 200 if( loc->part >= tracklen ) 201 { 202 printf("An entity has left the game area\n"); 203 entity->left_world (); 204 break; 205 } 206 track[loc->part].post_enter (entity); 117 207 } 118 } 119 for( float y = -128.0; y < 128.0; y += 25.0) 120 { 121 for( float z = -128.0; z < 128.0; z += 25.0) 122 { 123 glColor3f(0,1,0); 124 glVertex3f(-128.0,y,z); 125 glVertex3f(0.0,y,z); 126 glColor3f(0,0.5,0); 127 glVertex3f(0.0,y,z); 128 glVertex3f(128.0,y,z); 129 } 130 } 131 for( float x = -128.0; x < 128.0; x += 25.0) 132 { 133 for( float z = -128.0; z < 128.0; z += 25.0) 134 { 135 glColor3f(0,0,1); 136 glVertex3f(x,-128.0,z); 137 glVertex3f(x,0.0,z); 138 glColor3f(0,0,0.5); 139 glVertex3f(x,0.0,z); 140 glVertex3f(x,128.0,z); 141 } 142 } 143 //draw track 144 glColor3f(0,1,1); 145 for( int i = 0; i < tracklen; i++) 146 { 147 glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z); 148 glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z); 149 } 150 glEnd(); 151 } 152 153 /** 154 \brief updates Placements and notifies entities when they left the world 155 156 This runs trough all WorldEntities and maps Locations to Placements if they are bound, checks 157 whether they left the level boundaries and calls appropriate functions. 158 */ 159 void World::update () 160 { 161 List<WorldEntity> *l; 162 WorldEntity* entity; 163 Location* loc; 164 Placement* plc; 165 Uint32 t; 166 167 l = entities->get_next(); 168 while( l != NULL) 169 { 170 entity = l->get_object(); 171 172 if( !entity->isFree()) 173 { 174 loc = entity->get_location(); 175 plc = entity->get_placement(); 176 t = loc->part; 177 178 if( t >= tracklen) 179 { 180 printf("An entity is out of the game area\n"); 181 entity->left_world (); 182 } 183 else 184 { 185 while( track[t].map_coords( loc, plc)) 186 { 187 track[t].post_leave (entity); 188 if( loc->part >= tracklen) 189 { 190 printf("An entity has left the game area\n"); 191 entity->left_world (); 192 break; 193 } 194 track[loc->part].post_enter (entity); 195 } 196 } 197 } 198 else 199 { 200 // TO DO: implement check whether this particular free entity is out of the game area 201 // TO DO: call function to notify the entity that it left the game area 202 } 203 204 l = l->get_next(); 205 } 206 207 } 208 209 /** 210 \brief relays the passed time since the last frame to entities and Track parts 211 \param deltaT: the time passed since the last frame in milliseconds 208 } 209 } 210 else 211 { 212 /* TO DO: implement check whether this particular free entity 213 is out of the game area 214 TO DO: call function to notify the entity that it left 215 the game area 216 */ 217 } 218 219 l = l->get_next(); 220 } 221 222 } 223 224 /** 225 \brief relays the passed time since the last frame to entities and Track parts 226 \param deltaT: the time passed since the last frame in milliseconds 212 227 */ 213 228 void World::time_slice (Uint32 deltaT) 214 229 { 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 List<WorldEntity> *l; 231 WorldEntity* entity; 232 float seconds = deltaT; 233 234 seconds /= 1000; 235 236 l = entities->get_next(); 237 while( l != NULL) 238 { 239 entity = l->get_object(); 240 entity->tick (seconds); 241 l = l->get_next(); 242 } 243 244 for( int i = 0; i < tracklen; i++) track[i].tick (seconds); 230 245 } 231 246 232 247 /** 233 248 \brief removes level data from memory 234 249 */ 235 250 void World::unload() 236 251 { 237 238 252 if( pathnodes) delete []pathnodes; 253 if( track) delete []pathnodes; 239 254 } 240 255 241 256 /** 242 257 \brief loads a simple level for testing purposes 243 258 */ 244 259 void World::load_debug_level() 245 260 { 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 261 // create some path nodes 262 pathnodes = new Vector[6]; 263 pathnodes[0] = Vector(0, 0, 0); 264 pathnodes[1] = Vector(-100, 40, 0); 265 pathnodes[2] = Vector(-100, 140, 0); 266 pathnodes[3] = Vector(0, 180, 0); 267 pathnodes[4] = Vector(100, 140, 0); 268 pathnodes[5] = Vector(100, 40, 0); 269 270 // create the tracks 271 tracklen = 6; 272 track = new Track[6]; 273 for( int i = 0; i < tracklen; i++) 274 { 275 track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]); 276 } 277 278 // create a player 279 WorldEntity* myPlayer = (WorldEntity*) spawn<Player>(); 280 281 // bind input 267 282 Orxonox *orx = Orxonox::getInstance(); 268 283 orx->get_localinput()->bind (myPlayer); 269 284 270 271 285 // bind camera 286 orx->get_camera()->bind (myPlayer); 272 287 } 273 288 274 289 /** 275 \brief calls the correct mapping function to convert a given "look at"-Location to a Camera Placement 290 \brief calls the correct mapping function to convert a given "look at"-Location to a 291 Camera Placement 276 292 */ 277 293 void World::calc_camera_pos (Location* loc, Placement* plc)
Note: See TracChangeset
for help on using the changeset viewer.