Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Bin dran die Bewegung smoother zu machen-first try

File size: 3.8 KB
RevLine 
[1853]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.
[1872]12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
[2190]15   co-programmer: Christian Meyer
[1853]16*/
17
[2036]18#include "player.h"
[2190]19#include "stdincl.h"
20#include "collision.h"
[3155]21#include "command_node.h"
[2036]22
[1856]23using namespace std;
[1853]24
25
[2190]26Player::Player(bool isFree) : WorldEntity(isFree)
27{
[2860]28
[3151]29  obj = new Object ("reaplow.obj");
[3155]30  tottime=0.0f;
31 
[2860]32  /*
[2730]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 ();
[2860]56  */
[1872]57}
[1853]58
[1896]59Player::~Player () 
[2551]60
[1896]61{
62}
[1853]63
[2190]64void Player::post_spawn ()
[1858]65{
[2860]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)));
[1858]72}
73
[2190]74void Player::tick (float time)
[1872]75{
[2190]76        // movement
77        move (time);
[1872]78}
[1858]79
[2190]80void Player::hit (WorldEntity* weapon, Vector loc)
[1900]81{
82}
83
[2190]84void Player::destroy ()
[1872]85{
86}
87
[2190]88void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
[1872]89{
90}
91
[2190]92void Player::command (Command* cmd)
[1872]93{
[2636]94  //printf("Player|recieved command [%s]\n", cmd->cmd);
[3155]95  tottime=cmd->tottime;
[2636]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;
[1872]101}
102
[2190]103void Player::draw ()
[2640]104{ 
[2551]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);
[2190]110  get_placement()->w.matrix (matrix);
111  glMultMatrixf ((float*)matrix);
[2551]112 
[2860]113  glMatrixMode (GL_MODELVIEW);
114  glRotatef (-90, 0,1,0);
115  obj->draw();
116  //  glCallList (objectList);
[2551]117
118 
[2860]119 
[2551]120  //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
[2190]121}
[2036]122
[2190]123void Player::get_lookat (Location* locbuf)
[1896]124{
[2190]125        *locbuf = *get_location();
126        //locbuf->dist += 5.0;
127}
[2036]128
[2190]129void Player::left_world ()
130{
[1872]131}
132
[2190]133void Player::move (float time)
[1858]134{
[2551]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);
[3155]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));}
[2551]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 */
[3155]165  l->pos = l->pos + (accel*time);
[1896]166}
[1879]167
168
[1896]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.