Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/dave/src/player.cc @ 3172

Last change on this file since 3172 was 3172, checked in by bensch, 19 years ago

orxonox/branches/dave: (commit from dave) now the fighter banks while moving. really cool stuff

File size: 5.5 KB
Line 
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 "command_node.h"
22
23using namespace std;
24
25
26Player::Player(bool isFree) : WorldEntity(isFree)
27{
28
29  obj = new Object ("reaplow.obj");
30  tottime=0.0f;
31  movfinishright=movfinishleft=movfinishup=movfinishdown=false;
32  angleturn=false;
33 
34  /*
35  objectList = glGenLists(1);
36  glNewList (objectList, GL_COMPILE);
37
38  glBegin(GL_TRIANGLES);
39  glColor3f(1,1,1);
40  glVertex3f(0,0,0.5);
41  glVertex3f(-0.5,0,-1);
42  glVertex3f(0.5,0,-1);
43
44  glVertex3f(0,0,0.5);
45  glVertex3f(0,0.5,-1);
46  glVertex3f(0,-0.5,-1);
47  glEnd();
48   
49  glBegin(GL_QUADS);
50  glColor3f(0,0,1);
51  glVertex3f(0.5,0.5,-1);
52  glVertex3f(0.5,-0.5,-1);
53  glVertex3f(-0.5,-0.5,-1);
54  glVertex3f(-0.5,0.5,-1);
55  glEnd();
56 
57  glEndList ();
58  */
59}
60
61Player::~Player () 
62
63{
64}
65
66void Player::post_spawn ()
67{
68  travel_speed = 15.0;
69  velocity = Vector();
70  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
71  bFire = false;
72  acceleration = 10.0;
73  set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
74}
75
76void Player::tick (float time)
77{
78        // movement
79        move (time);
80}
81
82void Player::hit (WorldEntity* weapon, Vector loc)
83{
84}
85
86void Player::destroy ()
87{
88}
89
90void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
91{
92}
93
94void Player::command (Command* cmd)
95{
96  //printf("Player|recieved command [%s]\n", cmd->cmd);
97 
98  tottime=cmd->tottime;
99  rottime=cmd->rottime;
100  angleturn=cmd->angleturn;
101 
102 
103  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
104  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
105  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
106  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
107  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
108}
109
110void Player::draw ()
111{ 
112  glMatrixMode(GL_MODELVIEW);
113  glLoadIdentity();
114  float matrix[4][4];
115  float a[3];
116  a[0]=.8f;
117  a[1]=.8f;
118  a[2]=.8f;
119  glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
120  glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
121  get_placement()->w.matrix (matrix);
122  glMultMatrixf ((float*)matrix);
123 
124  glMatrixMode (GL_MODELVIEW);
125  glRotatef (angle,0,0,1);
126  glRotatef (-90, 0,1,0);
127 
128  obj->draw();
129  //  glCallList (objectList);
130
131 
132 
133  //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
134}
135
136void Player::get_lookat (Location* locbuf)
137{
138        *locbuf = *get_location();
139        //locbuf->dist += 5.0;
140}
141
142void Player::left_world ()
143{
144}
145
146void Player::move (float time)
147{
148  Vector accel(0.0, 0.0, 0.0);
149  /* FIXME: calculating the direction and orthDirection every time_slice is redundant! save it somewhere */
150  Placement *pos = get_placement();
151  /* calculate the direction in which the craft is heading  */
152  Vector direction(0.0, 0.0, 1.0);
153  direction = pos->w.apply(direction);
154  Vector orthDirection(0.0, 0.0, 1.0);
155  orthDirection = orthDirection.cross(direction);
156 
157  if(rottime<1.0f)
158          rottime=rottime+2.5f*time;
159  else
160          rottime=1.0f;
161  if(tottime<1.5f)
162          tottime=tottime+4.0f*time;
163  else
164          tottime=1.5f;
165 
166  //Langsam zurückdrehen    ->anlgeturn ist für das Zurückdrehen verantwortlich!
167  if((angleturn||bLeft&&bRight)&&angle<=0.0f){
168          if(!bLeft)
169          angle=angle+rottime*10.0f;
170          if(angle>0.0f){
171                 
172                  angleturn=false;
173                  angle=0.0f;}
174          }
175 
176  if((angleturn||bLeft&&bRight)&&angle>=0.0f){
177          if(!bRight)
178          angle=angle-rottime*10.0f;
179          if(angle<0.0f){
180                  angleturn=false;
181                  angle=0.0f;}
182                }
183  //Bewegung lansam abbremsen    **************
184  if(movfinishleft&&!bLeft){
185          accel=accel+(orthDirection*acceleration*(tottimecopy-pow(tottime,1.5f)+.5f));
186          if(tottime>tottimecopy)
187                  movfinishleft=false;
188  }
189  if(movfinishright&&!bRight){
190        accel=accel-(orthDirection*acceleration*(tottimecopy-pow(tottime,1.5f)+.5f));
191        if(tottime>tottimecopy)
192                movfinishright=false;
193  }
194  if(movfinishup&&!bUp){
195        accel=accel+(direction*acceleration*(tottimecopy-pow(tottime,1.5f)+.5f));
196        if(tottime>tottimecopy)
197                movfinishup=false;
198  }
199 
200  if(movfinishdown&&!bDown){
201        accel=accel-(direction*acceleration*(tottimecopy-pow(tottime,1.5f)+.5f));
202        if(tottime>tottimecopy)
203                movfinishdown=false;
204  } 
205  //                            **************
206 
207  if( bUp) { accel = accel+(direction*acceleration*pow(tottime,2.0f));movfinishup=true;tottimecopy=tottime;}
208  if( bDown) { accel = accel-(direction*acceleration*pow(tottime,2.0f));movfinishdown=true;tottimecopy=tottime; }
209  if( bLeft ) { accel = accel + (orthDirection*acceleration*pow(tottime,2.0f));
210        if(angle>-40.0f){
211          angle=angle-rottime*40.0f;}
212        movfinishleft=true;
213        tottimecopy=tottime;}
214  if( bRight ) { accel = accel - (orthDirection*acceleration*pow(tottime,2.0f));
215        if(angle<40.0f){
216          angle=angle+rottime*40.0f;}
217          movfinishright=true;
218          tottimecopy=tottime;
219  }
220  if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */}
221  if( bDescend) {/* FIXME */}
222
223  Location* l = get_location();
224 
225  // r(t) = r(0) + v(0)*t + 1/2*a*t^2
226  // r = position
227  // v = velocity
228  // a = acceleration
229
230  /* this the base-speed of the player: determines how fast and how the player follows the track*/
231  l->dist = l->dist + travel_speed * time;
232
233  /* this updates the player position on the track - user interaction */
234  l->pos = l->pos + (accel*time);
235}
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
Note: See TracBrowser for help on using the repository browser.