| 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 "event_handler.h" |
|---|
| 21 | #include "event.h" |
|---|
| 22 | |
|---|
| 23 | using namespace std; |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | \brief standard constructor |
|---|
| 28 | |
|---|
| 29 | \todo this constructor is not jet implemented - do it |
|---|
| 30 | */ |
|---|
| 31 | PilotNode::PilotNode () |
|---|
| 32 | { |
|---|
| 33 | this->setClassID(CL_PILOT_PARENT, "PilotNode"); |
|---|
| 34 | |
|---|
| 35 | travelSpeed = 30.0; |
|---|
| 36 | velocity = new Vector(); |
|---|
| 37 | bUp = bDown = bLeft = bRight = false; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | \brief standard deconstructor |
|---|
| 43 | |
|---|
| 44 | \todo this deconstructor is not jet implemented - do it |
|---|
| 45 | */ |
|---|
| 46 | PilotNode::~PilotNode () |
|---|
| 47 | { |
|---|
| 48 | |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | void PilotNode::tick(float time) |
|---|
| 53 | { |
|---|
| 54 | this->move(time); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | \brief action if player moves |
|---|
| 60 | \param time the timeslice since the last frame |
|---|
| 61 | */ |
|---|
| 62 | void 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 | void PilotNode::process( const Event &event) |
|---|
| 101 | { |
|---|
| 102 | if( event.type == KeyMapper::PEV_UP) |
|---|
| 103 | { |
|---|
| 104 | this->bUp = event.bPressed; |
|---|
| 105 | } |
|---|
| 106 | else if( event.type == KeyMapper::PEV_DOWN) |
|---|
| 107 | { |
|---|
| 108 | this->bDown = event.bPressed; |
|---|
| 109 | } |
|---|
| 110 | else if( event.type == KeyMapper::PEV_RIGHT) |
|---|
| 111 | { |
|---|
| 112 | this->bRight= event.bPressed; |
|---|
| 113 | } |
|---|
| 114 | else if( event.type == KeyMapper::PEV_LEFT) |
|---|
| 115 | { |
|---|
| 116 | this->bLeft = event.bPressed; |
|---|
| 117 | } |
|---|
| 118 | else if( event.type == EV_MOUSE_MOTION) |
|---|
| 119 | { |
|---|
| 120 | this->pitch = event.x - 400; |
|---|
| 121 | this->roll = event.y - 300; |
|---|
| 122 | } |
|---|
| 123 | } |
|---|