Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2780 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
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"
[2036]21
[1856]22using namespace std;
[1853]23
24
[2190]25Player::Player(bool isFree) : WorldEntity(isFree)
26{
[2730]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
[1872]51}
[1853]52
[1896]53Player::~Player () 
[2551]54
[1896]55{
56}
[1853]57
[2190]58void Player::post_spawn ()
[1858]59{
[2551]60        travel_speed = 15.0;
[2190]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)));
[1858]66}
67
[2190]68void Player::tick (float time)
[1872]69{
[2190]70        // movement
71        move (time);
[1872]72}
[1858]73
[2190]74void Player::hit (WorldEntity* weapon, Vector loc)
[1900]75{
76}
77
[2190]78void Player::destroy ()
[1872]79{
80}
81
[2190]82void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
[1872]83{
84}
85
[2190]86void Player::command (Command* cmd)
[1872]87{
[2636]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;
[1872]94}
95
[2190]96void Player::draw ()
[2640]97{ 
[2551]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);
[2190]103  get_placement()->w.matrix (matrix);
104  glMultMatrixf ((float*)matrix);
[2551]105 
[2730]106  glCallList (objectList);
[2551]107
108 
109  //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
[2190]110}
[2036]111
[2190]112void Player::get_lookat (Location* locbuf)
[1896]113{
[2190]114        *locbuf = *get_location();
115        //locbuf->dist += 5.0;
116}
[2036]117
[2190]118void Player::left_world ()
119{
[1872]120}
121
[2190]122void Player::move (float time)
[1858]123{
[2551]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;
[1896]152}
[1879]153
154
[1896]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.