Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3279 was 3279, checked in by dave, 19 years ago

branches/old.dave: Die Neigung des Raumschiffes ist jetzt nicht mehr so stark, und jetzt kann man auch 2 Tasten aufs mal drücken, ohne dass das Raumschiffsche jedes mal anhält:)

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