[3471] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: Christian Meyer |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #include "player.h" |
---|
| 19 | #include "stdincl.h" |
---|
[3474] | 20 | //#include "collision.h" |
---|
[3484] | 21 | #include "objModel.h" |
---|
[3471] | 22 | |
---|
| 23 | using namespace std; |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | \brief creates a new Player |
---|
| 27 | \param isFree if the player is free |
---|
| 28 | */ |
---|
| 29 | Player::Player(bool isFree) : WorldEntity(isFree) |
---|
| 30 | { |
---|
| 31 | this->model = new OBJModel("../data/models/reaplow.obj"); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /** |
---|
[3544] | 35 | \brief destructs the player, deletes alocated memory |
---|
[3471] | 36 | */ |
---|
| 37 | Player::~Player () |
---|
| 38 | { |
---|
[3566] | 39 | |
---|
[3471] | 40 | } |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | \brief effect that occurs after the player is spawned |
---|
| 44 | */ |
---|
| 45 | void Player::postSpawn () |
---|
| 46 | { |
---|
| 47 | travelSpeed = 15.0; |
---|
| 48 | velocity = Vector(); |
---|
| 49 | bUp = bDown = bLeft = bRight = bAscend = bDescend = false; |
---|
| 50 | bFire = false; |
---|
| 51 | acceleration = 10.0; |
---|
[3474] | 52 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
[3471] | 53 | } |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | \brief the function called for each passing timeSnap |
---|
| 57 | \param time The timespan passed since last update |
---|
| 58 | */ |
---|
| 59 | void Player::tick (float time) |
---|
| 60 | { |
---|
| 61 | // movement |
---|
| 62 | this->move (time); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | \brief if the player is hit, call this function |
---|
| 67 | \param weapon hit by this weapon |
---|
| 68 | \param loc ?? |
---|
| 69 | */ |
---|
| 70 | void Player::hit (WorldEntity* weapon, Vector loc) |
---|
| 71 | { |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | \brief Collision with another Entity has this effect |
---|
| 77 | \param other the other colider |
---|
| 78 | \param ownhitflags ?? |
---|
| 79 | \param otherhitflags ?? |
---|
| 80 | */ |
---|
| 81 | void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) |
---|
| 82 | { |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | \brief The connection to the command node |
---|
| 87 | \param cmd the Command unit from witch to map |
---|
| 88 | |
---|
| 89 | here the commands are mapped to the players movement/weaponary |
---|
| 90 | */ |
---|
| 91 | void Player::command (Command* cmd) |
---|
| 92 | { |
---|
| 93 | //printf("Player|recieved command [%s]\n", cmd->cmd); |
---|
| 94 | if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp; |
---|
| 95 | else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp; |
---|
| 96 | else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp; |
---|
| 97 | else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp; |
---|
| 98 | else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | \brief draws the player after transforming him. |
---|
| 103 | */ |
---|
| 104 | void Player::draw () |
---|
| 105 | { |
---|
| 106 | glMatrixMode(GL_MODELVIEW); |
---|
[3526] | 107 | glPushMatrix(); |
---|
[3471] | 108 | float matrix[4][4]; |
---|
| 109 | |
---|
| 110 | /* translate */ |
---|
| 111 | glTranslatef (this->getAbsCoor ().x, |
---|
| 112 | this->getAbsCoor ().y, |
---|
| 113 | this->getAbsCoor ().z); |
---|
| 114 | /* rotate */ |
---|
| 115 | this->getAbsDir ().matrix (matrix); |
---|
| 116 | glMultMatrixf((float*)matrix); |
---|
| 117 | |
---|
| 118 | this->model->draw(); |
---|
[3526] | 119 | glPopMatrix(); |
---|
[3471] | 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | /*PN |
---|
| 124 | void Player::getLookat(Location* locbuf) |
---|
| 125 | { |
---|
| 126 | *locbuf = *getLocation(); |
---|
| 127 | //locbuf->dist += 5.0; |
---|
| 128 | } |
---|
| 129 | */ |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | \brief the action occuring if the player left the game |
---|
| 133 | */ |
---|
| 134 | void Player::leftWorld () |
---|
| 135 | { |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | \brief action if player moves |
---|
| 140 | \param time the timeslice since the last frame |
---|
| 141 | */ |
---|
| 142 | void Player::move (float time) |
---|
| 143 | { |
---|
| 144 | Vector accel(0.0, 0.0, 0.0); |
---|
| 145 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
| 146 | //Placement *pos = getPlacement(); |
---|
| 147 | |
---|
| 148 | /* calculate the direction in which the craft is heading */ |
---|
| 149 | Vector direction (1.0, 0.0, 0.0); |
---|
| 150 | //direction = this->absDirection.apply (direction); |
---|
| 151 | Vector orthDirection (0.0, 0.0, 1.0); |
---|
| 152 | //orthDirection = orthDirection.cross (direction); |
---|
| 153 | |
---|
| 154 | if( bUp) { accel = accel+(direction*acceleration); } |
---|
| 155 | if( bDown) { accel = accel-(direction*acceleration); } |
---|
| 156 | if( bLeft ) { accel = accel - (orthDirection*acceleration); } |
---|
| 157 | if( bRight ) { accel = accel + (orthDirection*acceleration); } |
---|
| 158 | if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */} |
---|
| 159 | if( bDescend) {/* FIXME */} /* \todo up and down player movement */ |
---|
| 160 | |
---|
| 161 | //Location* l = getLocation(); |
---|
| 162 | |
---|
| 163 | // r(t) = r(0) + v(0)*t + 1/2*a*t^2 |
---|
| 164 | // r = position |
---|
| 165 | // v = velocity |
---|
| 166 | // a = acceleration |
---|
| 167 | |
---|
| 168 | /* this the base-speed of the player: determines how fast and how the player follows the track*/ |
---|
| 169 | //l->dist = l->dist + travelSpeed * time; |
---|
| 170 | |
---|
[3535] | 171 | // Vector* shift = new Vector (this->travelSpeed * time, 0, 0); |
---|
| 172 | // this->shiftCoor (shift); |
---|
[3471] | 173 | |
---|
| 174 | /* this updates the player position on the track - user interaction */ |
---|
| 175 | //l->pos = l->pos + accel*time; |
---|
| 176 | Vector move = accel * time; |
---|
| 177 | this->shiftCoor (&move); |
---|
| 178 | } |
---|