Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3350 was 3280, checked in by dave, 20 years ago

branches/old.dave: Nochmal das gleiche, Raumschiff sollte drehen, aber nur 20°

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