Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/player.cc @ 3544

Last change on this file since 3544 was 3544, checked in by bensch, 19 years ago

orxonox/trunk: now the delete-process is as inteded by c++
virtual ~ClassName extends deletion and deletes also the MasterClass

File size: 4.3 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 "objModel.h"
22
23using namespace std;
24
25/**
26   \brief creates a new Player
27   \param isFree if the player is free
28*/
29Player::Player(bool isFree) : WorldEntity(isFree)
30{
31  this->model = new OBJModel("../data/models/reaplow.obj");
32}
33
34/**
35   \brief destructs the player, deletes alocated memory
36*/
37Player::~Player ()
38{
39  delete this->model;
40}
41
42/**
43   \brief effect that occurs after the player is spawned
44*/
45void Player::postSpawn ()
46{
47  travelSpeed = 15.0;
48  velocity = Vector();
49  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
50  bFire = false;
51  acceleration = 10.0;
52  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
53}
54
55/**
56   \brief the function called for each passing timeSnap
57   \param time The timespan passed since last update
58*/
59void Player::tick (float time)
60{
61  // movement
62  this->move (time);
63}
64
65/**
66   \brief if the player is hit, call this function
67   \param weapon hit by this weapon
68   \param loc ??
69*/
70void Player::hit (WorldEntity* weapon, Vector loc)
71{
72}
73
74
75/**
76    \brief Collision with another Entity has this effect
77    \param other the other colider
78    \param ownhitflags ??
79    \param otherhitflags ??
80*/
81void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
82{
83}
84
85/**
86   \brief The connection to the command node
87   \param cmd the Command unit from witch to map
88
89   here the commands are mapped to the players movement/weaponary
90*/
91void Player::command (Command* cmd)
92{
93  //printf("Player|recieved command [%s]\n", cmd->cmd);
94  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
95  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
96  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
97  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
98  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
99}
100
101/**
102   \brief draws the player after transforming him.
103*/
104void Player::draw ()
105{ 
106  glMatrixMode(GL_MODELVIEW);
107  glPushMatrix();
108  float matrix[4][4];
109 
110  /* translate */
111  glTranslatef (this->getAbsCoor ().x, 
112                this->getAbsCoor ().y, 
113                this->getAbsCoor ().z);
114  /* rotate */
115  this->getAbsDir ().matrix (matrix);
116  glMultMatrixf((float*)matrix);
117 
118  this->model->draw();
119  glPopMatrix();
120}
121
122
123/*PN
124  void Player::getLookat(Location* locbuf)
125  {
126  *locbuf = *getLocation();
127  //locbuf->dist += 5.0;
128  }
129*/
130
131/**
132   \brief the action occuring if the player left the game
133*/
134void Player::leftWorld ()
135{
136}
137
138/**
139   \brief action if player moves
140   \param time the timeslice since the last frame
141*/
142void Player::move (float time)
143{
144  Vector accel(0.0, 0.0, 0.0);
145  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
146  //Placement *pos = getPlacement();
147 
148  /* calculate the direction in which the craft is heading  */
149  Vector direction (1.0, 0.0, 0.0);
150  //direction = this->absDirection.apply (direction);
151  Vector orthDirection (0.0, 0.0, 1.0);
152  //orthDirection = orthDirection.cross (direction);
153
154  if( bUp) { accel = accel+(direction*acceleration); }
155  if( bDown) { accel = accel-(direction*acceleration); }
156  if( bLeft ) { accel = accel - (orthDirection*acceleration); }
157  if( bRight ) { accel = accel + (orthDirection*acceleration); }
158  if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */}
159  if( bDescend) {/* FIXME */} /* \todo up and down player movement */
160
161  //Location* l = getLocation();
162 
163  // r(t) = r(0) + v(0)*t + 1/2*a*t^2
164  // r = position
165  // v = velocity
166  // a = acceleration
167
168  /* this the base-speed of the player: determines how fast and how the player follows the track*/
169  //l->dist = l->dist + travelSpeed * time;
170 
171  //  Vector* shift = new Vector (this->travelSpeed * time, 0, 0);
172  //  this->shiftCoor (shift);
173 
174  /* this updates the player position on the track - user interaction */
175  //l->pos = l->pos + accel*time;
176  Vector move = accel * time;
177  this->shiftCoor (&move);
178}
Note: See TracBrowser for help on using the repository browser.