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