Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: doxygen-tags: player.cc/h p_node.cc/h base_entity.h skysphere.cc/h

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