Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2080 in orxonox.OLD


Ignore:
Timestamp:
Jul 6, 2004, 10:29:05 PM (20 years ago)
Author:
chris
Message:

orxonox/branches/chris: Implemented basic track and spawning functionality. Added a function to convert a Rotation into a glmatrix. Implemented operator* in Rotation. Refined World, made World friend class of world_entity. Implemented camera functionality (can now be bound to the worldentity it should focus on).

Location:
orxonox/branches/chris/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/chris/src/camera.cc

    r2068 r2080  
    1212
    1313   ### File Specific:
    14    main-programmer: ...
     14   main-programmer: Christian Meyer
    1515   co-programmer: ...
    1616*/
     
    7070 
    7171  glMatrixMode (GL_MODELVIEW);
     72  glLoadIdentity ();
    7273}
    7374
     
    8788void Camera::bind (WorldEntity* entity)
    8889{
    89         if( entity != NULL) bound = entity;
     90        if( entity != NULL)
     91        {
     92                if( entity->bFree) printf("Cannot bind camera to free entity");
     93                else bound = entity;
     94        }
    9095}
  • orxonox/branches/chris/src/orxonox.cc

    r2068 r2080  
    8787       
    8888        if( path != NULL) strcpy (configfilename, path);
     89        else strcpy (configfilename, "./");
    8990        strcat (configfilename, "/.orxonox.conf");
    9091}
     
    191192int Orxonox::init_world ()
    192193{
    193         printf("Not yet implemented\n");
     194        world = new World();
     195       
     196        // TO DO: replace this with a menu/intro
     197        world->load_debug_level();
     198       
    194199        return 0;
    195200}
  • orxonox/branches/chris/src/track.cc

    r2068 r2080  
    1212
    1313   ### File Specific:
    14    main-programmer: ...
     14   main-programmer: Christian Meyer
    1515   co-programmer: ...
    1616*/
     
    2121using namespace std;
    2222
    23 
    24 
    25 Track::Track ()
     23Track::Track (Uint32 number, Uint32 next, Vector* start, Vector* finish)
    2624{
     25        ID = number;
     26        offset = start;
     27        end = finish;
     28        nextID = next;
    2729}
    2830
     
    3335void Track::map_camera (Location* lookat, Placement* camplc)
    3436{
     37        Line trace(*offset, *end - *offset);
     38        float l = trace.len ();
     39       
     40        camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0);
     41        camplc->w = Rotation( (trace.r + (trace.a * ((lookat->dist) / l))) - camplc->r);
    3542}
    3643
    37 void Track::map_coords (Location* loc, Placement* plc)
     44bool Track::map_coords (Location* loc, Placement* plc)
    3845{
     46        Line trace(*offset, *end - *offset);
     47        float l = trace.len ();
    3948       
     49        if( loc->dist > l)
     50        {
     51                loc->dist -= l;
     52                loc->part = nextID;
     53                return true;
     54        }
     55       
     56        Rotation dir(trace.a);
     57       
     58        plc->r = trace.r + (trace.a * ((loc->dist) / l)) + rotate_vector( loc->pos, dir);
     59        plc->w = dir * loc->rot;
     60       
     61        return false;
     62}
     63
     64void Track::post_enter (WorldEntity* entity)
     65{
     66}
     67
     68void Track::post_leave (WorldEntity* entity)
     69{
     70}
     71
     72void Track::tick (float deltaT)
     73{
    4074}
    4175
  • orxonox/branches/chris/src/track.h

    r2068 r2080  
    99        Vector* offset;
    1010        Vector* end;
     11        Uint32 nextID;
    1112       
    1213 public:
    13   Track ();
     14  Track (Uint32 number, Uint32 next, Vector* start, Vector* finish);
    1415  ~Track ();
    1516       
     17        virtual void post_enter (WorldEntity* entity);  // handle coordinate transition in here !!! (when dist < 0 or dist > lasttracklenght)
     18        virtual void post_leave (WorldEntity* entity);
     19        virtual void tick (float deltaT);
    1620        virtual void map_camera (Location* lookat, Placement* camplc);
    17         virtual void map_coords (Location* loc, Placement* plc);
     21        virtual bool map_coords (Location* loc, Placement* plc);        // this should return true if the entity left track boundaries
    1822};
    1923
  • orxonox/branches/chris/src/vector.cc

    r2068 r2080  
    291291}
    292292
     293/**
     294   \brief multiplies two rotational matrices
     295   \param r: another Rotation
     296   \return the matrix product of the Rotations
     297   
     298   Use this to rotate one rotation by another
     299*/
     300Rotation Rotation::operator* (Rotation& r)
     301{
     302        Rotation p();
     303       
     304        p[0] = m[0]*r.m[0] + m[1]*r.m[3] + m[2]*r.m[6];
     305        p[1] = m[0]*r.m[1] + m[1]*r.m[4] + m[2]*r.m[7];
     306        p[2] = m[0]*r.m[2] + m[1]*r.m[5] + m[2]*r.m[8];
     307       
     308        p[3] = m[3]*r.m[0] + m[4]*r.m[3] + m[5]*r.m[6];
     309        p[4] = m[3]*r.m[1] + m[4]*r.m[4] + m[5]*r.m[7];
     310        p[5] = m[3]*r.m[2] + m[4]*r.m[5] + m[5]*r.m[8];
     311
     312        p[6] = m[6]*r.m[0] + m[7]*r.m[3] + m[8]*r.m[6];
     313        p[7] = m[6]*r.m[1] + m[7]*r.m[4] + m[8]*r.m[7];
     314        p[8] = m[6]*r.m[2] + m[7]*r.m[5] + m[8]*r.m[8];
     315       
     316        return p;
     317}
     318
    293319
    294320/**
  • orxonox/branches/chris/src/vector.h

    r2068 r2080  
    5858  ~Rotation () {}
    5959 
     60  Rotation operator* (const Rotation& r);
     61 
    6062  glmatrix (float* buffer);
    6163};
  • orxonox/branches/chris/src/world.cc

    r2068 r2080  
    1818#include <stdlib.h>
    1919#include <cmath>
    20 
    21 #include "npc.h"
    22 #include "player.h"
    23 #include "environment.h"
    24 #include "shoot_laser.h"
    25 #include "shoot_rocket.h"
    26 #include "stdincl.h"
    27 #include "data_tank.h"
    2820
    2921#include "world.h"
     
    4638World::~World ()
    4739{
     40        unload ();
    4841        delete entities;
    4942}
    5043
    51 template<class T> T* World::spawn<T>(Location* loc, WorldEntity* owner)
    52 {
     44template<class T> T* World::spawn<T>(Location* loc = NULL, WorldEntity* owner = NULL)
     45{
     46        Location zeroloc;
    5347        T* entity = new T();
    5448        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
     49        if( loc == NULL)
     50        {
     51                zeroloc.dist = 0;
     52                zeroloc.part = 0;
     53                zeroloc.pos = Vector();
     54                zeroloc.rot = Rotation();
     55                loc = &zeroloc;
     56        }
     57        entity->init (loc, owner);
     58        if (entity->bFree)
     59        {
     60                track[loc->part].map_coords( loc, entity->get_placement())
     61        }
     62        entity->post_spawn ();
     63        return entity;
     64}
     65
     66template<class T> T* World::spawn<T>(Placement* plc, WorldEntity* owner = NULL)
     67{
     68        T* entity = new T();
     69        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
     70        entity->init (plc, owner);
     71        if (!entity->bFree)
     72        {
     73                printf("Can't spawn unfree entity with placement\n");
     74                entities->remove( (WorldEntity*)entity, LIST_FIND_FW);
     75                return NULL;
     76        }
     77        entity->post_spawn ();
    5578        return entity;
    5679}
     
    107130void World::update ()
    108131{
     132        List<WorldEntity> *l;
     133        WorldEntity* entity;
     134        Location* loc;
     135        Placement* plc;
     136        Uint32 t;
     137       
     138        l = entities->get_next(); 
     139        while( l != NULL)
     140        {
     141                entity = l->get_object();
     142               
     143                if( entity != bFree)
     144                {
     145                        loc = entity->get_location();
     146                        plc = entity->get_placement();
     147                        t = loc->part;
     148                       
     149                        if( t >= tracklen)
     150                        {
     151                                printf("An entity is out of the game area\n");
     152                                entity->left_world ();
     153                        }
     154                        else
     155                        {
     156                                while( track[t].map_coords( loc, plc))
     157                                {
     158                                        track[t]->post_leave (entity);
     159                                        if( loc->part >= tracklen)
     160                                        {
     161                                                printf("An entity has left the game area\n");
     162                                                entity->left_world ();
     163                                                break;
     164                                        }
     165                                        track[loc->part]->post_enter (entity);
     166                                }
     167                        }
     168                }
     169                else
     170                {
     171                        // TO DO: implement check whether this particular free entity is out of the game area
     172                        // TO DO: call function to notify the entity that it left the game area
     173                }
     174               
     175          l = l->get_next();
     176        }
     177       
    109178}
    110179
     
    124193          l = l->get_next();
    125194        }
    126 }
     195       
     196        for( int i = 0; i < tracklen) track[i].tick (seconds);
     197}
     198
     199void World::unload()
     200{
     201        if( pathnodes) delete []pathnodes;
     202        if( track) delete []pathnodes;
     203}
     204
     205void World::load_debug_level()
     206{
     207        // create some path nodes
     208        pathnodes = new Vector[6];
     209        pathnodes[0] = Vector(0, 0, 0);
     210        pathnodes[1] = Vector(-100, 40, 0);
     211        pathnodes[2] = Vector(-100, 140, 0);
     212        pathnodes[3] = Vector(0, 180, 0);
     213        pathnodes[4] = Vector(100, 140, 0);
     214        pathnodes[5] = Vector(100, 40, 0);     
     215       
     216        // create the tracks
     217        tracklen = 6;
     218        track = new Track[6];
     219        for( int i = 0; i < tracklen; i++)
     220        {
     221                track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]);
     222        }
     223       
     224        // create a player
     225       
     226        // bind input
     227        // bind camera
     228}
  • orxonox/branches/chris/src/world.h

    r2068 r2080  
    1717        void calc_camera_pos (Location* loc, Placement* plc);
    1818       
     19        void unload ();
     20       
     21        void load_debug_level ();
     22       
    1923 private:
    2024 
  • orxonox/branches/chris/src/world_entity.cc

    r2068 r2080  
    3737This is some sort of standard interface to all WorldEntities...
    3838*/
    39 WorldEntity::WorldEntity ()
     39WorldEntity::WorldEntity (bool isFree = false) : bFree(isFree)
    4040{
    41   health = 100;
    42   speed = 0;
     41        collisioncluster = NULL;
     42        owner = NULL;
    4343}
    44 
    4544
    4645WorldEntity::~WorldEntity () {}
    4746
    48 /**
    49    \brief sets the position of this entity
    50    \param position: Vector, pointing (from 0,0,0) to the new position
    51 */
    52 void WorldEntity::setPosition(Vector* position) {}
     47Location* WorldEntity::getLocation ()
     48{
     49        return &loc;
     50}
    5351
    54 /**
    55    \brief gets the postion of this entity
    56    \return a Vector, pointing (from 0,0,0) to the new position
    57 */
    58 Vector* getPosition() {}
     52Placement* WorldEntity::getPlacement ()
     53{
     54        return &place;
     55}
    5956
    60 /**
    61    \brief sets orientation of this entity
    62    \param orientation: vector specifying in which direction the entity looks
    63 */
    64 void WorldEntity::setOrientation(Vector* orientation) {}
    65 
    66 /**
    67    \brief gets orientation of this entity
    68    \return vector specifying in which direction the entity looks
    69 */
    70 Vector* WorldEntity::getOrientation() {}
     57void WorldEntity::set_collision (CollisionCluster* newhull)
     58{
     59        if( newhull == NULL) return;
     60        if( collisioncluster != NULL) delete collisioncluster;
     61        collisioncluster = newhull;
     62}
    7163
    7264/**
     
    149141void WorldEntity::destroy() {}
    150142
    151 /**
    152    \brief this function is automatically called before the entity enters the world
    153 */
    154 void WorldEntity::entityPreEnter() {}
     143void WorldEntity::init( Location* spawnloc, WorldEntity* spawnowner)
     144{
     145        loc = *spawnloc;
     146        owner = spawnowner;
     147}
    155148
    156 /**
    157    \brief this function is automatically called after the entity enters the world
    158 
    159 */
    160 void WorldEntity::entityPostEnter() {}
    161 
    162 /**
    163    \brief this function is automatically called before the entity quits the world
    164 
    165 */
    166 void WorldEntity::entityPreQuit() {}
    167 
    168 /**
    169    \brief this function is automatically called after the entity quits the world
    170 */
    171 void WorldEntity::entityPostQuit() {}
     149void WorldEntity::init( Placement* spawnplc, WorldEntity* spawnowner)
     150{
     151        plc = *spawnplc;
     152        owner = spawnowner;
     153}
  • orxonox/branches/chris/src/world_entity.h

    r2068 r2080  
    99class Ability;
    1010
    11 class WorldEntity {
     11class WorldEntity
     12{       
     13        friend class World;
    1214
    1315 public:
    14   WorldEntity ();
     16  WorldEntity (bool isFree);
    1517  ~WorldEntity ();
    1618
     19        Location* get_location ();
     20        Placement* get_placement ();
     21        void set_collision (CollisionCluster* newhull);
     22       
     23  //void addAbility(Ability* ability);
     24  //void removeAbility(Ability* ability);
    1725
    18   void setPosition(Vector* position);
    19   Vector* getPosition();
    20   void setOrientation(Vector* orientation);
    21   Vector* getOrientation();
    22   void setSpawnPoint(Vector* place);
    23   void setSpeed(float speed);
    24   float getSpeed();
    25   void setHealth(float health);
    26   float getHealth();
    27 
    28   void addAbility(Ability* ability);
    29   void removeAbility(Ability* ability);
    30 
     26        virtual void post_spawn ();
    3127  virtual void tick (float time);
    32   virtual void draw ();
    33   virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
    3428  virtual void hit (WorldEntity* weapon, Vector loc);
    3529  virtual void destroy ();
    36   virtual void command (Command* cmd);
     30  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
     31        virtual void command (Command* cmd);
     32 
     33  virtual void draw ();
    3734  virtual void get_lookat (Location* locbuf);
    3835
    39   virtual void entityPreEnter();
    40   virtual void entityPostEnter();
    41   virtual void entityPreQuit();
    42   virtual void entityPostQuit();
     36        virtual void left_world ();
    4337
     38 private:
    4439  bool bCollide;
    4540  bool bDraw;
    46 
    47  private:
     41  bool bFree;           // Whether entity movement is bound to the track
     42  
    4843        WorldEntity* owner;
    4944        CollisionCluster* collisioncluster;
    5045        Placement place;
    5146        Location loc;
    52   /* List of abilities */
    53   float health;
    54   float speed;
    55   /* entity can be in the air or at ground: */
    56   int airGround;
    5747
    58  
    59 
     48        void init( Location* spawnloc, WorldEntity* spawnowner);
     49        void init( Placement* spawnplc, WorldEntity* spawnowner);
    6050};
    6151
Note: See TracChangeset for help on using the changeset viewer.