Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/track/pilot_node.cc @ 5498

Last change on this file since 5498 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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: ...
16
17   bensch: added comments
18*/
19
20
21#include "pilot_node.h"
22#include "event_handler.h"
23#include "event.h"
24
25using namespace std;
26
27/**
28 *  standard constructor
29*/
30PilotNode::PilotNode ()
31{
32   this->setClassID(CL_PILOT_PARENT, "PilotNode");
33   this->setName("PilotNode");
34
35   travelSpeed = 30.0;
36   velocity = new Vector();
37   bUp = bDown = bLeft = bRight = false;
38}
39
40/**
41 *  standard deconstructor
42*/
43PilotNode::~PilotNode ()
44{
45
46}
47
48/**
49  *  ticks the node
50  * @param time the time about whitch to tick                                           \
51*/
52void PilotNode::tick(float time)
53{
54  this->move(time);
55}
56
57
58/**
59 *  action if player moves
60 * @param time the timeslice since the last frame
61*/
62void PilotNode::move (float time)
63{
64  Vector accel(0.0, 0.0, 0.0);
65  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
66  /* calculate the direction in which the craft is heading  */
67  //Vector direction (1.0, 0.0, 0.0);
68  //direction = this->absDirection.apply (direction);
69  //Vector orthDirection (0.0, 0.0, 1.0);
70  //orthDirection = orthDirection.cross (direction);
71
72   Quaternion q = this->getAbsDir();
73   Vector direction(1,0,0);
74   direction = q.apply(direction);
75
76
77
78   Vector orthDirection(0,0,1);
79   orthDirection = q.apply(orthDirection);
80
81   if( this->bUp)
82     accel = accel+(direction*acceleration);
83   if( this->bDown)
84     accel = accel -(direction*acceleration);
85   if( this->bLeft)
86     accel = accel - (orthDirection*acceleration);
87   if( this->bRight)
88     accel = accel + (orthDirection*acceleration);
89
90   Vector move = accel * time;
91   this->shiftCoor (move);
92
93   Quaternion q1(-M_PI/4 * this->roll/40000.0, Vector(0,0,1));
94   Quaternion q2(-M_PI/4 * this->pitch/30000.0, Vector(0,1,0));
95   //this->shiftDir(q1*q2);
96   this->shiftDir(q1*q2);
97}
98
99/**
100 *  handles events
101 * @param event the event that occured
102*/
103void PilotNode::process( const Event &event)
104{
105  if( event.type == KeyMapper::PEV_UP)
106    {
107      this->bUp = event.bPressed;
108    }
109  else if( event.type == KeyMapper::PEV_DOWN)
110    {
111      this->bDown = event.bPressed;
112    }
113  else if( event.type == KeyMapper::PEV_RIGHT)
114    {
115      this->bRight= event.bPressed;
116    }
117  else if( event.type == KeyMapper::PEV_LEFT)
118    {
119      this->bLeft = event.bPressed;
120    }
121  else if( event.type == EV_MOUSE_MOTION)
122    {
123      this->pitch = event.x - 400;
124      this->roll = event.y - 300;
125    }
126}
Note: See TracBrowser for help on using the repository browser.