Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: better ModelView-matrix transformations

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
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   \brief action that happens when the player is destroyed.
76*/
77void Player::destroy ()
78{
79}
80
81/**
82    \brief Collision with another Entity has this effect
83    \param other the other colider
84    \param ownhitflags ??
85    \param otherhitflags ??
86*/
87void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
88{
89}
90
91/**
92   \brief The connection to the command node
93   \param cmd the Command unit from witch to map
94
95   here the commands are mapped to the players movement/weaponary
96*/
97void Player::command (Command* cmd)
98{
99  //printf("Player|recieved command [%s]\n", cmd->cmd);
100  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
101  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
102  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
103  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
104  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
105}
106
107/**
108   \brief draws the player after transforming him.
109*/
110void Player::draw ()
111{ 
112  glMatrixMode(GL_MODELVIEW);
113  glPushMatrix();
114  float matrix[4][4];
115 
116  /* translate */
117  glTranslatef (this->getAbsCoor ().x, 
118                this->getAbsCoor ().y, 
119                this->getAbsCoor ().z);
120  /* rotate */
121  this->getAbsDir ().matrix (matrix);
122  glMultMatrixf((float*)matrix);
123 
124  this->model->draw();
125  glPopMatrix();
126}
127
128
129/*PN
130  void Player::getLookat(Location* locbuf)
131  {
132  *locbuf = *getLocation();
133  //locbuf->dist += 5.0;
134  }
135*/
136
137/**
138   \brief the action occuring if the player left the game
139*/
140void Player::leftWorld ()
141{
142}
143
144/**
145   \brief action if player moves
146   \param time the timeslice since the last frame
147*/
148void Player::move (float time)
149{
150  Vector accel(0.0, 0.0, 0.0);
151  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
152  //Placement *pos = getPlacement();
153 
154  /* calculate the direction in which the craft is heading  */
155  Vector direction (1.0, 0.0, 0.0);
156  //direction = this->absDirection.apply (direction);
157  Vector orthDirection (0.0, 0.0, 1.0);
158  //orthDirection = orthDirection.cross (direction);
159
160  if( bUp) { accel = accel+(direction*acceleration); }
161  if( bDown) { accel = accel-(direction*acceleration); }
162  if( bLeft ) { accel = accel - (orthDirection*acceleration); }
163  if( bRight ) { accel = accel + (orthDirection*acceleration); }
164  if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */}
165  if( bDescend) {/* FIXME */} /* \todo up and down player movement */
166
167  //Location* l = getLocation();
168 
169  // r(t) = r(0) + v(0)*t + 1/2*a*t^2
170  // r = position
171  // v = velocity
172  // a = acceleration
173
174  /* this the base-speed of the player: determines how fast and how the player follows the track*/
175  //l->dist = l->dist + travelSpeed * time;
176 
177  Vector* shift = new Vector (this->travelSpeed * time, 0, 0);
178  this->shiftCoor (shift);
179 
180  /* this updates the player position on the track - user interaction */
181  //l->pos = l->pos + accel*time;
182  Vector move = accel * time;
183  this->shiftCoor (&move);
184}
Note: See TracBrowser for help on using the repository browser.