Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: very fun effect when using the mouse to drive through debug level1, will be fixed…

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: ...
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  Quaternion q1(M_PI/4 * this->pitch/400.0, Vector(1,0,0));
86  this->shiftDir(q1);
87}
88
89
90void PilotNode::process( const Event &event)
91{
92  if( event.type == KeyMapper::PEV_UP)
93    {
94      this->bUp = event.bPressed;
95    }
96  else if( event.type == KeyMapper::PEV_DOWN)
97    {
98      this->bDown = event.bPressed;
99    }
100  else if( event.type == KeyMapper::PEV_RIGHT)
101    {
102      this->bRight= event.bPressed;
103    }
104  else if( event.type == KeyMapper::PEV_LEFT)
105    {
106      this->bLeft = event.bPressed;
107    }
108  else if( event.type == EV_MOUSE_MOTION)
109    {
110      PRINTF(0)("Mouse moved by %d,%d to (%d,%d)\n", event.xRel, event.yRel,
111            event.x, event.y);
112      this->pitch = event.x - 400;
113      this->roll = event.y - 300;
114    }
115}
Note: See TracBrowser for help on using the repository browser.