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" |
---|
20 | //#include "collision.h" |
---|
21 | #include "objModel.h" |
---|
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 | /** |
---|
35 | \brief destructs the player |
---|
36 | */ |
---|
37 | Player::~Player () |
---|
38 | { |
---|
39 | this->destroy(); |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | \brief deletes all allocated memory of the Player |
---|
44 | */ |
---|
45 | void Player::destroy () |
---|
46 | { |
---|
47 | delete this->model; |
---|
48 | |
---|
49 | static_cast<WorldEntity*>(this)->destroy(); |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | \brief effect that occurs after the player is spawned |
---|
54 | */ |
---|
55 | void Player::postSpawn () |
---|
56 | { |
---|
57 | travelSpeed = 15.0; |
---|
58 | velocity = Vector(); |
---|
59 | bUp = bDown = bLeft = bRight = bAscend = bDescend = false; |
---|
60 | bFire = false; |
---|
61 | acceleration = 10.0; |
---|
62 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | \brief the function called for each passing timeSnap |
---|
67 | \param time The timespan passed since last update |
---|
68 | */ |
---|
69 | void Player::tick (float time) |
---|
70 | { |
---|
71 | // movement |
---|
72 | this->move (time); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | \brief if the player is hit, call this function |
---|
77 | \param weapon hit by this weapon |
---|
78 | \param loc ?? |
---|
79 | */ |
---|
80 | void Player::hit (WorldEntity* weapon, Vector loc) |
---|
81 | { |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /** |
---|
86 | \brief Collision with another Entity has this effect |
---|
87 | \param other the other colider |
---|
88 | \param ownhitflags ?? |
---|
89 | \param otherhitflags ?? |
---|
90 | */ |
---|
91 | void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) |
---|
92 | { |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | \brief The connection to the command node |
---|
97 | \param cmd the Command unit from witch to map |
---|
98 | |
---|
99 | here the commands are mapped to the players movement/weaponary |
---|
100 | */ |
---|
101 | void Player::command (Command* cmd) |
---|
102 | { |
---|
103 | //printf("Player|recieved command [%s]\n", cmd->cmd); |
---|
104 | if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp; |
---|
105 | else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp; |
---|
106 | else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp; |
---|
107 | else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp; |
---|
108 | else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp; |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | \brief draws the player after transforming him. |
---|
113 | */ |
---|
114 | void Player::draw () |
---|
115 | { |
---|
116 | glMatrixMode(GL_MODELVIEW); |
---|
117 | glPushMatrix(); |
---|
118 | float matrix[4][4]; |
---|
119 | |
---|
120 | /* translate */ |
---|
121 | glTranslatef (this->getAbsCoor ().x, |
---|
122 | this->getAbsCoor ().y, |
---|
123 | this->getAbsCoor ().z); |
---|
124 | /* rotate */ |
---|
125 | this->getAbsDir ().matrix (matrix); |
---|
126 | glMultMatrixf((float*)matrix); |
---|
127 | |
---|
128 | this->model->draw(); |
---|
129 | glPopMatrix(); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /*PN |
---|
134 | void Player::getLookat(Location* locbuf) |
---|
135 | { |
---|
136 | *locbuf = *getLocation(); |
---|
137 | //locbuf->dist += 5.0; |
---|
138 | } |
---|
139 | */ |
---|
140 | |
---|
141 | /** |
---|
142 | \brief the action occuring if the player left the game |
---|
143 | */ |
---|
144 | void Player::leftWorld () |
---|
145 | { |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | \brief action if player moves |
---|
150 | \param time the timeslice since the last frame |
---|
151 | */ |
---|
152 | void Player::move (float time) |
---|
153 | { |
---|
154 | Vector accel(0.0, 0.0, 0.0); |
---|
155 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
156 | //Placement *pos = getPlacement(); |
---|
157 | |
---|
158 | /* calculate the direction in which the craft is heading */ |
---|
159 | Vector direction (1.0, 0.0, 0.0); |
---|
160 | //direction = this->absDirection.apply (direction); |
---|
161 | Vector orthDirection (0.0, 0.0, 1.0); |
---|
162 | //orthDirection = orthDirection.cross (direction); |
---|
163 | |
---|
164 | if( bUp) { accel = accel+(direction*acceleration); } |
---|
165 | if( bDown) { accel = accel-(direction*acceleration); } |
---|
166 | if( bLeft ) { accel = accel - (orthDirection*acceleration); } |
---|
167 | if( bRight ) { accel = accel + (orthDirection*acceleration); } |
---|
168 | if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */} |
---|
169 | if( bDescend) {/* FIXME */} /* \todo up and down player movement */ |
---|
170 | |
---|
171 | //Location* l = getLocation(); |
---|
172 | |
---|
173 | // r(t) = r(0) + v(0)*t + 1/2*a*t^2 |
---|
174 | // r = position |
---|
175 | // v = velocity |
---|
176 | // a = acceleration |
---|
177 | |
---|
178 | /* this the base-speed of the player: determines how fast and how the player follows the track*/ |
---|
179 | //l->dist = l->dist + travelSpeed * time; |
---|
180 | |
---|
181 | // Vector* shift = new Vector (this->travelSpeed * time, 0, 0); |
---|
182 | // this->shiftCoor (shift); |
---|
183 | |
---|
184 | /* this updates the player position on the track - user interaction */ |
---|
185 | //l->pos = l->pos + accel*time; |
---|
186 | Vector move = accel * time; |
---|
187 | this->shiftCoor (&move); |
---|
188 | } |
---|