Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8019 was 7868, checked in by bensch, 18 years ago

trunk: merge Check in the Event-changes:
r7867 | bensch | 2006-05-26 13:19:46 +0200 (Fri, 26 May 2006) | 1 line

Events better subscribed


r7866 | bensch | 2006-05-26 13:11:10 +0200 (Fri, 26 May 2006) | 1 line

Events are subscribed at the EventListener, and not the EventHandler

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.h"
23#include "key_mapper.h"
24
25
26/**
27 *  standard constructor
28*/
29PilotNode::PilotNode ()
30{
31   this->setClassID(CL_PILOT_PARENT, "PilotNode");
32   this->setName("PilotNode");
33
34   travelSpeed = 30.0;
35   velocity = new Vector();
36   bUp = bDown = bLeft = bRight = false;
37}
38
39/**
40 *  standard deconstructor
41*/
42PilotNode::~PilotNode ()
43{
44
45}
46
47/**
48  *  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 *  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 *  handles events
100 * @param event the event that occured
101*/
102void PilotNode::process( const Event &event)
103{
104  if( event.type == KeyMapper::PEV_FORWARD)
105    {
106      this->bUp = event.bPressed;
107    }
108  else if( event.type == KeyMapper::PEV_BACKWARD)
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.