Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/buerli/src/player.cc @ 3089

Last change on this file since 3089 was 2707, checked in by bensch, 20 years ago

orxonox/branches/buerli: merged back from trunk, with new configure makefile and so forth.

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