Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2968 was 2968, checked in by bensch, 20 years ago

orxonox/trunk/importer: nicer configure.ac

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