Changeset 2551 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Oct 11, 2004, 12:53:43 AM (20 years ago)
- Location:
- orxonox/trunk
- Files:
-
- 4 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/README
r1896 r2551 20 20 1) Alien is a great film 21 21 2) Guiness is the most delicious beer 22 3) If you think there is anything missing: you can be shure it's an arcade game 22 3) If you think there is anything missing specialy in terms of story: you can be shure it's an arcade game 23 4) Wanna chill: ask Boozoo Bajou 23 24 24 25 to be continoued... -
orxonox/trunk/src/Makefile.am
r2190 r2551 6 6 7 7 bin_PROGRAMS=orxonox 8 orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc 8 orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc 9 9 10 10 # uncomment the following if bencoder requires the math library -
orxonox/trunk/src/Makefile.in
r2190 r2551 117 117 #"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include" 118 118 bin_PROGRAMS = orxonox 119 orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc 119 orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc 120 120 subdir = src 121 121 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 … … 129 129 data_tank.$(OBJEXT) world_entity.$(OBJEXT) vector.$(OBJEXT) \ 130 130 camera.$(OBJEXT) collision.$(OBJEXT) command_node.$(OBJEXT) \ 131 ini_parser.$(OBJEXT) keynames.$(OBJEXT) track.$(OBJEXT) 131 ini_parser.$(OBJEXT) keynames.$(OBJEXT) track.$(OBJEXT) \ 132 base_entity.$(OBJEXT) 132 133 orxonox_OBJECTS = $(am_orxonox_OBJECTS) 133 134 orxonox_LDADD = $(LDADD) … … 138 139 depcomp = $(SHELL) $(top_srcdir)/depcomp 139 140 am__depfiles_maybe = depfiles 140 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/camera.Po ./$(DEPDIR)/collision.Po \ 141 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/base_entity.Po ./$(DEPDIR)/camera.Po \ 142 @AMDEP_TRUE@ ./$(DEPDIR)/collision.Po \ 141 143 @AMDEP_TRUE@ ./$(DEPDIR)/command_node.Po \ 142 144 @AMDEP_TRUE@ ./$(DEPDIR)/data_tank.Po ./$(DEPDIR)/ini_parser.Po \ … … 151 153 -o $@ 152 154 DIST_SOURCES = $(orxonox_SOURCES) 153 DIST_COMMON = $(srcdir)/Makefile.in INSTALL Makefile.am155 DIST_COMMON = $(srcdir)/Makefile.in ChangeLog INSTALL Makefile.am 154 156 SOURCES = $(orxonox_SOURCES) 155 157 … … 197 199 -rm -f *.tab.c 198 200 201 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base_entity.Po@am__quote@ 199 202 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/camera.Po@am__quote@ 200 203 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Po@am__quote@ -
orxonox/trunk/src/camera.cc
r2190 r2551 29 29 Camera::Camera () 30 30 { 31 bound = NULL; 31 bound = NULL; 32 /* give it some physical live */ 33 m = 10; 34 a = new Vector(0.0, 0.0, 0.0); 35 v = new Vector(0.0, 0.0, 0.0); 36 fs = new Vector(0.0, 0.0, 0.0); 37 cameraMode = NORMAL; 38 39 deltaTime = 3000.0; 40 cameraOffset = 1.0; 41 cameraOffsetZ = 10.0; 42 t = 0.0; 43 44 actual_place.r.x = 0.0; 45 actual_place.r.y = 10.0; 46 actual_place.r.z = -5.0; 32 47 } 33 48 … … 48 63 void Camera::time_slice (Uint32 deltaT) 49 64 { 50 update_desired_place (); 51 jump (NULL); 52 } 53 54 /** 55 \brief this calculates the location where the track wants the camera to be 56 57 This refreshes the placement the camera should have according to the bound entity's position on the track. 65 if(t <= deltaTime) 66 {t += deltaT;} 67 //printf("time is: t=%f\n", t ); 68 update_desired_place (); 69 jump (NULL); 70 } 71 72 /** 73 \brief this calculates the location where the track wants the camera to be 74 75 This refreshes the placement the camera should have according to the 76 bound entity's position on the track. 58 77 */ 59 78 void Camera::update_desired_place () 60 79 { 61 Orxonox *orx = Orxonox::getInstance(); 62 Location lookat; 80 switch(cameraMode) 81 { 82 83 case ELLIPTICAL: 84 { 85 //r = actual_place.r 86 Orxonox *orx = Orxonox::getInstance(); 87 Location lookat; 88 Placement plFocus; 89 if( bound != NULL) 90 { 91 bound->get_lookat (&lookat); 92 orx->get_world()->calc_camera_pos (&lookat, &plFocus); 93 Quaternion *fr; 94 if(t < 20.0) 95 { 96 Vector *start = new Vector(0.0, 1.0, 0.0); 97 //r = /*actual_place.r*/ *start - plFocus.r; 98 r = *(new Vector(0.0, 5.0, 0.0)); 99 100 Vector up(0.0, 0.0, 1.0); 63 101 64 if( bound != NULL) 65 { 66 bound->get_lookat (&lookat); 67 orx->get_world()->calc_camera_pos (&lookat, &desired_place); 68 } 69 else 70 { 71 desired_place.r = Vector (0,0,0); 72 desired_place.w = Quaternion (); 73 } 74 } 75 76 /** 77 \brief initialize rendering perspective according to this camera 78 79 This is called immediately before the a rendering cycle starts, it sets all global rendering options as 80 well as the GL_PROJECTION matrix according to the camera. 102 Vector op(1.0, 0.0, 0.0); 103 float angle = angle_deg(op, *start); 104 printf("angle is: %f\n", angle); 105 106 //if in one plane 107 from = new Quaternion(angle, up); 108 109 //from = new Quaternion(*start, *up); 110 //&from = &plFocus.w; 111 //fr = &plFocus.w; real quaternion use 112 113 114 115 Vector vDirection(1.0, 0.0, 0.0); 116 //vDirection = plFocus.w.apply(vDirection); 117 to = new Quaternion(vDirection, *start); 118 res = new Quaternion(); 119 } 120 //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z ); 121 rAbs = r.len(); 122 if(t < 30.0) /* FIXME!!*/ 123 { 124 ka = rAbs / deltaTime*deltaTime; 125 } 126 /* this is the new length of the vector */ 127 //float len = ka * powf((deltaTime - t), 2); 128 129 /* calc the rotation */ 130 /* 131 Vector axis(0.0, 0.0, 1.0); 132 if(t < 30.0) 133 a0 = PI/4 - atanf(fabs(r.x) / fabs(r.y)); 134 printf("a0 = %f\n", a0); 135 float angle = a0/deltaTime * (deltaTime - t); 136 printf("angle is: %f\n", angle); 137 Quaternion q(angle, axis); 138 */ 139 //r = q.apply(r); 140 //r = r * (len/r.len()); 141 142 //res->quatSlerp(from, to, t/deltaTime, res); 143 res->quatSlerp(to, from, t/deltaTime, res); 144 145 Vector ursp(0.0, 0.0, 0.0); 146 desired_place.r = /*plFocus.r -*/ ursp - res->apply(r); 147 148 printf("desired place is: %f, %f, %f\n", desired_place.r.x, desired_place.r.y, desired_place.r.z); 149 //plLastBPlace = *bound->get_placement(); 150 } 151 } 152 break; 153 case SMOTH_FOLLOW: 154 { 155 Placement *plBound = bound->get_placement(); 156 Location lcBound; 157 if(bound != null) 158 { 159 bound->get_lookat(&lcBound); 160 Vector vDirection(0.0, 0.0, 1.0); 161 vDirection = plBound->w.apply(vDirection); 162 desired_place.r = (vDirection * ((lcBound.dist-10.0)/* / l*/)) + Vector(0,0,5.0); 163 } 164 break; 165 } 166 /* this is a camera mode that tries just to follow the entity. */ 167 case STICKY: 168 { 169 if(bound != null) 170 { 171 Placement *plBound = bound->get_placement(); 172 Vector vDirection(0.0, 0.0, 1.0); 173 Vector eclipticOffset(0.0, 0.0, 5.0); 174 vDirection = plBound->w.apply(vDirection); 175 desired_place.r = plBound->r - vDirection*10 + eclipticOffset; 176 } 177 break; 178 } 179 /* the camera is handled like an entity and rolls on the track */ 180 case NORMAL: 181 Orxonox *orx = Orxonox::getInstance(); 182 Location lookat; 183 if( bound != NULL) 184 { 185 bound->get_lookat (&lookat); 186 orx->get_world()->calc_camera_pos (&lookat, &desired_place); 187 } 188 else 189 { 190 desired_place.r = Vector (0,0,0); 191 desired_place.w = Quaternion (); 192 } 193 break; 194 } 195 } 196 197 /** 198 \brief initialize rendering perspective according to this camera 199 200 This is called immediately before the rendering cycle starts, it sets all global 201 rendering options as well as the GL_PROJECTION matrix according to the camera. 81 202 */ 82 203 void Camera::apply () 83 204 { 84 205 glMatrixMode (GL_PROJECTION); 85 206 glLoadIdentity (); 86 // view 87 // TO DO: implement options for frustum generation 88 glFrustum( -1.0,1.0,-1.0,1.0,1.5,250.0); 89 //Vector up(0,0,1); 90 //Vector dir(1,0,0); 91 //Quaternion q(dir,up); 92 //float matrix[4][4]; 93 //q.conjugate().matrix (matrix); 94 //glMultMatrixf ((float*)matrix); 95 //glTranslatef (10,0,-5); 96 // 97 //dir = Vector(-1,-1,0); 98 //q = Quaternion( dir, up); 99 //glMatrixMode (GL_MODELVIEW); 100 //glLoadIdentity (); 101 //q.matrix (matrix); 102 //glMultMatrixf ((float*)matrix); 103 //glTranslatef (2,2,0); 104 // 105 //glBegin(GL_TRIANGLES); 106 //glColor3f(1,0,0); 107 //glVertex3f(0,0,0.5); 108 //glColor3f(0,1,0); 109 //glVertex3f(-0.5,0,-1); 110 //glColor3f(0,0,1); 111 //glVertex3f(0.5,0,-1); 112 //glEnd(); 113 114 // rotation 207 // view 208 // TO DO: implement options for frustum generation 209 glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0); 210 //Vector up(0,0,1); 211 //Vector dir(1,0,0); 212 //Quaternion q(dir,up); 213 //float matrix[4][4]; 214 //q.conjugate().matrix (matrix); 215 //glMultMatrixf ((float*)matrix); 216 //glTranslatef (10,0,-5); 217 // 218 //dir = Vector(-1,-1,0); 219 //q = Quaternion( dir, up); 220 //glMatrixMode (GL_MODELVIEW); 221 //glLoadIdentity (); 222 //q.matrix (matrix); 223 //glMultMatrixf ((float*)matrix); 224 //glTranslatef (2,2,0); 225 // 226 //glBegin(GL_TRIANGLES); 227 //glColor3f(1,0,0); 228 //glVertex3f(0,0,0.5); 229 //glColor3f(0,1,0); 230 //glVertex3f(-0.5,0,-1); 231 //glColor3f(0,0,1); 232 //glVertex3f(0.5,0,-1); 233 //glEnd(); 234 235 // ===== first camera control calculation option 236 // rotation 115 237 float matrix[4][4]; 116 238 actual_place.w.conjugate().matrix (matrix); 239 /* orientation and */ 117 240 glMultMatrixf ((float*)matrix); 118 // translation241 /* translation */ 119 242 glTranslatef (-actual_place.r.x, -actual_place.r.y,- actual_place.r.z); 120 243 //Placement *plBound = bound->get_placement(); 244 245 // ===== second camera control calculation option 246 /* 247 gluLookAt(actual_place.r.x, actual_place.r.y, actual_place.r.z, 248 plBound->r.x, plBound->r.y, plBound->r.z, 249 0.0, 0.0, 1.0); 250 */ 251 121 252 glMatrixMode (GL_MODELVIEW); 122 253 glLoadIdentity (); 123 124 printf("Camera@%f/%f/%f\n",actual_place.r.x,actual_place.r.y,actual_place.r.z);125 Vector unique(1,0,0);126 Vector test = actual_place.w.apply (unique);127 printf("Camera&%f/%f/%f\n", test.x, test.y, test.z);128 254 } 129 255 … … 136 262 void Camera::jump (Placement* plc = NULL) 137 263 { 138 if( plc == NULL) 139 { 140 actual_place = desired_place; 141 } 142 else 143 { 144 desired_place = *plc; 145 actual_place = *plc; 146 } 264 if( plc == NULL) 265 { 266 actual_place = desired_place; 267 //printf("Camera|jump: camer@ %f, %f, %f\n\n", actual_place.r.x, actual_place.r.y, actual_place.r.z); 268 } 269 else 270 { 271 desired_place = *plc; 272 actual_place = *plc; 273 } 147 274 } 148 275 … … 157 284 void Camera::bind (WorldEntity* entity) 158 285 { 159 if( entity != NULL) 286 if( entity != NULL) 287 { 288 if( entity->isFree ()) printf("Cannot bind camera to free entity"); 289 else 160 290 { 161 if( entity->isFree ()) printf("Cannot bind camera to free entity");162 else bound = entity;163 164 } 291 bound = entity; 292 } 293 } 294 } -
orxonox/trunk/src/camera.h
r2190 r2551 13 13 //! Camera 14 14 /** 15 This class controls the viewpoint from which the World is rendered. To use the Camera it has 16 to be bound to a WorldEntity which serves as the reference focus point. The Camera itself calls 17 the WorldEntity::get_lookat() and World::calc_camera_pos() functions to calculate the position it 18 currently should be in. 15 This class controls the viewpoint from which the World is rendered. To use the 16 Camera it has to be bound to a WorldEntity which serves as the reference focus 17 point. The Camera itself calls the WorldEntity::get_lookat() and 18 World::calc_camera_pos() functions to calculate the position it currently should 19 be in. 19 20 */ 21 22 enum CAMERA_MODE {NORMAL, SMOTH_FOLLOW, STICKY, ELLIPTICAL}; 23 20 24 class Camera { 21 25 private: 22 WorldEntity* bound; //!< the WorldEntity the Camera is bound to 23 Placement actual_place; //!< the Camera's current position 24 Placement desired_place; //!< where the Camera should be according to calculations 26 WorldEntity* bound; //!< the WorldEntity the Camera is bound to 27 Placement actual_place; //!< the Camera's current position 28 Placement desired_place; //!< where the Camera should be according to calculations 29 30 /* physical system - not needed yet */ 31 float m; //!< mass 32 Vector *fs; //!< seil-kraft 33 Vector *a; //!< acceleration 34 Vector *v; //!< velocity 35 36 /* elliptical camera mode variables */ 37 Placement plLastBPlace; 38 float cameraOffset; 39 float cameraOffsetZ; 40 float deltaTime; 41 float t; 42 Vector r; 43 float rAbs; 44 float ka; 45 float a0; 46 47 Quaternion *from; 48 Quaternion *to; 49 Quaternion *res; 50 51 52 CAMERA_MODE cameraMode; //!< saves the camera mode: how the camera follows the entity 25 53 26 54 void update_desired_place (); -
orxonox/trunk/src/coordinates.h
r2191 r2551 9 9 #include "vector.h" 10 10 11 class Track; 12 11 13 //! Coordinates relative to track 12 14 /** … … 16 18 { 17 19 unsigned long part; //!< ID of the track part the object is on 20 Track* track; //!< This is the current Track to which the Entity belongs to 18 21 float dist; //!< The distance that has already been traveled on the track 19 Vector pos; //!< The position relative to the offset marked by the distance already covered 20 Quaternion rot; 22 Vector pos; //!< The position relative to the offset marked by the distance already covered - this is mostly for user interaction/control 23 Quaternion rot; //!< The direction the object is heading (relative to track direction) 21 24 } Location; 22 25 … … 28 31 { 29 32 Vector r; //!< Absolute x/y/z coordinates 30 Quaternion w; 33 Quaternion w; //!< Absolute orientation 31 34 } Placement; 32 35 -
orxonox/trunk/src/ini_parser.cc
r2190 r2551 63 63 int IniParser::get_section( char* section) 64 64 { 65 bInSection = false; 66 if( stream == NULL) return -1; 67 68 char linebuffer[PARSELINELENGHT]; 69 char secbuffer[PARSELINELENGHT]; 70 char* ptr; 71 72 rewind (stream); 73 while( !feof( stream)) 65 bInSection = false; 66 if( stream == NULL) return -1; 67 68 char linebuffer[PARSELINELENGHT]; 69 char secbuffer[PARSELINELENGHT]; 70 char* ptr; 71 72 rewind (stream); 73 while( !feof( stream)) 74 { 75 // get next line 76 fgets (linebuffer, PARSELINELENGHT, stream); 77 // remove newline char 78 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 79 // check for section identifyer 80 if( sscanf (linebuffer, "[%s", secbuffer) == 1) 74 81 { 75 // get next line 76 fgets (linebuffer, PARSELINELENGHT, stream); 77 // remove newline char 78 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 79 // check for section identifyer 80 if( sscanf (linebuffer, "[%s", secbuffer) == 1) 82 if( (ptr = strchr( secbuffer, ']')) != NULL) 83 { 84 *ptr = 0; 85 if( !strcmp( secbuffer, section)) 81 86 { 82 if( (ptr = strchr( secbuffer, ']')) != NULL) 83 { 84 *ptr = 0; 85 if( !strcmp( secbuffer, section)) 86 { 87 bInSection = true; 88 return 0; 89 } 90 } 87 bInSection = true; 88 return 0; 91 89 } 90 } 92 91 } 93 return -1; 92 } 93 return -1; 94 94 } 95 95 -
orxonox/trunk/src/orxonox.cc
r2190 r2551 230 230 void Orxonox::mainLoop() 231 231 { 232 233 232 lastframe = SDL_GetTicks(); 233 bQuitOrxonox = false; 234 234 // This is where everything is run 235 printf("Orxonox|Entering main loop\n");235 printf("Orxonox|Entering main loop\n"); 236 236 while( !bQuitOrxonox) 237 { 238 // Network 239 synchronize(); 240 // Process input 241 handle_input(); 242 // Process time 243 time_slice(); 244 // Process collision 245 collision(); 246 // Draw 247 display(); 248 } 249 printf("Orxonox|Exiting the main loop\n"); 237 { 238 printf("<=="); 239 240 // Network 241 synchronize(); 242 // Process input 243 handle_input(); 244 // Process time 245 time_slice(); 246 // Process collision 247 collision(); 248 // Draw 249 display(); 250 251 printf(">\n"); 252 } 253 printf("Orxonox|Exiting the main loop\n"); 250 254 } 251 255 … … 283 287 void Orxonox::time_slice () 284 288 { 285 Uint32 curframe = SDL_GetTicks(); 286 if( !pause) 289 Uint32 curframe = SDL_GetTicks(); 290 if( !pause) 291 { 292 Uint32 dt = curframe - lastframe; 293 294 if(dt > 0) 287 295 { 288 world->time_slice (curframe - lastframe); 289 world->update (); 290 localcamera->time_slice (curframe - lastframe); 296 float fps = 1000/dt; 297 printf("%f", fps); 291 298 } 292 lastframe = curframe; 299 300 world->time_slice (dt); 301 world->update (); 302 localcamera->time_slice (dt); 303 } 304 lastframe = curframe; 293 305 } 294 306 -
orxonox/trunk/src/player.cc
r2190 r2551 28 28 29 29 Player::~Player () 30 30 31 { 31 32 } … … 33 34 void Player::post_spawn () 34 35 { 35 travel_speed = 1 0.0;36 travel_speed = 15.0; 36 37 velocity = Vector(); 37 38 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; … … 71 72 void Player::draw () 72 73 { 73 74 75 76 77 74 glMatrixMode(GL_MODELVIEW); 75 glLoadIdentity(); 76 float matrix[4][4]; 77 78 glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z); 78 79 get_placement()->w.matrix (matrix); 79 80 glMultMatrixf ((float*)matrix); 80 81 glBegin(GL_TRIANGLES); 82 glColor3f(1,0,0); 83 glVertex3f(0,0,0.5); 84 glColor3f(0,1,0); 85 glVertex3f(-0.5,0,-1); 86 glColor3f(0,0,1); 87 glVertex3f(0.5,0,-1); 88 glEnd(); 89 90 printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z); 81 82 glBegin(GL_TRIANGLES); 83 glColor3f(1,1,1); 84 glVertex3f(0,0,0.5); 85 glVertex3f(-0.5,0,-1); 86 glVertex3f(0.5,0,-1); 87 88 glVertex3f(0,0,0.5); 89 glVertex3f(0,0.5,-1); 90 glVertex3f(0,-0.5,-1); 91 glEnd(); 92 93 glBegin(GL_QUADS); 94 glColor3f(0,0,1); 95 glVertex3f(0.5,0.5,-1); 96 glVertex3f(0.5,-0.5,-1); 97 glVertex3f(-0.5,-0.5,-1); 98 glVertex3f(-0.5,0.5,-1); 99 glEnd(); 100 101 //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z); 91 102 } 92 103 … … 103 114 void Player::move (float time) 104 115 { 105 float xAccel, yAccel, zAccel; 106 xAccel = yAccel = zAccel = 0; 107 if( bUp) xAccel += acceleration; 108 if( bDown) xAccel -= acceleration; 109 if( bLeft) yAccel += acceleration; 110 if( bRight) yAccel -= acceleration; 111 if( bAscend) zAccel += acceleration; 112 if( bDescend) zAccel -= acceleration; 113 114 Vector accel( xAccel, yAccel, zAccel); 115 116 Location* l = get_location(); 117 118 // r(t) = r(0) + v(0)*t + 1/2*a*t^2 119 // r = position 120 // v = velocity 121 // a = acceleration 122 123 l->pos = l->pos + velocity*time + (accel*(0.5*time*time)); 124 l->dist += travel_speed * time; 125 126 velocity = velocity + (accel * time); 127 printf("Player|velocity %f/%f/%f\n", velocity.x, velocity.y, velocity.z); 116 Vector accel(0.0, 0.0, 0.0); 117 /* FIXME: calculating the direction and orthDirection every time_slice is redundant! save it somewhere */ 118 Placement *pos = get_placement(); 119 /* calculate the direction in which the craft is heading */ 120 Vector direction(0.0, 0.0, 1.0); 121 direction = pos->w.apply(direction); 122 Vector orthDirection(0.0, 0.0, 1.0); 123 orthDirection = orthDirection.cross(direction); 124 125 if( bUp) { accel = accel+(direction*acceleration); } 126 if( bDown) { accel = accel-(direction*acceleration); } 127 if( bLeft ) { accel = accel + (orthDirection*acceleration); } 128 if( bRight ) { accel = accel - (orthDirection*acceleration); } 129 if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */} 130 if( bDescend) {/* FIXME */} 131 132 Location* l = get_location(); 133 134 // r(t) = r(0) + v(0)*t + 1/2*a*t^2 135 // r = position 136 // v = velocity 137 // a = acceleration 138 139 /* this the base-speed of the player: determines how fast and how the player follows the track*/ 140 l->dist = l->dist + travel_speed * time; 141 142 /* this updates the player position on the track - user interaction */ 143 l->pos = l->pos + accel*time; 128 144 } 129 145 -
orxonox/trunk/src/player.h
r2190 r2551 12 12 class Player : public WorldEntity 13 13 { 14 15 14 friend class World; 15 16 16 public: 17 17 Player (bool isFree = false); 18 18 ~Player (); 19 20 19 20 virtual void post_spawn (); 21 21 virtual void tick (float time); 22 22 virtual void hit (WorldEntity* weapon, Vector loc); 23 23 virtual void destroy (); 24 24 virtual void collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags); 25 25 virtual void command (Command* cmd); 26 26 27 27 virtual void draw (); 28 28 virtual void get_lookat (Location* locbuf); 29 30 31 29 30 virtual void left_world (); 31 32 32 private: 33 34 35 36 37 38 39 40 33 bool bUp, bDown, bLeft, bRight, bAscend, bDescend; 34 bool bFire; 35 Vector velocity; 36 float travel_speed; 37 float acceleration; 38 39 void move (float time); 40 41 41 }; 42 42 -
orxonox/trunk/src/stdincl.h
r2190 r2551 10 10 #include <SDL/SDL.h> 11 11 #include <GL/gl.h> 12 #include <GL/glu.h> 12 13 13 14 #include "vector.h" -
orxonox/trunk/src/track.cc
r2190 r2551 54 54 55 55 /** 56 \brief calculate a camera Placement from a "look at"-Location 57 \param lookat: the Location the camera should be centered on 58 \param camplc: pointer to a buffer where the new camera Placement should be put into 59 60 Theoretically you can place the camera wherever you want, but for the sake of common sense I suggest that you at least 61 try to keep the thing that should be looked at inside camera boundaries. 56 \brief calculate a camera Placement from a "look at"-Location 57 \param lookat: the Location the camera should be centered on 58 \param camplc: pointer to a buffer where the new camera Placement should be put into 59 60 Theoretically you can place the camera wherever you want, but for the sake of 61 common sense I suggest that you at least try to keep the thing that should be looked 62 at inside camera boundaries. 62 63 */ 63 64 void Track::map_camera (Location* lookat, Placement* camplc) 64 65 { 65 Line trace(*offset, *end - *offset); 66 float l = trace.len (); 67 68 // camplc->r = *offset + Vector(0,0,0.5); 69 // camplc->w = Quaternion (trace.a, Vector(0,0,1)); 70 float r = (lookat->dist)*PI / l; 71 camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); 72 camplc->w = Quaternion(Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)), Vector(0,sin(r),cos(r))); 73 66 Line trace(*offset, *end - *offset); 67 float l = trace.len (); 68 69 // camplc->r = *offset + Vector(0,0,0.5); 70 // camplc->w = Quaternion (trace.a, Vector(0,0,1)); 71 float r = (lookat->dist)*PI / l; 72 camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); 73 74 Vector w(0.0,0.0,0.0); 75 w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)); 76 //Vector up(0.0,sin(r),cos(r)); // corrupt... 77 Vector up(0.0, 0.0, 1.0); 78 79 camplc->w = Quaternion(w, up); 80 81 //printf("\n------\nup vector: [%f, %f, %f]\n", up.x, up.y, up.z); 82 //printf("direction: [%f, %f, %f]\n", w.x, w.y, w.z); 83 //printf("quaternion: w[ %f ], v[ %f, %f, %f ]\n", camplc->w.w, camplc->w.v.x, camplc->w.v.y, camplc->w.v.z); 74 84 } 75 85 76 86 /** 77 \brief calculate a Placement from a given Location 78 \param loc: the Location the entity is in 79 \param plc: a pointer to a buffer where the corresponding Placement should be put into 80 81 There are no limitations to how you transform a Location into a Placement, but for the sake of placement compatibility between 82 track parts you should make sure that the resulting Placement at dist == 0 is equal to the offset Vector and the Placement at 83 dist == len() is equal to the end Vector. Elseway there will be ugly artifacts when transfering between track parts. 87 \brief calculate a Placement from a given Location 88 \param loc: the Location the entity is in 89 \param plc: a pointer to a buffer where the corresponding Placement should be put 90 into 91 \return: true if track changes - false if track stays 92 93 There are no limitations to how you transform a Location into a Placement, but for 94 the sake of placement compatibility between track parts you should make sure that 95 the resulting Placement at dist == 0 is equal to the offset Vector and the Placement 96 at dist == len() is equal to the end Vector. Elseway there will be ugly artifacts 97 when transfering between track parts. 84 98 */ 85 99 bool Track::map_coords (Location* loc, Placement* plc) … … 88 102 float l = trace.len (); 89 103 104 /* change to the next track? */ 90 105 if( loc->dist > l) 91 106 { 92 107 loc->dist -= l; 93 108 loc->part = nextID; 109 //FIXME: loc->track = this; 94 110 return true; 95 111 } 96 112 97 Quaternion dir(trace.a, Vector(0,0,1)); 98 113 /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of 114 * the track */ 115 Quaternion dir(trace.a, Vector(0,0,1)); 116 99 117 plc->r = trace.r + (trace.a * ((loc->dist) / l)) + /*dir.apply*/(loc->pos); 100 118 plc->w = dir * loc->rot; … … 107 125 \param entity: pointer to the WorldEntity in question 108 126 109 You can do stuff like add or remove effects, do some coordinate finetuning or whatever in here. 127 You can do stuff like add or remove effects, do some coordinate finetuning 128 or whatever in here. 110 129 */ 111 130 void Track::post_enter (WorldEntity* entity) … … 117 136 \param entity: pointer to the WorldEntity in question 118 137 119 You can do stuff like add or remove effects, do some coordinate finetuning or whatever in here. 138 You can do stuff like add or remove effects, do some coordinate finetuning 139 or whatever in here. 120 140 */ 121 141 void Track::post_leave (WorldEntity* entity) -
orxonox/trunk/src/track.h
r2190 r2551 11 11 //! The Red Line through a level 12 12 /** 13 14 13 Handles level boundaries, bound movement mapping, camera placement and scripting. 14 To create special levels with special camera movement, rules or whatever, derive from this base class. 15 15 */ 16 16 class Track 17 17 { 18 18 private: 19 Uint32 ID; 20 Vector* offset; 21 Vector* end; 22 Uint32 nextID; 19 Uint32 ID; 20 Vector* offset; 21 Vector* end; 22 // Vector* direction; // unity direction vector: it is costy to always recalculate it 23 //Vector* up; // direction where up is ment to be - diffuse in space, eh? 24 //Vector* traverse; // right-left 25 Uint32 nextID; 26 23 27 24 28 public: -
orxonox/trunk/src/vector.cc
r2190 r2551 12 12 13 13 ### File Specific: 14 main-programmer: Christian Meyer 15 co-programmer: ... 14 main-programmer: Christian Meyer 15 co-programmer: Patrick Boenzli : Vector::scale() 16 Vector::abs() 16 17 17 18 Quaternion code borrowed from an Gamasutra article by Nick Bobick and Ken Shoemake … … 147 148 z = z / l; 148 149 } 150 151 152 /** 153 \bref returns the voctor normalized to length 1.0 154 */ 155 156 Vector* Vector::getNormalized() 157 { 158 float l = len(); 159 if(l != 1.0) 160 { 161 return this; 162 } 163 else if(l == 0.0) 164 { 165 return 0; 166 } 167 168 Vector *normalizedVector = new Vector(x / l, y /l, z / l); 169 return normalizedVector; 170 } 171 172 173 void Vector::scale(const Vector& v) 174 { 175 x *= v.x; 176 y *= v.y; 177 z *= v.z; 178 } 179 149 180 150 181 /** … … 156 187 return sqrt (x*x+y*y+z*z); 157 188 } 189 190 191 192 Vector Vector::abs() 193 { 194 Vector v(fabs(x), fabs(y), fabs(z)); 195 return v; 196 } 197 158 198 159 199 /** … … 168 208 } 169 209 210 170 211 /** 171 212 \brief calculate the angle between two vectors in degrees … … 202 243 203 244 /** 204 \brief calculates a look_at rotation 205 \param dir: the direction you want to look 206 \param up: specify what direction up should be 207 208 Mathematically this determines the rotation a (0,0,1)-Vector has to undergo to point the same way as dir. 209 If you want to use this with cameras, you'll have to reverse the dir Vector (Vector(0,0,0) - your viewing direction) 210 or you'll point the wrong way. You can use this for meshes as well (then you do not have to reverse the vector), but keep in mind that if you do that, the model's front 211 has to point in +z direction, and left and right should be -x or +x respectively or the mesh wont rotate correctly. 245 \brief calculates a look_at rotation 246 \param dir: the direction you want to look 247 \param up: specify what direction up should be 248 249 Mathematically this determines the rotation a (0,0,1)-Vector has to undergo to point 250 the same way as dir. If you want to use this with cameras, you'll have to reverse the 251 dir Vector (Vector(0,0,0) - your viewing direction) or you'll point the wrong way. You 252 can use this for meshes as well (then you do not have to reverse the vector), but keep 253 in mind that if you do that, the model's front has to point in +z direction, and left 254 and right should be -x or +x respectively or the mesh wont rotate correctly. 212 255 */ 213 256 Quaternion::Quaternion (const Vector& dir, const Vector& up) 214 257 { 215 258 Vector z = dir; 216 259 z.normalize(); 217 260 Vector x = up.cross(z); … … 246 289 \param yaw: the yaw in radians 247 290 248 I DO HONESTLY NOT EXACTLY KNOW WHICH ANGLE REPRESENTS WHICH ROTATION. And I do not know in what order they are applied,249 I just copy-pasted the code.291 I DO HONESTLY NOT EXACTLY KNOW WHICH ANGLE REPRESENTS WHICH ROTATION. And I do not know 292 in what order they are applied, I just copy-pasted the code. 250 293 */ 251 294 Quaternion::Quaternion (float roll, float pitch, float yaw) … … 407 450 void Quaternion::matrix (float m[4][4]) const 408 451 { 409 410 411 412 452 float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2; 453 454 // calculate coefficients 455 x2 = v.x + v.x; 413 456 y2 = v.y + v.y; 414 z2 = v.z + v.z; 415 xx = v.x * x2; xy = v.x * y2; xz = v.x * z2; 416 yy = v.y * y2; yz = v.y * z2; zz = v.z * z2; 417 wx = w * x2; wy = w * y2; wz = w * z2; 418 419 m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz; 420 m[2][0] = xz + wy; m[3][0] = 0.0; 421 422 m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz); 423 m[2][1] = yz - wx; m[3][1] = 0.0; 424 425 m[0][2] = xz - wy; m[1][2] = yz + wx; 426 m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0; 427 428 m[0][3] = 0; m[1][3] = 0; 429 m[2][3] = 0; m[3][3] = 1; 430 } 431 432 /** 433 \brief convert a rotational 4x4 glMatrix into a Quaternion 434 \param m: a 4x4 matrix in glMatrix order 457 z2 = v.z + v.z; 458 xx = v.x * x2; xy = v.x * y2; xz = v.x * z2; 459 yy = v.y * y2; yz = v.y * z2; zz = v.z * z2; 460 wx = w * x2; wy = w * y2; wz = w * z2; 461 462 m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz; 463 m[2][0] = xz + wy; m[3][0] = 0.0; 464 465 m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz); 466 m[2][1] = yz - wx; m[3][1] = 0.0; 467 468 m[0][2] = xz - wy; m[1][2] = yz + wx; 469 m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0; 470 471 m[0][3] = 0; m[1][3] = 0; 472 m[2][3] = 0; m[3][3] = 1; 473 } 474 475 476 void Quaternion::quatSlerp(const Quaternion* from, const Quaternion* to, float t, Quaternion* res) 477 { 478 float tol[4]; 479 double omega, cosom, sinom, scale0, scale1; 480 DELTA = 0.2; 481 482 cosom = from->v.x * to->v.x + from->v.y * to->v.y + from->v.z * to->v.z + from->w * to->w; 483 484 if( cosom < 0.0 ) 485 { 486 cosom = -cosom; 487 tol[0] = -to->v.x; 488 tol[1] = -to->v.y; 489 tol[2] = -to->v.z; 490 tol[3] = -to->w; 491 } 492 else 493 { 494 tol[0] = to->v.x; 495 tol[1] = to->v.y; 496 tol[2] = to->v.z; 497 tol[3] = to->w; 498 } 499 500 //if( (1.0 - cosom) > DELTA ) 501 //{ 502 omega = acos(cosom); 503 sinom = sin(omega); 504 scale0 = sin((1.0 - t) * omega) / sinom; 505 scale1 = sin(t * omega) / sinom; 506 //} 507 /* 508 else 509 { 510 scale0 = 1.0 - t; 511 scale1 = t; 512 } 513 */ 514 res->v.x = scale0 * from->v.x + scale1 * tol[0]; 515 res->v.y = scale0 * from->v.y + scale1 * tol[1]; 516 res->v.z = scale0 * from->v.z + scale1 * tol[2]; 517 res->w = scale0 * from->w + scale1 * tol[3]; 518 } 519 520 521 /** 522 \brief convert a rotational 4x4 glMatrix into a Quaternion 523 \param m: a 4x4 matrix in glMatrix order 435 524 */ 436 525 Quaternion::Quaternion (float m[4][4]) -
orxonox/trunk/src/vector.h
r2190 r2551 33 33 float dot (const Vector& v) const; 34 34 Vector cross (const Vector& v) const; 35 void scale(const Vector& v); 35 36 float len() const; 36 37 void normalize(); 38 Vector* getNormalized(); 39 Vector abs(); 37 40 }; 38 41 … … 66 69 float norm () const; 67 70 void matrix (float m[4][4]) const; 71 void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res); 72 73 private: 74 float DELTA; 75 68 76 }; 69 77 -
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) -
orxonox/trunk/src/world.h
r2190 r2551 40 40 // base level data 41 41 Track* track; 42 Uint32 tracklen; 42 Uint32 tracklen; // number of Tracks the World consist of 43 43 Vector* pathnodes; 44 44 -
orxonox/trunk/src/world_entity.h
r2190 r2551 14 14 class WorldEntity 15 15 { 16 17 16 friend class World; 17 18 18 public: 19 19 WorldEntity (bool isFree = false); 20 20 ~WorldEntity (); 21 22 23 24 25 26 27 21 22 Location* get_location (); 23 Placement* get_placement (); 24 void set_collision (CollisionCluster* newhull); 25 26 bool isFree (); 27 28 28 //void addAbility(Ability* ability); 29 29 //void removeAbility(Ability* ability); 30 31 30 31 virtual void post_spawn (); 32 32 virtual void tick (float time); 33 33 virtual void hit (WorldEntity* weapon, Vector loc); 34 34 virtual void destroy (); 35 35 virtual void collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags); 36 36 virtual void command (Command* cmd); 37 37 38 38 virtual void draw (); 39 39 virtual void get_lookat (Location* locbuf); 40 41 42 40 41 virtual void left_world (); 42 43 43 private: 44 44 const bool bFree; … … 46 46 bool bDraw; 47 47 48 49 50 51 52 53 54 48 WorldEntity* owner; 49 CollisionCluster* collisioncluster; 50 Placement place; 51 Location loc; 52 53 void init( Location* spawnloc, WorldEntity* spawnowner); 54 void init( Placement* spawnplc, WorldEntity* spawnowner); 55 55 }; 56 56
Note: See TracChangeset
for help on using the changeset viewer.