Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2096 in orxonox.OLD for orxonox/branches/chris


Ignore:
Timestamp:
Jul 9, 2004, 11:14:42 AM (20 years ago)
Author:
chris
Message:

orxonox/branches/chris: Messed with the Player class, added stuff here and there, debug world now creates a player and bind IO to it. Added some doxygen tags.

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

Legend:

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

    r2080 r2096  
    2121using namespace std;
    2222
     23/**
     24   \brief creates a Camera
     25   
     26   This standard constructor sets all parameters to zero
     27*/
    2328Camera::Camera ()
    2429{
     
    3035}
    3136
     37/**
     38   \brief default destructor
     39*/
    3240Camera::~Camera ()
    3341{
    3442}
    3543
     44/**
     45   \brief time based actualisation of camera parameters
     46   \param deltaT: The amount of time that has passed in milliseconds
     47   
     48   This is called by the World in every time_slice, use it to do fancy time dependant effects (such
     49   as smooth camera movement or swaying).
     50*/
    3651void Camera::time_slice (Uint32 deltaT)
    3752{
     
    3954}
    4055
     56/**
     57  \brief this calculates the location where the track wants the camera to be
     58   
     59        This refreshes the placement the camera should have according to the bound entity's position on the track.
     60*/
    4161void Camera::update_desired_place ()
    4262{
     
    5676}
    5777
     78/**
     79  \brief initialize rendering perspective according to this camera
     80   
     81        This is called immediately before the a rendering cycle starts, it sets all global rendering options as
     82        well as the GL_PROJECTION matrix according to the camera.
     83*/
    5884void Camera::apply ()
    5985{
     
    7399}
    74100
     101/**
     102  \brief set the camera position
     103  \param plc: The Placement to set the camera to
     104       
     105        This will set the actual and desired placement of the camera to plc
     106*/
    75107void Camera::jump (Placement* plc = NULL)
    76108{
     
    86118}
    87119
     120/**
     121  \brief bind the camera to an entity
     122  \param entity: The enitity to bind the camera to
     123       
     124        This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's
     125        Location and get_lookat() to determine the viewpoint the camera will render from.
     126        Note that you cannot bind a camera to a free entity.
     127*/
    88128void Camera::bind (WorldEntity* entity)
    89129{
  • orxonox/branches/chris/src/camera.h

    r2068 r2096  
     1/*!
     2    \file camera.h
     3    \brief Viewpoint controlling class definitions
     4*/
    15
    26#ifndef CAMERA_H
    37#define CAMERA_H
    48
     9//! Camera
     10/**
     11        This class controls the viewpoint from which the World is rendered. To use the Camera it has
     12        to be bound to a WorldEntity which serves as the reference focus point. The Camera itself calls
     13        the WorldEntity::get_lookat() and World::calc_camera_pos() functions to calculate the position it
     14        currently should be in.
     15*/
    516class Camera {
    617 private:
    7         WorldEntity* bound;
    8         Placement actual_place;
    9         Placement desired_place;
     18        WorldEntity* bound;             //!< the WorldEntity the Camera is bound to
     19        Placement actual_place; //!< the Camera's current position
     20        Placement desired_place; //!< where the Camera should be according to calculations
    1021
    1122        void update_desired_place ();
  • orxonox/branches/chris/src/command_node.cc

    r2068 r2096  
    2323
    2424using namespace std;
     25
    2526
    2627CommandNode::CommandNode (int ID)
     
    173174        List<WorldEntity>* plist = bound;
    174175       
     176        if( bLocalInput) send_over_network (cmd);
     177       
    175178        while( (plist = plist->get_next()) != NULL)
    176179        {
     
    178181        }
    179182}
     183
     184void CommandNode::set_netID (int ID)
     185{
     186}
     187
     188void CommandNode::send_over_network (Command* cmd)
     189{
     190}
  • orxonox/branches/chris/src/command_node.h

    r2066 r2096  
    1515#define DEFAULT_KEYBIND_FILE "default.ini"
    1616
     17//! Key aliasing structure
     18/**
     19        This structure contains the key aliasing information, e.g. the command strings that
     20        have been bound to the keys.
     21*/
    1722typedef struct
    1823{
     
    2126} KeyBindings;
    2227
     28//! Command Node
     29/**
     30        This class gathers all incoming SDL_Events and processes them. Keyboard, mouse and joystick input is
     31        captured and translated into command messages which are passed down to the bound WorldEntities (via WorldEntity::command()).
     32        Other SDL_Events are passed to Orxonox::event_handler() to deal with them. If the CommandNode has been created
     33        with bLocalInput set to false, it will query the network class for incoming commands that match his netID and pass
     34        them on to his WorldEntities.
     35*/
    2336class CommandNode {
    2437 private:
    25         bool bLocalInput;
    26         int netID;
     38        bool bLocalInput;       //!< Identifies the CommandNode that processes local input
     39        int netID;      //!< Unique identifier that is used to determine between remote CommandNodes
    2740        KeyBindings* aliases;
    28         List<WorldEntity>* bound;
     41        List<WorldEntity>* bound;       //!< List of WorldEntites that recieve commands from this CommandNode
    2942        int coord[2];
    3043       
     
    3346        void process_local ();
    3447        void process_network ();
    35         void send_over_networ();
     48        void send_over_network (Command* cmd);
    3649       
    3750 public:
     
    4457  void unbind (WorldEntity* entity);
    4558  void process ();
     59 
     60  void set_netID (int ID);
    4661};
    4762
  • orxonox/branches/chris/src/orxonox.cc

    r2080 r2096  
    276276}
    277277
     278Camera* Orxonox::get_localinput ()
     279{
     280        return localinput;
     281}
     282
    278283Camera* Orxonox::get_world ()
    279284{
  • orxonox/branches/chris/src/orxonox.h

    r2068 r2096  
    5050  int init (int argc, char** argv);
    5151       
     52        CommandNode* get_localinput();
    5253        Camera* get_camera();
    5354        World* get_world();
  • orxonox/branches/chris/src/player.cc

    r2058 r2096  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer:
     15   co-programmer: Christian Meyer
    1616*/
    1717
     
    2020#include <GL/glut.h>
    2121
    22 #include "shoot_laser.h"
    23 #include "shoot_rocket.h"
    24 #include "data_tank.h"
    25 
    2622#include "player.h"
    2723
     
    2925
    3026
    31 Player::Player()
    32    : WorldEntity() {
    33   //cout << "Player::Player" << endl;
    34   xCor = yCor = zCor = 0;
    35   shootLaser = new ShootLaser;
    36   shootRocket = new ShootRocket;
     27Player::Player(bool isFree) : WorldEntity(isFree)
     28{
    3729}
    3830
    3931Player::~Player ()
    4032{
    41   //delete shootLaser;
    4233}
    4334
    44 
    45 void Player::setPosition( float x, float y, float z)
     35void Player::post_spawn ()
    4636{
    47   xCor = x; yCor = y; zCor = z;
     37        travel_speed = 1.0;
     38        velocity = Vector();
     39        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     40        bFire = false;
     41        acceleration = 10.0;
     42        set_collision (new CollisionCluster (1.0, Vector(0,0,0));
    4843}
    4944
    50 
    51 void Player::getPosition(float* x, float* y, float* z)
     45void Player::tick (float time)
    5246{
    53   *x = xCor; *y = yCor; *z = zCor;
     47        // movement
     48        move (float time);
    5449}
    5550
    56 
    57 void Player::setCollisionRadius(float radius)
     51void Player::hit (WorldEntity* weapon, Vector loc)
    5852{
    59   collisionRadius = radius;
    6053}
    6154
    62 
    63 void Player::goX(float x)
     55void Player::destroy ()
    6456{
    65   xCor += x;
    6657}
    6758
    68 
    69 void Player::goY(float y)
     59void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
    7060{
    71   yCor += y;
    7261}
    7362
    74 void Player::goZ(float z)
     63void Player::command (Command* cmd)
    7564{
    76   zCor += z;
     65        if( strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
     66        else if( strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
     67        else if( strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
     68        else if( strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
     69        else if( strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
    7770}
    7871
    79 
    80 
    81 void Player::shoot(int n)
     72void Player::draw ()
    8273{
    83 
    84   //  if (shootLaser->inhibitor++ <= 100)
    85   shootLaser->addShoot(xCor, yCor, zCor);
    86   // else if (shootLaser->inhibitor++ <= 200)
    87   shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0);
    88   //  else if (shootLaser->inhibitor++ <= 300)
    89   shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0);
    90   //  else
    91   shootLaser->inhibitor =0;
    92  
    93   //  if (shootRocket->inhibitor++ >=80)
    94   {
    95     shootRocket->addBackParable(xCor, yCor, zCor);
    96     shootRocket->addSideAcc(xCor, yCor, zCor, RIGHT);
    97     shootRocket->addSideAcc(xCor, yCor, zCor, LEFT);
    98     shootRocket->addRotater(xCor, yCor, zCor);
    99     //  if (shootRocket->inhibitor >=90)
    100     //        shootRocket->inhibitor =0;
    101   }
    102   //cout << "Player::shoot" << endl;
    103  
    104   /*
    105   shootLaser->addShoot(xCor, yCor, zCor);
    106   shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0);
    107   shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0);
    108   //shootRocket->addShoot(xCor, yCor, zCor);
    109   //cout << "Player::shoot" << endl;
    110   */
    11174}
    11275
     76void Player::get_lookat (Location* locbuf)
     77{
     78        *locbuf = *get_location();
     79        locbuf->dist += 5.0;
     80}
    11381
    114 //void Player::addIO(InputOutput *io) {}
     82void Player::left_world ()
     83{
     84}
    11585
    116 
    117 void Player::paint()
     86void Player::move (float time)
    11887{
    119   //cout << "Player::drawPlayer" << endl;
    120   glPushMatrix();
    121   glTranslatef(xCor, yCor, 3.0);
    122   glScalef(1.0, 3.0, 1.0);
    123   glutWireCube(1.0);
    124   glPopMatrix();
    125   /* draw all the shoots additionaly */
    126   shootLaser->drawShoot();
    127   shootRocket->drawShoot();
    128   //cout << "Player::drawPlayer, end" << endl;
     88        float xAccel, yAccel, zAccel;
     89        xAccel = yAccel = zAccel = 0;
     90        if( bUp) xAccel += acceleration;
     91        if( bDown) xAccel -= acceleration;
     92        if( bLeft) yAccel += acceleration;
     93        if( bRight) yAccel -= acceleration;
     94        if( bAscend) zAccel += acceleration;
     95        if( bDescend) zAccel -= acceleration;
     96       
     97        Vector accel( xAccel, yAccel, zAccel);
     98       
     99        Location* l = get_location();
     100       
     101        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
     102        // r = position
     103        // v = velocity
     104        // a = acceleration
     105       
     106        l->pos = l->pos + velocity*time + (accel*(0.5*t*t)));
     107        l->dist += travel_speed * time;
     108       
     109        velocity += accel * time;
    129110}
    130111
     
    146127
    147128
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
  • orxonox/branches/chris/src/player.h

    r2058 r2096  
    55#include "world_entity.h"
    66
    7 class ShootLaser;
    8 class ShootRocket;
    9 
    10 
    117class Player : public WorldEntity
    128{
     9        friend class World;
    1310
    1411 public:
    15   Player ();
     12  Player (bool isFree);
    1613  ~Player ();
    1714
    18   /* position of the spacecraft */
    19   float xCor;
    20   float yCor;
    21   float zCor;
     15        virtual void post_spawn ();
     16  virtual void tick (float time);
     17  virtual void hit (WorldEntity* weapon, Vector loc);
     18  virtual void destroy ();
     19  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
     20        virtual void command (Command* cmd);
    2221 
    23   float collisionRadius;
     22  virtual void draw ();
     23  virtual void get_lookat (Location* locbuf);
    2424
    25 
    26   /* this player wanna shoot? so include a ref to ShootLaser */
    27   ShootLaser* shootLaser;
    28   ShootRocket* shootRocket;
    29 
    30   void setPosition(float x, float y, float z);
    31   void getPosition(float* x, float* y, float* z);
    32   void setCollisionRadius(float radius);
    33   void paint();
    34   void goX(float x);
    35   void goY(float y);
    36   void goZ(float x);
    37   void shoot(int n);
    38   //  void addIO(InputOutput *io);
    39   void drawPlayer(void);
     25        virtual void left_world ();
    4026
    4127 private:
    42 
    43 
     28        bool bUp, bDown, bLeft, bRight, bAscend, bDescend;
     29        bool bFire;
     30        Vector velocity;
     31        float travel_speed;
     32        float acceleration;
     33       
     34        void move (float time);
     35       
    4436};
    4537
  • orxonox/branches/chris/src/vector.h

    r2080 r2096  
    1212#define PI 3.14159265359f
    1313
    14 //! 3D vector
    15 /**
    16   Class for 3-dimensional vector calculation
    17  
    18   Supports all common vector operations (dot, cross, lenght and so on)
    19 */
     14CommandNode::
    2015class Vector {
    2116
  • orxonox/branches/chris/src/world.cc

    r2080 r2096  
    223223       
    224224        // create a player
     225        Worldentity* myPlayer = spawn<Player>();
    225226       
    226227        // bind input
     228  Orxonox *orx = Orxonox::getInstance();
     229  orx->get_localinput()->bind (myPlayer);
     230 
    227231        // bind camera
    228 }
     232        orx->get_camera()->bind (myPlayer);
     233}
  • orxonox/branches/chris/src/world.h

    r2080 r2096  
    1010
    1111        template<class T> T* spawn<T>(Location* loc, WorldEntity* owner);       // template to be able to spawn any derivation of WorldEntity
     12        template<class T> T* spawn<T>(Placement* plc, WorldEntity* owner = NULL)
    1213
    1314        void time_slice (Uint32 deltaT);
  • orxonox/branches/chris/src/world_entity.cc

    r2080 r2096  
    4545WorldEntity::~WorldEntity () {}
    4646
    47 Location* WorldEntity::getLocation ()
     47Location* WorldEntity::get_location ()
    4848{
    4949        return &loc;
    5050}
    5151
    52 Placement* WorldEntity::getPlacement ()
     52Placement* WorldEntity::get_placement ()
    5353{
    5454        return &place;
     
    152152        owner = spawnowner;
    153153}
     154
  • orxonox/branches/chris/src/world_entity.h

    r2080 r2096  
    2020        Placement* get_placement ();
    2121        void set_collision (CollisionCluster* newhull);
    22        
     22               
    2323  //void addAbility(Ability* ability);
    2424  //void removeAbility(Ability* ability);
Note: See TracChangeset for help on using the changeset viewer.