Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/coord/pilot_node.cc @ 4423

Last change on this file since 4423 was 4423, checked in by patrick, 19 years ago

orxonox/trunk: space craft can be controled via keys, nothing new yet

File size: 2.3 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: ...
16*/
17
18
19#include "pilot_node.h"
20#include "command_node.h"
21#include "event_handler.h"
22#include "event.h"
23
24using namespace std;
25
26
27/**
28   \brief standard constructor
29
30   \todo this constructor is not jet implemented - do it
31*/
32PilotNode::PilotNode () 
33{
34   this->setClassID(CL_PILOT_PARENT, "PilotNode");
35
36   travelSpeed = 60.0;
37   velocity = new Vector();
38   bUp = bDown = bLeft = bRight = false;
39}
40
41
42/**
43   \brief standard deconstructor
44
45   \todo this deconstructor is not jet implemented - do it
46*/
47PilotNode::~PilotNode () 
48{
49
50}
51
52
53void PilotNode::tick(float time)
54{
55  this->move(time);
56}
57
58
59/**
60   \brief action if player moves
61   \param time the timeslice since the last frame
62*/
63void PilotNode::move (float time)
64{
65  Vector accel(0.0, 0.0, 0.0);
66  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
67  /* calculate the direction in which the craft is heading  */
68  Vector direction (1.0, 0.0, 0.0);
69  //direction = this->absDirection.apply (direction);
70  Vector orthDirection (0.0, 0.0, 1.0);
71  //orthDirection = orthDirection.cross (direction);
72
73  if( this->bUp)
74    accel = accel+(direction*acceleration);
75  if( this->bDown)
76    accel = accel -(direction*acceleration);
77  if( this->bLeft)
78    accel = accel - (orthDirection*acceleration); 
79  if( this->bRight)
80    accel = accel + (orthDirection*acceleration);
81
82  Vector move = accel * time;
83  this->shiftCoor (move);
84}
85
86void PilotNode::process( const Event &event)
87{
88  if( event.type == KeyMapper::PEV_UP)
89    {
90      this->bUp = event.bPressed;
91    }
92  else if( event.type == KeyMapper::PEV_DOWN)
93    {
94      this->bDown = event.bPressed;
95    }
96  else if( event.type == KeyMapper::PEV_RIGHT)
97    {
98      this->bRight= event.bPressed;
99    }
100  else if( event.type == KeyMapper::PEV_LEFT)
101    {
102      this->bLeft = event.bPressed;
103    }
104  else if( event.type == EV_MOUSE_MOTION)
105    {
106      PRINTF(0)("Mouse moved by %d,%d to (%d,%d)\n", event.xRel, event.yRel,
107            event.x, event.y);
108    }
109}
Note: See TracBrowser for help on using the repository browser.