Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 2.8 KB
RevLine 
[4326]1
2
[4597]3/*
[4326]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: ...
[4448]16
17   bensch: added comments
[4326]18*/
19
20
21#include "pilot_node.h"
[4418]22#include "event.h"
[7868]23#include "key_mapper.h"
[4326]24
25
[9869]26ObjectListDefinition(PilotNode);
[4326]27/**
[4836]28 *  standard constructor
[4326]29*/
[4597]30PilotNode::PilotNode ()
[4326]31{
[9869]32  this->registerObject(this, PilotNode::_objectList);
[4597]33   this->setName("PilotNode");
[4422]34
[4438]35   travelSpeed = 30.0;
[4423]36   velocity = new Vector();
37   bUp = bDown = bLeft = bRight = false;
[4326]38}
39
40/**
[4836]41 *  standard deconstructor
[4326]42*/
[4597]43PilotNode::~PilotNode ()
[4326]44{
45
46}
47
[4597]48/**
[4836]49  *  ticks the node
50  * @param time the time about whitch to tick                                           \
[4448]51*/
[4423]52void PilotNode::tick(float time)
[4326]53{
[4423]54  this->move(time);
55}
[4326]56
[4422]57
[4423]58/**
[4836]59 *  action if player moves
60 * @param time the timeslice since the last frame
[4423]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  */
[4438]67  //Vector direction (1.0, 0.0, 0.0);
[4423]68  //direction = this->absDirection.apply (direction);
[4438]69  //Vector orthDirection (0.0, 0.0, 1.0);
[4423]70  //orthDirection = orthDirection.cross (direction);
71
[4438]72   Quaternion q = this->getAbsDir();
73   Vector direction(1,0,0);
74   direction = q.apply(direction);
[4423]75
[4424]76
[4597]77
[4438]78   Vector orthDirection(0,0,1);
79   orthDirection = q.apply(orthDirection);
[4597]80
[4438]81   if( this->bUp)
82     accel = accel+(direction*acceleration);
83   if( this->bDown)
84     accel = accel -(direction*acceleration);
85   if( this->bLeft)
[4597]86     accel = accel - (orthDirection*acceleration);
[4438]87   if( this->bRight)
88     accel = accel + (orthDirection*acceleration);
[4597]89
[4438]90   Vector move = accel * time;
91   this->shiftCoor (move);
[4597]92
[4438]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);
[4326]97}
[4418]98
[4448]99/**
[4836]100 *  handles events
101 * @param event the event that occured
[4448]102*/
[4418]103void PilotNode::process( const Event &event)
104{
[6997]105  if( event.type == KeyMapper::PEV_FORWARD)
[4423]106    {
107      this->bUp = event.bPressed;
108    }
[6997]109  else if( event.type == KeyMapper::PEV_BACKWARD)
[4423]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    {
[4424]123      this->pitch = event.x - 400;
124      this->roll = event.y - 300;
[4423]125    }
[4418]126}
Note: See TracBrowser for help on using the repository browser.