Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2289 was 2190, checked in by bensch, 20 years ago

orxonox/trunk: merged and copied all files from branches/chris into trunk. it all seems to be in propper order.

File size: 2.7 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
33void Player::post_spawn ()
34{
35        travel_speed = 10.0;
36        velocity = Vector();
37        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
38        bFire = false;
39        acceleration = 10.0;
40        set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
41}
42
43void Player::tick (float time)
44{
45        // movement
46        move (time);
47}
48
49void Player::hit (WorldEntity* weapon, Vector loc)
50{
51}
52
53void Player::destroy ()
54{
55}
56
57void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
58{
59}
60
61void Player::command (Command* cmd)
62{
63        printf("Player|recieved command [%s]\n", cmd->cmd);
64        if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
65        else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
66        else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
67        else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
68        else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
69}
70
71void Player::draw ()
72{
73        glMatrixMode(GL_MODELVIEW);
74        glLoadIdentity();
75        float matrix[4][4];
76
77        glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
78  get_placement()->w.matrix (matrix);
79  glMultMatrixf ((float*)matrix);
80       
81        glBegin(GL_TRIANGLES);
82        glColor3f(1,0,0);
83        glVertex3f(0,0,0.5);
84        glColor3f(0,1,0);
85        glVertex3f(-0.5,0,-1);
86        glColor3f(0,0,1);
87        glVertex3f(0.5,0,-1);
88        glEnd();
89       
90        printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
91}
92
93void Player::get_lookat (Location* locbuf)
94{
95        *locbuf = *get_location();
96        //locbuf->dist += 5.0;
97}
98
99void Player::left_world ()
100{
101}
102
103void Player::move (float time)
104{
105        float xAccel, yAccel, zAccel;
106        xAccel = yAccel = zAccel = 0;
107        if( bUp) xAccel += acceleration;
108        if( bDown) xAccel -= acceleration;
109        if( bLeft) yAccel += acceleration;
110        if( bRight) yAccel -= acceleration;
111        if( bAscend) zAccel += acceleration;
112        if( bDescend) zAccel -= acceleration;
113       
114        Vector accel( xAccel, yAccel, zAccel);
115       
116        Location* l = get_location();
117       
118        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
119        // r = position
120        // v = velocity
121        // a = acceleration
122       
123        l->pos = l->pos + velocity*time + (accel*(0.5*time*time));
124        l->dist += travel_speed * time;
125       
126        velocity = velocity + (accel * time);
127        printf("Player|velocity %f/%f/%f\n", velocity.x, velocity.y, velocity.z);
128}
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Note: See TracBrowser for help on using the repository browser.