Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2751 was 2730, checked in by bensch, 20 years ago

orxonox/trunk: implemented a glList for player:

this is for testing purposes only, and will be set correctly, as soon as the Phyisics engine is up and running.
3 things have been done:


  1. added GLuint objectList to the player class.
  2. moved the mesh-definition of the player-object to the Player::Player, and packed into a list which resides to objectList.
  3. glCallList added into Player::Draw()

Patrick: i hope you don't mind this slight change in the trunk

File size: 3.5 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  objectList = glGenLists(1);
28  glNewList (objectList, GL_COMPILE);
29
30  glBegin(GL_TRIANGLES);
31  glColor3f(1,1,1);
32  glVertex3f(0,0,0.5);
33  glVertex3f(-0.5,0,-1);
34  glVertex3f(0.5,0,-1);
35
36  glVertex3f(0,0,0.5);
37  glVertex3f(0,0.5,-1);
38  glVertex3f(0,-0.5,-1);
39  glEnd();
40   
41  glBegin(GL_QUADS);
42  glColor3f(0,0,1);
43  glVertex3f(0.5,0.5,-1);
44  glVertex3f(0.5,-0.5,-1);
45  glVertex3f(-0.5,-0.5,-1);
46  glVertex3f(-0.5,0.5,-1);
47  glEnd();
48 
49  glEndList ();
50
51}
52
53Player::~Player () 
54
55{
56}
57
58void Player::post_spawn ()
59{
60        travel_speed = 15.0;
61        velocity = Vector();
62        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
63        bFire = false;
64        acceleration = 10.0;
65        set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
66}
67
68void Player::tick (float time)
69{
70        // movement
71        move (time);
72}
73
74void Player::hit (WorldEntity* weapon, Vector loc)
75{
76}
77
78void Player::destroy ()
79{
80}
81
82void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
83{
84}
85
86void Player::command (Command* cmd)
87{
88  //printf("Player|recieved command [%s]\n", cmd->cmd);
89  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
90  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
91  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
92  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
93  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
94}
95
96void Player::draw ()
97{ 
98  glMatrixMode(GL_MODELVIEW);
99  glLoadIdentity();
100  float matrix[4][4];
101 
102  glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
103  get_placement()->w.matrix (matrix);
104  glMultMatrixf ((float*)matrix);
105 
106  glCallList (objectList);
107
108 
109  //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
110}
111
112void Player::get_lookat (Location* locbuf)
113{
114        *locbuf = *get_location();
115        //locbuf->dist += 5.0;
116}
117
118void Player::left_world ()
119{
120}
121
122void Player::move (float time)
123{
124  Vector accel(0.0, 0.0, 0.0);
125  /* FIXME: calculating the direction and orthDirection every time_slice is redundant! save it somewhere */
126  Placement *pos = get_placement();
127  /* calculate the direction in which the craft is heading  */
128  Vector direction(0.0, 0.0, 1.0);
129  direction = pos->w.apply(direction);
130  Vector orthDirection(0.0, 0.0, 1.0);
131  orthDirection = orthDirection.cross(direction);
132
133  if( bUp) { accel = accel+(direction*acceleration); }
134  if( bDown) { accel = accel-(direction*acceleration); }
135  if( bLeft ) { accel = accel + (orthDirection*acceleration); }
136  if( bRight ) { accel = accel - (orthDirection*acceleration); }
137  if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */}
138  if( bDescend) {/* FIXME */}
139
140  Location* l = get_location();
141 
142  // r(t) = r(0) + v(0)*t + 1/2*a*t^2
143  // r = position
144  // v = velocity
145  // a = acceleration
146
147  /* this the base-speed of the player: determines how fast and how the player follows the track*/
148  l->dist = l->dist + travel_speed * time;
149
150  /* this updates the player position on the track - user interaction */
151  l->pos = l->pos + accel*time;
152}
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Note: See TracBrowser for help on using the repository browser.