[1853] | 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. |
---|
[1872] | 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[2190] | 15 | co-programmer: Christian Meyer |
---|
[1853] | 16 | */ |
---|
| 17 | |
---|
[2036] | 18 | #include "player.h" |
---|
[2190] | 19 | #include "stdincl.h" |
---|
| 20 | #include "collision.h" |
---|
[3365] | 21 | #include "importer/model.h" |
---|
[2036] | 22 | |
---|
[1856] | 23 | using namespace std; |
---|
[1853] | 24 | |
---|
| 25 | |
---|
[2190] | 26 | Player::Player(bool isFree) : WorldEntity(isFree) |
---|
| 27 | { |
---|
[2811] | 28 | |
---|
[3365] | 29 | this->model = new Model("reaplow.obj"); |
---|
[3210] | 30 | /* |
---|
[2730] | 31 | objectList = glGenLists(1); |
---|
| 32 | glNewList (objectList, GL_COMPILE); |
---|
| 33 | |
---|
| 34 | glBegin(GL_TRIANGLES); |
---|
| 35 | glColor3f(1,1,1); |
---|
| 36 | glVertex3f(0,0,0.5); |
---|
| 37 | glVertex3f(-0.5,0,-1); |
---|
| 38 | glVertex3f(0.5,0,-1); |
---|
| 39 | |
---|
| 40 | glVertex3f(0,0,0.5); |
---|
| 41 | glVertex3f(0,0.5,-1); |
---|
| 42 | glVertex3f(0,-0.5,-1); |
---|
| 43 | glEnd(); |
---|
| 44 | |
---|
| 45 | glBegin(GL_QUADS); |
---|
| 46 | glColor3f(0,0,1); |
---|
| 47 | glVertex3f(0.5,0.5,-1); |
---|
| 48 | glVertex3f(0.5,-0.5,-1); |
---|
| 49 | glVertex3f(-0.5,-0.5,-1); |
---|
| 50 | glVertex3f(-0.5,0.5,-1); |
---|
| 51 | glEnd(); |
---|
| 52 | |
---|
| 53 | glEndList (); |
---|
[3210] | 54 | */ |
---|
[1872] | 55 | } |
---|
[1853] | 56 | |
---|
[3365] | 57 | Player::~Player () |
---|
[3194] | 58 | { |
---|
[3365] | 59 | delete this->model; |
---|
[1896] | 60 | } |
---|
[1853] | 61 | |
---|
[3365] | 62 | void Player::postSpawn () |
---|
[1858] | 63 | { |
---|
[3227] | 64 | travelSpeed = 15.0; |
---|
[2816] | 65 | velocity = Vector(); |
---|
| 66 | bUp = bDown = bLeft = bRight = bAscend = bDescend = false; |
---|
| 67 | bFire = false; |
---|
| 68 | acceleration = 10.0; |
---|
[3227] | 69 | setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
[1858] | 70 | } |
---|
| 71 | |
---|
[3365] | 72 | void Player::tick (float time) |
---|
[1872] | 73 | { |
---|
[3209] | 74 | // movement |
---|
[3365] | 75 | this->move (time); |
---|
[1872] | 76 | } |
---|
[1858] | 77 | |
---|
[3365] | 78 | void Player::hit (WorldEntity* weapon, Vector loc) |
---|
[1900] | 79 | { |
---|
| 80 | } |
---|
| 81 | |
---|
[3365] | 82 | void Player::destroy () |
---|
[1872] | 83 | { |
---|
| 84 | } |
---|
| 85 | |
---|
[3365] | 86 | void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) |
---|
[1872] | 87 | { |
---|
| 88 | } |
---|
| 89 | |
---|
[3365] | 90 | void Player::command (Command* cmd) |
---|
[1872] | 91 | { |
---|
[2636] | 92 | //printf("Player|recieved command [%s]\n", cmd->cmd); |
---|
| 93 | if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp; |
---|
| 94 | else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp; |
---|
| 95 | else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp; |
---|
| 96 | else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp; |
---|
| 97 | else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp; |
---|
[1872] | 98 | } |
---|
| 99 | |
---|
[3365] | 100 | void Player::draw () |
---|
[2640] | 101 | { |
---|
[2551] | 102 | glMatrixMode(GL_MODELVIEW); |
---|
| 103 | glLoadIdentity(); |
---|
| 104 | float matrix[4][4]; |
---|
| 105 | |
---|
[3365] | 106 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 107 | //rotate |
---|
| 108 | this->getAbsDir ().matrix (matrix); |
---|
[3226] | 109 | glMultMatrixf((float*)matrix); |
---|
[2551] | 110 | |
---|
[3226] | 111 | glMatrixMode(GL_MODELVIEW); |
---|
[3365] | 112 | this->model->draw(); |
---|
[3226] | 113 | // glCallList(objectList); |
---|
[2190] | 114 | } |
---|
[2036] | 115 | |
---|
[3365] | 116 | |
---|
| 117 | /*PN |
---|
[3226] | 118 | void Player::getLookat(Location* locbuf) |
---|
[1896] | 119 | { |
---|
[3227] | 120 | *locbuf = *getLocation(); |
---|
[3210] | 121 | //locbuf->dist += 5.0; |
---|
[2190] | 122 | } |
---|
[3365] | 123 | */ |
---|
[2036] | 124 | |
---|
[3365] | 125 | void Player::leftWorld () |
---|
[2190] | 126 | { |
---|
[1872] | 127 | } |
---|
| 128 | |
---|
[3365] | 129 | void Player::move (float time) |
---|
[1858] | 130 | { |
---|
[2551] | 131 | Vector accel(0.0, 0.0, 0.0); |
---|
[3227] | 132 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
[3365] | 133 | //Placement *pos = getPlacement(); |
---|
| 134 | |
---|
[2551] | 135 | /* calculate the direction in which the craft is heading */ |
---|
[3365] | 136 | Vector direction (1.0, 0.0, 0.0); |
---|
| 137 | //direction = this->absDirection.apply (direction); |
---|
| 138 | Vector orthDirection (0.0, 0.0, 1.0); |
---|
| 139 | //orthDirection = orthDirection.cross (direction); |
---|
[2551] | 140 | |
---|
| 141 | if( bUp) { accel = accel+(direction*acceleration); } |
---|
| 142 | if( bDown) { accel = accel-(direction*acceleration); } |
---|
[3365] | 143 | if( bLeft ) { accel = accel - (orthDirection*acceleration); } |
---|
| 144 | if( bRight ) { accel = accel + (orthDirection*acceleration); } |
---|
[2551] | 145 | if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */} |
---|
[3210] | 146 | if( bDescend) {/* FIXME */} /* \todo up and down player movement */ |
---|
[2551] | 147 | |
---|
[3365] | 148 | //Location* l = getLocation(); |
---|
[2551] | 149 | |
---|
| 150 | // r(t) = r(0) + v(0)*t + 1/2*a*t^2 |
---|
| 151 | // r = position |
---|
| 152 | // v = velocity |
---|
| 153 | // a = acceleration |
---|
| 154 | |
---|
| 155 | /* this the base-speed of the player: determines how fast and how the player follows the track*/ |
---|
[3365] | 156 | //l->dist = l->dist + travelSpeed * time; |
---|
| 157 | |
---|
| 158 | Vector* shift = new Vector (this->travelSpeed * time, 0, 0); |
---|
| 159 | this->shiftCoor (shift); |
---|
| 160 | |
---|
[2551] | 161 | /* this updates the player position on the track - user interaction */ |
---|
[3365] | 162 | //l->pos = l->pos + accel*time; |
---|
| 163 | Vector move = accel * time; |
---|
| 164 | this->shiftCoor (&move); |
---|
[1896] | 165 | } |
---|