Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/player.cc @ 3209

Last change on this file since 3209 was 3209, checked in by patrick, 19 years ago

orxonox/trunk: resolving segfault on map-change and game-end - yea - major master step

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