Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: pilot node correction in control speed

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
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 = 30.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   Quaternion q = this->getAbsDir();
74   Vector direction(1,0,0);
75   direction = q.apply(direction);
76
77   
78
79   Vector orthDirection(0,0,1);
80   orthDirection = q.apply(orthDirection);
81   
82   if( this->bUp)
83     accel = accel+(direction*acceleration);
84   if( this->bDown)
85     accel = accel -(direction*acceleration);
86   if( this->bLeft)
87     accel = accel - (orthDirection*acceleration); 
88   if( this->bRight)
89     accel = accel + (orthDirection*acceleration);
90   
91   Vector move = accel * time;
92   this->shiftCoor (move);
93   
94   Quaternion q1(-M_PI/4 * this->roll/40000.0, Vector(0,0,1));
95   Quaternion q2(-M_PI/4 * this->pitch/30000.0, Vector(0,1,0));
96   //this->shiftDir(q1*q2);
97   this->shiftDir(q1*q2);
98}
99
100
101void PilotNode::process( const Event &event)
102{
103  if( event.type == KeyMapper::PEV_UP)
104    {
105      this->bUp = event.bPressed;
106    }
107  else if( event.type == KeyMapper::PEV_DOWN)
108    {
109      this->bDown = event.bPressed;
110    }
111  else if( event.type == KeyMapper::PEV_RIGHT)
112    {
113      this->bRight= event.bPressed;
114    }
115  else if( event.type == KeyMapper::PEV_LEFT)
116    {
117      this->bLeft = event.bPressed;
118    }
119  else if( event.type == EV_MOUSE_MOTION)
120    {
121      this->pitch = event.x - 400;
122      this->roll = event.y - 300;
123    }
124}
Note: See TracBrowser for help on using the repository browser.