Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: moved pilot node to util/track directory

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