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