Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/player.cc @ 2105

Last change on this file since 2105 was 2105, checked in by chris, 20 years ago

orxonox/branches/chris: Port to SDL complete. Everything compiles and the generated executable runs without crashing. Keyboard and mouse handling works. Drawing is messed up, possibly because of my incompetent Rotation class. Hence all you see at them moment is a pitch black screen. I added the makefile I used to compile it since bensch hasn't yet included SDL into the configure script.

File size: 2.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}
28
29Player::~Player () 
30{
31}
32
33void Player::post_spawn ()
34{
35        travel_speed = 1.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        if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
64        else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
65        else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
66        else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
67        else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
68}
69
70void Player::draw ()
71{
72        glMatrixMode(GL_MODELVIEW);
73        float matrix[16];
74  get_placement()->w.glmatrix (matrix);
75  glLoadMatrixf (matrix);
76
77        glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
78       
79        glBegin(GL_TRIANGLES);
80        glColor3f(1,0,0);
81        glVertex3f(0,0,0);
82        glColor3f(0,1,0);
83        glVertex3f(-1,-0.5,0);
84        glColor3f(0,0,1);
85        glVertex3f(-1,+0.5,0);
86        glEnd();
87}
88
89void Player::get_lookat (Location* locbuf)
90{
91        *locbuf = *get_location();
92        locbuf->dist += 5.0;
93}
94
95void Player::left_world ()
96{
97}
98
99void Player::move (float time)
100{
101        float xAccel, yAccel, zAccel;
102        xAccel = yAccel = zAccel = 0;
103        if( bUp) xAccel += acceleration;
104        if( bDown) xAccel -= acceleration;
105        if( bLeft) yAccel += acceleration;
106        if( bRight) yAccel -= acceleration;
107        if( bAscend) zAccel += acceleration;
108        if( bDescend) zAccel -= acceleration;
109       
110        Vector accel( xAccel, yAccel, zAccel);
111       
112        Location* l = get_location();
113       
114        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
115        // r = position
116        // v = velocity
117        // a = acceleration
118       
119        l->pos = l->pos + velocity*time + (accel*(0.5*time*time));
120        l->dist += travel_speed * time;
121       
122        velocity = velocity + (accel * time);
123}
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
Note: See TracBrowser for help on using the repository browser.