Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/parenting/src/player.cc @ 3307

Last change on this file since 3307 was 3307, checked in by patrick, 20 years ago

orxonox/branches/parenting: now parenting works visibly good :) meaning, that the old abilities have been reimplemented and are working now. turned coord system again to the old one to be able to enjoy the terrific green lands of orxonox

File size: 3.9 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
22using namespace std;
23
24
25Player::Player(bool isFree) : WorldEntity(isFree)
26{
27
28  this->obj = new Object("reaplow.obj");
29  /*
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 ();
53  */
54}
55
56Player::~Player ()
57{
58  delete this->obj;
59}
60
61void Player::postSpawn ()
62{
63  travelSpeed = 15.0;
64  velocity = Vector();
65  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
66  bFire = false;
67  acceleration = 10.0;
68  setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
69}
70
71void Player::tick (float time)
72{
73  // movement
74  this->move (time);
75}
76
77void Player::hit (WorldEntity* weapon, Vector loc)
78{
79}
80
81void Player::destroy ()
82{
83}
84
85void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
86{
87}
88
89void Player::command (Command* cmd)
90{
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;
97}
98
99void Player::draw ()
100{ 
101  glMatrixMode(GL_MODELVIEW);
102  glLoadIdentity();
103  float matrix[4][4];
104 
105  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
106  printf("Player::draw() - (%f, %f, %f)\n", this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
107  //rotate
108  this->getAbsDir ().matrix (matrix);
109  glMultMatrixf((float*)matrix);
110 
111  glMatrixMode(GL_MODELVIEW);
112  obj->draw();
113  // glCallList(objectList);
114}
115
116
117/*PN
118void Player::getLookat(Location* locbuf)
119{
120  *locbuf = *getLocation();
121  //locbuf->dist += 5.0;
122}
123*/
124
125void Player::leftWorld ()
126{
127}
128
129void Player::move (float time)
130{
131  Vector accel(0.0, 0.0, 0.0);
132  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
133  //Placement *pos = getPlacement();
134 
135  /* calculate the direction in which the craft is heading  */
136  Vector direction (1.0, 0.0, 0.0);
137  //direction = this->absDirection.apply (direction);
138  Vector orthDirection (0.0, 1.0, 0.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 */} /* \todo up and down player movement */
147
148  //Location* l = getLocation();
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 + travelSpeed * time;
157 
158  Vector* shift = new Vector (this->travelSpeed * time, 0, 0);
159  this->shiftCoor (shift);
160 
161  /* this updates the player position on the track - user interaction */
162  //l->pos = l->pos + accel*time;
163  Vector move = accel * time;
164  this->shiftCoor (&move);
165}
Note: See TracBrowser for help on using the repository browser.