Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/world_entities/player.cc @ 3542

Last change on this file since 3542 was 3542, checked in by chris, 19 years ago

orxonox/branches/levelloader: First incarnation of a debugworld loaded from a XML-File in place, compilability in place, all necessary basic loading constuctors in place. Unfortunately the code still generates interferences with the old hardcoded debugworld resulting in SegFault crash.

File size: 5.7 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
25CREATE_FACTORY(Player);
26
27/**
28   \brief creates a new Player
29   \param isFree if the player is free
30*/
31Player::Player(bool isFree) : WorldEntity(isFree)
32{
33
34  this->model = new OBJModel("../data/models/reaplow.obj");
35  /*
36  objectList = glGenLists(1);
37  glNewList (objectList, GL_COMPILE);
38
39  glBegin(GL_TRIANGLES);
40  glColor3f(1,1,1);
41  glVertex3f(0,0,0.5);
42  glVertex3f(-0.5,0,-1);
43  glVertex3f(0.5,0,-1);
44
45  glVertex3f(0,0,0.5);
46  glVertex3f(0,0.5,-1);
47  glVertex3f(0,-0.5,-1);
48  glEnd();
49   
50  glBegin(GL_QUADS);
51  glColor3f(0,0,1);
52  glVertex3f(0.5,0.5,-1);
53  glVertex3f(0.5,-0.5,-1);
54  glVertex3f(-0.5,-0.5,-1);
55  glVertex3f(-0.5,0.5,-1);
56  glEnd();
57 
58  glEndList ();
59  */
60}
61
62/**
63   \brief creates a new Player from Xml Data
64   \param root the xml element containing player data
65   
66   \todo add more parameters to load
67*/
68Player::Player(TiXmlElement* root)
69{
70        char* temp;
71        const char* string;
72        string = grabParameter( root, "name");
73        if( string == NULL)
74        {
75                PRINTF(1)("Player is missing a proper 'name'\n");
76                string = "Unknown";
77                temp = new char[strlen(string + 2)];
78                strcpy( temp, string);
79                this->setName( temp);
80        }
81        else
82        {
83                temp = new char[strlen(string + 2)];
84                strcpy( temp, string);
85                this->setName( temp);
86        }
87       
88        this->model = NULL;
89        string = grabParameter( root, "model");
90        if( string != NULL)
91                this->model = new OBJModel( string);
92        else
93        {
94                PRINTF(1)("Player is missing a proper 'model'\n");
95                this->model = new OBJModel( "../data/models/reaplow.obj");
96        }
97        if( this->model == NULL)
98        {
99                PRINTF(1)("Player model '%s' could not be loaded\n", string);
100        }
101}
102
103/**
104   \brief destructs the player
105*/
106Player::~Player ()
107{
108  delete this->model;
109}
110
111/**
112   \brief effect that occurs after the player is spawned
113*/
114void Player::postSpawn ()
115{
116  travelSpeed = 15.0;
117  velocity = Vector();
118  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
119  bFire = false;
120  acceleration = 10.0;
121  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
122}
123
124/**
125   \brief the function called for each passing timeSnap
126   \param time The timespan passed since last update
127*/
128void Player::tick (float time)
129{
130  // movement
131  this->move (time);
132}
133
134/**
135   \brief if the player is hit, call this function
136   \param weapon hit by this weapon
137   \param loc ??
138*/
139void Player::hit (WorldEntity* weapon, Vector loc)
140{
141}
142
143/**
144   \brief action that happens when the player is destroyed.
145*/
146void Player::destroy ()
147{
148}
149
150/**
151    \brief Collision with another Entity has this effect
152    \param other the other colider
153    \param ownhitflags ??
154    \param otherhitflags ??
155*/
156void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
157{
158}
159
160/**
161   \brief The connection to the command node
162   \param cmd the Command unit from witch to map
163
164   here the commands are mapped to the players movement/weaponary
165*/
166void Player::command (Command* cmd)
167{
168  //printf("Player|recieved command [%s]\n", cmd->cmd);
169  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
170  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
171  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
172  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
173  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
174}
175
176/**
177   \brief draws the player after transforming him.
178*/
179void Player::draw ()
180{ 
181  glMatrixMode(GL_MODELVIEW);
182  glLoadIdentity();
183  float matrix[4][4];
184 
185  /* translate */
186  glTranslatef (this->getAbsCoor ().x, 
187                this->getAbsCoor ().y, 
188                this->getAbsCoor ().z);
189  /* rotate */
190  this->getAbsDir ().matrix (matrix);
191  glMultMatrixf((float*)matrix);
192 
193  glMatrixMode(GL_MODELVIEW);
194  this->model->draw();
195  // glCallList(objectList);
196}
197
198
199/*PN
200  void Player::getLookat(Location* locbuf)
201  {
202  *locbuf = *getLocation();
203  //locbuf->dist += 5.0;
204  }
205*/
206
207/**
208   \brief the action occuring if the player left the game
209*/
210void Player::leftWorld ()
211{
212}
213
214/**
215   \brief action if player moves
216   \param time the timeslice since the last frame
217*/
218void Player::move (float time)
219{
220  Vector accel(0.0, 0.0, 0.0);
221  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
222  //Placement *pos = getPlacement();
223 
224  /* calculate the direction in which the craft is heading  */
225  Vector direction (1.0, 0.0, 0.0);
226  //direction = this->absDirection.apply (direction);
227  Vector orthDirection (0.0, 0.0, 1.0);
228  //orthDirection = orthDirection.cross (direction);
229
230  if( bUp) { accel = accel+(direction*acceleration); }
231  if( bDown) { accel = accel-(direction*acceleration); }
232  if( bLeft ) { accel = accel - (orthDirection*acceleration); }
233  if( bRight ) { accel = accel + (orthDirection*acceleration); }
234  if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */}
235  if( bDescend) {/* FIXME */} /* \todo up and down player movement */
236
237  //Location* l = getLocation();
238 
239  // r(t) = r(0) + v(0)*t + 1/2*a*t^2
240  // r = position
241  // v = velocity
242  // a = acceleration
243
244  /* this the base-speed of the player: determines how fast and how the player follows the track*/
245  //l->dist = l->dist + travelSpeed * time;
246 
247  Vector* shift = new Vector (this->travelSpeed * time, 0, 0);
248  this->shiftCoor (shift);
249 
250  /* this updates the player position on the track - user interaction */
251  //l->pos = l->pos + accel*time;
252  Vector move = accel * time;
253  this->shiftCoor (&move);
254}
Note: See TracBrowser for help on using the repository browser.