Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2190 in orxonox.OLD for orxonox/trunk/src/player.cc


Ignore:
Timestamp:
Jul 17, 2004, 12:11:20 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: merged and copied all files from branches/chris into trunk. it all seems to be in propper order.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/player.cc

    r2036 r2190  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer:
     15   co-programmer: Christian Meyer
    1616*/
    1717
    18 #include <iostream>
    19 #include <stdlib.h>
    20 #include <GL/glut.h>
    21 
    22 #include "shoot_laser.h"
    23 #include "shoot_rocket.h"
    24 #include "data_tank.h"
    25 
    2618#include "player.h"
     19#include "stdincl.h"
     20#include "collision.h"
    2721
    2822using namespace std;
    2923
    3024
    31 Player::Player()
    32    : WorldEntity() {
    33   //cout << "Player::Player" << endl;
    34   xCor = yCor = zCor = 0;
    35   shootLaser = new ShootLaser;
    36   shootRocket = new ShootRocket;
     25Player::Player(bool isFree) : WorldEntity(isFree)
     26{
    3727}
    3828
    3929Player::~Player ()
    4030{
    41   //delete shootLaser;
    4231}
    4332
    44 
    45 void Player::setPosition( float x, float y, float z)
     33void Player::post_spawn ()
    4634{
    47   xCor = x; yCor = y; zCor = z;
     35        travel_speed = 10.0;
     36        velocity = Vector();
     37        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     38        bFire = false;
     39        acceleration = 10.0;
     40        set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
    4841}
    4942
    50 
    51 void Player::getPosition(float* x, float* y, float* z)
     43void Player::tick (float time)
    5244{
    53   *x = xCor; *y = yCor; *z = zCor;
     45        // movement
     46        move (time);
    5447}
    5548
    56 
    57 void Player::setCollisionRadius(float radius)
     49void Player::hit (WorldEntity* weapon, Vector loc)
    5850{
    59   collisionRadius = radius;
    6051}
    6152
    62 
    63 void Player::goX(float x)
     53void Player::destroy ()
    6454{
    65   xCor += x;
    6655}
    6756
    68 
    69 void Player::goY(float y)
     57void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
    7058{
    71   yCor += y;
    7259}
    7360
    74 void Player::goZ(float z)
     61void Player::command (Command* cmd)
    7562{
    76   zCor += z;
     63        printf("Player|recieved command [%s]\n", cmd->cmd);
     64        if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
     65        else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
     66        else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
     67        else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
     68        else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
    7769}
    7870
     71void Player::draw ()
     72{
     73        glMatrixMode(GL_MODELVIEW);
     74        glLoadIdentity();
     75        float matrix[4][4];
    7976
    80 
    81 void Player::shoot(int n)
    82 {
    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   */
     77        glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
     78  get_placement()->w.matrix (matrix);
     79  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);
    11191}
    11292
     93void Player::get_lookat (Location* locbuf)
     94{
     95        *locbuf = *get_location();
     96        //locbuf->dist += 5.0;
     97}
    11398
    114 //void Player::addIO(InputOutput *io) {}
     99void Player::left_world ()
     100{
     101}
    115102
    116 
    117 void Player::paint()
     103void Player::move (float time)
    118104{
    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;
     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);
    129128}
    130129
     
    146145
    147146
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
Note: See TracChangeset for help on using the changeset viewer.