Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2551 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Oct 11, 2004, 12:53:43 AM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: minor changes - enhanced sc controll, fixed uncontrolled rotation effect, added some debug outputs for testing purposes, reformatted some src files from win style but not all

Location:
orxonox/trunk/src
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r2190 r2551  
    66
    77bin_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
     8orxonox_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
    99
    1010#  uncomment the following if bencoder requires the math library
  • orxonox/trunk/src/Makefile.in

    r2190 r2551  
    117117#"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include"
    118118bin_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
     119orxonox_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
    120120subdir = src
    121121ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
     
    129129        data_tank.$(OBJEXT) world_entity.$(OBJEXT) vector.$(OBJEXT) \
    130130        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)
    132133orxonox_OBJECTS = $(am_orxonox_OBJECTS)
    133134orxonox_LDADD = $(LDADD)
     
    138139depcomp = $(SHELL) $(top_srcdir)/depcomp
    139140am__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 \
    141143@AMDEP_TRUE@    ./$(DEPDIR)/command_node.Po \
    142144@AMDEP_TRUE@    ./$(DEPDIR)/data_tank.Po ./$(DEPDIR)/ini_parser.Po \
     
    151153        -o $@
    152154DIST_SOURCES = $(orxonox_SOURCES)
    153 DIST_COMMON = $(srcdir)/Makefile.in INSTALL Makefile.am
     155DIST_COMMON = $(srcdir)/Makefile.in ChangeLog INSTALL Makefile.am
    154156SOURCES = $(orxonox_SOURCES)
    155157
     
    197199        -rm -f *.tab.c
    198200
     201@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base_entity.Po@am__quote@
    199202@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/camera.Po@am__quote@
    200203@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Po@am__quote@
  • orxonox/trunk/src/camera.cc

    r2190 r2551  
    2929Camera::Camera ()
    3030{
    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;
    3247}
    3348
     
    4863void Camera::time_slice (Uint32 deltaT)
    4964{
    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.
    5877*/
    5978void Camera::update_desired_place ()
    6079{
    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);
    63101               
    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.
    81202*/
    82203void Camera::apply ()
    83204{
    84         glMatrixMode (GL_PROJECTION);
     205  glMatrixMode (GL_PROJECTION);
    85206  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
    115237  float matrix[4][4];
    116238  actual_place.w.conjugate().matrix (matrix);
     239  /* orientation and */
    117240  glMultMatrixf ((float*)matrix);
    118         // translation
     241  /*  translation */
    119242  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
    121252  glMatrixMode (GL_MODELVIEW);
    122253  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);
    128254}
    129255
     
    136262void Camera::jump (Placement* plc = NULL)
    137263{
    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    }
    147274}
    148275
     
    157284void Camera::bind (WorldEntity* entity)
    158285{
    159         if( entity != NULL)
     286  if( entity != NULL)
     287    {
     288      if( entity->isFree ()) printf("Cannot bind camera to free entity");
     289      else
    160290        {
    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  
    1313//! Camera
    1414/**
    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.
    1920*/
     21
     22enum CAMERA_MODE {NORMAL, SMOTH_FOLLOW, STICKY, ELLIPTICAL};
     23
    2024class Camera {
    2125 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
    2553
    2654        void update_desired_place ();
  • orxonox/trunk/src/coordinates.h

    r2191 r2551  
    99#include "vector.h"
    1010
     11class Track;
     12
    1113//! Coordinates relative to track
    1214/**
     
    1618{
    1719  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
    1821  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;         //!< The direction the object is heading (relative to track direction)
     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)
    2124} Location;
    2225
     
    2831{
    2932  Vector r;              //!< Absolute x/y/z coordinates
    30   Quaternion w;            //!< Absolute orientation
     33  Quaternion w;          //!< Absolute orientation
    3134} Placement;
    3235
  • orxonox/trunk/src/ini_parser.cc

    r2190 r2551  
    6363int IniParser::get_section( char* section)
    6464{
    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)
    7481        {
    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))
    8186                {
    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;
    9189                }
     90            }
    9291        }
    93         return -1;
     92    }
     93  return -1;
    9494}
    9595
  • orxonox/trunk/src/orxonox.cc

    r2190 r2551  
    230230void Orxonox::mainLoop()
    231231{
    232         lastframe = SDL_GetTicks();
    233         bQuitOrxonox = false;
     232  lastframe = SDL_GetTicks();
     233  bQuitOrxonox = false;
    234234  // This is where everything is run
    235 printf("Orxonox|Entering main loop\n");
     235  printf("Orxonox|Entering main loop\n");
    236236  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");
    250254}
    251255
     
    283287void Orxonox::time_slice ()
    284288{
    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)
    287295        {
    288                 world->time_slice (curframe - lastframe);
    289                 world->update ();
    290                 localcamera->time_slice (curframe - lastframe);
     296          float fps = 1000/dt;
     297          printf("%f", fps);
    291298        }
    292         lastframe = curframe;
     299     
     300      world->time_slice (dt);
     301      world->update ();
     302      localcamera->time_slice (dt);
     303    }
     304  lastframe = curframe;
    293305}
    294306
  • orxonox/trunk/src/player.cc

    r2190 r2551  
    2828
    2929Player::~Player ()
     30
    3031{
    3132}
     
    3334void Player::post_spawn ()
    3435{
    35         travel_speed = 10.0;
     36        travel_speed = 15.0;
    3637        velocity = Vector();
    3738        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     
    7172void Player::draw ()
    7273{
    73         glMatrixMode(GL_MODELVIEW);
    74         glLoadIdentity();
    75         float matrix[4][4];
    76 
    77         glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
     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);
    7879  get_placement()->w.matrix (matrix);
    7980  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);
    91102}
    92103
     
    103114void Player::move (float time)
    104115{
    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;
    128144}
    129145
  • orxonox/trunk/src/player.h

    r2190 r2551  
    1212class Player : public WorldEntity
    1313{
    14         friend class World;
    15 
     14  friend class World;
     15 
    1616 public:
    1717  Player (bool isFree = false);
    1818  ~Player ();
    19 
    20         virtual void post_spawn ();
     19 
     20  virtual void post_spawn ();
    2121  virtual void tick (float time);
    2222  virtual void hit (WorldEntity* weapon, Vector loc);
    2323  virtual void destroy ();
    2424  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
    25         virtual void command (Command* cmd);
     25  virtual void command (Command* cmd);
    2626 
    2727  virtual void draw ();
    2828  virtual void get_lookat (Location* locbuf);
    29 
    30         virtual void left_world ();
    31 
     29 
     30  virtual void left_world ();
     31 
    3232 private:
    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         
     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  
    4141};
    4242
  • orxonox/trunk/src/stdincl.h

    r2190 r2551  
    1010#include <SDL/SDL.h>
    1111#include <GL/gl.h>
     12#include <GL/glu.h>
    1213
    1314#include "vector.h"
  • orxonox/trunk/src/track.cc

    r2190 r2551  
    5454
    5555/**
    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.
    6263*/
    6364void Track::map_camera (Location* lookat, Placement* camplc)
    6465{
    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);
    7484}
    7585
    7686/**
    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.
    8498*/
    8599bool Track::map_coords (Location* loc, Placement* plc)
     
    88102        float l = trace.len ();
    89103       
     104        /* change to the next track? */
    90105        if( loc->dist > l)
    91106        {
    92107                loc->dist -= l;
    93108                loc->part = nextID;
     109                //FIXME: loc->track = this;
    94110                return true;
    95111        }
    96112       
    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
    99117        plc->r = trace.r + (trace.a * ((loc->dist) / l)) + /*dir.apply*/(loc->pos);
    100118        plc->w = dir * loc->rot;
     
    107125        \param entity: pointer to the WorldEntity in question
    108126       
    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.
    110129*/
    111130void Track::post_enter (WorldEntity* entity)
     
    117136        \param entity: pointer to the WorldEntity in question
    118137       
    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.
    120140*/
    121141void Track::post_leave (WorldEntity* entity)
  • orxonox/trunk/src/track.h

    r2190 r2551  
    1111//!     The Red Line through a level
    1212/**
    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.
     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.
    1515*/
    1616class Track
    1717{
    1818 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 
    2327       
    2428 public:
  • orxonox/trunk/src/vector.cc

    r2190 r2551  
    1212
    1313   ### 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()
    1617   
    1718   Quaternion code borrowed from an Gamasutra article by Nick Bobick and Ken Shoemake
     
    147148  z = z / l;
    148149}
     150
     151
     152/**
     153   \bref returns the voctor normalized to length 1.0
     154*/
     155
     156Vector* 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
     173void Vector::scale(const Vector& v)
     174{
     175  x *= v.x;
     176  y *= v.y;
     177  z *= v.z;
     178}
     179
    149180 
    150181/**
     
    156187  return sqrt (x*x+y*y+z*z);
    157188}
     189
     190
     191
     192Vector Vector::abs()
     193{
     194  Vector v(fabs(x), fabs(y), fabs(z));
     195  return v;
     196}
     197
    158198
    159199/**
     
    168208}
    169209
     210
    170211/**
    171212   \brief calculate the angle between two vectors in degrees
     
    202243
    203244/**
    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.
    212255*/
    213256Quaternion::Quaternion (const Vector& dir, const Vector& up)
    214257{
    215         Vector z = dir;
     258  Vector z = dir;
    216259  z.normalize();
    217260  Vector x = up.cross(z);
     
    246289        \param yaw: the yaw in radians
    247290       
    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.
    250293*/
    251294Quaternion::Quaternion (float roll, float pitch, float yaw)
     
    407450void Quaternion::matrix (float m[4][4]) const
    408451{
    409         float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
    410 
    411         // calculate coefficients
    412         x2 = v.x + v.x;
     452  float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
     453 
     454  // calculate coefficients
     455  x2 = v.x + v.x;
    413456  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
     476void 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
    435524*/
    436525Quaternion::Quaternion (float m[4][4])
  • orxonox/trunk/src/vector.h

    r2190 r2551  
    3333  float dot (const Vector& v) const;
    3434  Vector cross (const Vector& v) const;
     35  void scale(const Vector& v);
    3536  float len() const;
    3637  void normalize();
     38  Vector* getNormalized();
     39  Vector abs();
    3740};
    3841
     
    6669        float norm () const;
    6770        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
    6876};
    6977
  • orxonox/trunk/src/world.cc

    r2190 r2551  
    2727
    2828/**
    29    \brief create a new World
    30    
    31    This creates a new empty world!
     29    \brief create a new World
     30    
     31    This creates a new empty world!
    3232*/
    3333World::World ()
    3434{
    35         entities = new List<WorldEntity>();
    36 }
    37 
    38 /**
    39    \brief remove the World from memory
     35  entities = new List<WorldEntity>();
     36}
     37
     38/**
     39    \brief remove the World from memory
    4040*/
    4141World::~World ()
    4242{
    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.
    5253*/
    5354void World::collide ()
    5455{
    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 )
    6471                {
    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                  }
    8080                }
    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
    8790*/
    8891void World::draw ()
    8992{
    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*/
     170void 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) )
    110198                {
    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);
    117207                }
    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
    212227*/
    213228void World::time_slice (Uint32 deltaT)
    214229{
    215         List<WorldEntity> *l;
    216         WorldEntity* entity;
    217         float seconds = deltaT;
    218        
    219         seconds /= 1000;
    220        
    221         l = entities->get_next(); 
    222         while( l != NULL)
    223         {
    224                 entity = l->get_object();
    225                 entity->tick (seconds);
    226           l = l->get_next();
    227         }
    228        
    229         for( int i = 0; i < tracklen; i++) track[i].tick (seconds);
     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);
    230245}
    231246
    232247/**
    233         \brief removes level data from memory
     248   \brief removes level data from memory
    234249*/
    235250void World::unload()
    236251{
    237         if( pathnodes) delete []pathnodes;
    238         if( track) delete []pathnodes;
     252  if( pathnodes) delete []pathnodes;
     253  if( track) delete []pathnodes;
    239254}
    240255
    241256/**
    242         \brief loads a simple level for testing purposes
     257   \brief loads a simple level for testing purposes
    243258*/
    244259void World::load_debug_level()
    245260{
    246         // create some path nodes
    247         pathnodes = new Vector[6];
    248         pathnodes[0] = Vector(0, 0, 0);
    249         pathnodes[1] = Vector(-100, 40, 0);
    250         pathnodes[2] = Vector(-100, 140, 0);
    251         pathnodes[3] = Vector(0, 180, 0);
    252         pathnodes[4] = Vector(100, 140, 0);
    253         pathnodes[5] = Vector(100, 40, 0);     
    254        
    255         // create the tracks
    256         tracklen = 6;
    257         track = new Track[6];
    258         for( int i = 0; i < tracklen; i++)
    259         {
    260                 track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]);
    261         }
    262        
    263         // create a player
    264         WorldEntity* myPlayer = (WorldEntity*) spawn<Player>();
    265        
    266         // bind input
     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
    267282  Orxonox *orx = Orxonox::getInstance();
    268283  orx->get_localinput()->bind (myPlayer);
    269284 
    270         // bind camera
    271         orx->get_camera()->bind (myPlayer);
     285  // bind camera
     286  orx->get_camera()->bind (myPlayer);
    272287}
    273288
    274289/**
    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
    276292*/
    277293void World::calc_camera_pos (Location* loc, Placement* plc)
  • orxonox/trunk/src/world.h

    r2190 r2551  
    4040                // base level data
    4141        Track* track;
    42         Uint32 tracklen;
     42        Uint32 tracklen;   // number of Tracks the World consist of
    4343        Vector* pathnodes;
    4444
  • orxonox/trunk/src/world_entity.h

    r2190 r2551  
    1414class WorldEntity
    1515{       
    16         friend class World;
    17 
     16  friend class World;
     17 
    1818 public:
    1919  WorldEntity (bool isFree = false);
    2020  ~WorldEntity ();
    21 
    22         Location* get_location ();
    23         Placement* get_placement ();
    24         void set_collision (CollisionCluster* newhull);
    25 
    26         bool isFree ();
    27         
     21 
     22  Location* get_location ();
     23  Placement* get_placement ();
     24  void set_collision (CollisionCluster* newhull);
     25 
     26  bool isFree ();
     27  
    2828  //void addAbility(Ability* ability);
    2929  //void removeAbility(Ability* ability);
    30 
    31         virtual void post_spawn ();
     30 
     31  virtual void post_spawn ();
    3232  virtual void tick (float time);
    3333  virtual void hit (WorldEntity* weapon, Vector loc);
    3434  virtual void destroy ();
    3535  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
    36         virtual void command (Command* cmd);
     36  virtual void command (Command* cmd);
    3737 
    3838  virtual void draw ();
    3939  virtual void get_lookat (Location* locbuf);
    40 
    41         virtual void left_world ();
    42 
     40 
     41  virtual void left_world ();
     42 
    4343 private:
    4444  const bool bFree;     
     
    4646  bool bDraw;
    4747 
    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);
     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);
    5555};
    5656
Note: See TracChangeset for help on using the changeset viewer.