Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Bin dran die Bewegung smoother zu machen-first try

File size: 3.8 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 
32  /*
33  objectList = glGenLists(1);
34  glNewList (objectList, GL_COMPILE);
35
36  glBegin(GL_TRIANGLES);
37  glColor3f(1,1,1);
38  glVertex3f(0,0,0.5);
39  glVertex3f(-0.5,0,-1);
40  glVertex3f(0.5,0,-1);
41
42  glVertex3f(0,0,0.5);
43  glVertex3f(0,0.5,-1);
44  glVertex3f(0,-0.5,-1);
45  glEnd();
46   
47  glBegin(GL_QUADS);
48  glColor3f(0,0,1);
49  glVertex3f(0.5,0.5,-1);
50  glVertex3f(0.5,-0.5,-1);
51  glVertex3f(-0.5,-0.5,-1);
52  glVertex3f(-0.5,0.5,-1);
53  glEnd();
54 
55  glEndList ();
56  */
57}
58
59Player::~Player () 
60
61{
62}
63
64void Player::post_spawn ()
65{
66  travel_speed = 15.0;
67  velocity = Vector();
68  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
69  bFire = false;
70  acceleration = 10.0;
71  set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
72}
73
74void Player::tick (float time)
75{
76        // movement
77        move (time);
78}
79
80void Player::hit (WorldEntity* weapon, Vector loc)
81{
82}
83
84void Player::destroy ()
85{
86}
87
88void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
89{
90}
91
92void Player::command (Command* cmd)
93{
94  //printf("Player|recieved command [%s]\n", cmd->cmd);
95  tottime=cmd->tottime;
96  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
97  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
98  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
99  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
100  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
101}
102
103void Player::draw ()
104{ 
105  glMatrixMode(GL_MODELVIEW);
106  glLoadIdentity();
107  float matrix[4][4];
108 
109  glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
110  get_placement()->w.matrix (matrix);
111  glMultMatrixf ((float*)matrix);
112 
113  glMatrixMode (GL_MODELVIEW);
114  glRotatef (-90, 0,1,0);
115  obj->draw();
116  //  glCallList (objectList);
117
118 
119 
120  //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
121}
122
123void Player::get_lookat (Location* locbuf)
124{
125        *locbuf = *get_location();
126        //locbuf->dist += 5.0;
127}
128
129void Player::left_world ()
130{
131}
132
133void Player::move (float time)
134{
135  Vector accel(0.0, 0.0, 0.0);
136  /* FIXME: calculating the direction and orthDirection every time_slice is redundant! save it somewhere */
137  Placement *pos = get_placement();
138  /* calculate the direction in which the craft is heading  */
139  Vector direction(0.0, 0.0, 1.0);
140  direction = pos->w.apply(direction);
141  Vector orthDirection(0.0, 0.0, 1.0);
142  orthDirection = orthDirection.cross(direction);
143  if(tottime<1.5f)
144          tottime=tottime+4.0f*time;
145  else
146          tottime=1.5f;
147  if( bUp) { accel = accel+(direction*acceleration*pow(tottime,2.0f)); }
148  if( bDown) { accel = accel-(direction*acceleration*pow(tottime,2.0f)); }
149  if( bLeft ) { accel = accel + (orthDirection*acceleration*pow(tottime,2.0f)); }
150  if( bRight ) { accel = accel - (orthDirection*acceleration*pow(tottime,2.0f));}
151  if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */}
152  if( bDescend) {/* FIXME */}
153
154  Location* l = get_location();
155 
156  // r(t) = r(0) + v(0)*t + 1/2*a*t^2
157  // r = position
158  // v = velocity
159  // a = acceleration
160
161  /* this the base-speed of the player: determines how fast and how the player follows the track*/
162  l->dist = l->dist + travel_speed * time;
163
164  /* this updates the player position on the track - user interaction */
165  l->pos = l->pos + (accel*time);
166}
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Note: See TracBrowser for help on using the repository browser.