Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2624 was 2551, checked in by patrick, 20 years ago

orxonox/trunk: minor changes - enhanced sc controll, fixed uncontrolled rotation effect, added some debug outputs for testing purposes, reformatted some src files from win style but not all

File size: 3.4 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{
[1872]27}
[1853]28
[1896]29Player::~Player () 
[2551]30
[1896]31{
32}
[1853]33
[2190]34void Player::post_spawn ()
[1858]35{
[2551]36        travel_speed = 15.0;
[2190]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)));
[1858]42}
43
[2190]44void Player::tick (float time)
[1872]45{
[2190]46        // movement
47        move (time);
[1872]48}
[1858]49
[2190]50void Player::hit (WorldEntity* weapon, Vector loc)
[1900]51{
52}
53
[2190]54void Player::destroy ()
[1872]55{
56}
57
[2190]58void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
[1872]59{
60}
61
[2190]62void Player::command (Command* cmd)
[1872]63{
[2190]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;
[1872]70}
71
[2190]72void Player::draw ()
73{
[2551]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);
[2190]79  get_placement()->w.matrix (matrix);
80  glMultMatrixf ((float*)matrix);
[2551]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);
[2190]102}
[2036]103
[2190]104void Player::get_lookat (Location* locbuf)
[1896]105{
[2190]106        *locbuf = *get_location();
107        //locbuf->dist += 5.0;
108}
[2036]109
[2190]110void Player::left_world ()
111{
[1872]112}
113
[2190]114void Player::move (float time)
[1858]115{
[2551]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;
[1896]144}
[1879]145
146
[1896]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.