[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 | |
---|
| 26 | /** |
---|
[4836] | 27 | * standard constructor |
---|
[4326] | 28 | */ |
---|
[4597] | 29 | PilotNode::PilotNode () |
---|
[4326] | 30 | { |
---|
| 31 | this->setClassID(CL_PILOT_PARENT, "PilotNode"); |
---|
[4597] | 32 | this->setName("PilotNode"); |
---|
[4422] | 33 | |
---|
[4438] | 34 | travelSpeed = 30.0; |
---|
[4423] | 35 | velocity = new Vector(); |
---|
| 36 | bUp = bDown = bLeft = bRight = false; |
---|
[4326] | 37 | } |
---|
| 38 | |
---|
| 39 | /** |
---|
[4836] | 40 | * standard deconstructor |
---|
[4326] | 41 | */ |
---|
[4597] | 42 | PilotNode::~PilotNode () |
---|
[4326] | 43 | { |
---|
| 44 | |
---|
| 45 | } |
---|
| 46 | |
---|
[4597] | 47 | /** |
---|
[4836] | 48 | * ticks the node |
---|
| 49 | * @param time the time about whitch to tick \ |
---|
[4448] | 50 | */ |
---|
[4423] | 51 | void PilotNode::tick(float time) |
---|
[4326] | 52 | { |
---|
[4423] | 53 | this->move(time); |
---|
| 54 | } |
---|
[4326] | 55 | |
---|
[4422] | 56 | |
---|
[4423] | 57 | /** |
---|
[4836] | 58 | * action if player moves |
---|
| 59 | * @param time the timeslice since the last frame |
---|
[4423] | 60 | */ |
---|
| 61 | void 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 */ |
---|
[4438] | 66 | //Vector direction (1.0, 0.0, 0.0); |
---|
[4423] | 67 | //direction = this->absDirection.apply (direction); |
---|
[4438] | 68 | //Vector orthDirection (0.0, 0.0, 1.0); |
---|
[4423] | 69 | //orthDirection = orthDirection.cross (direction); |
---|
| 70 | |
---|
[4438] | 71 | Quaternion q = this->getAbsDir(); |
---|
| 72 | Vector direction(1,0,0); |
---|
| 73 | direction = q.apply(direction); |
---|
[4423] | 74 | |
---|
[4424] | 75 | |
---|
[4597] | 76 | |
---|
[4438] | 77 | Vector orthDirection(0,0,1); |
---|
| 78 | orthDirection = q.apply(orthDirection); |
---|
[4597] | 79 | |
---|
[4438] | 80 | if( this->bUp) |
---|
| 81 | accel = accel+(direction*acceleration); |
---|
| 82 | if( this->bDown) |
---|
| 83 | accel = accel -(direction*acceleration); |
---|
| 84 | if( this->bLeft) |
---|
[4597] | 85 | accel = accel - (orthDirection*acceleration); |
---|
[4438] | 86 | if( this->bRight) |
---|
| 87 | accel = accel + (orthDirection*acceleration); |
---|
[4597] | 88 | |
---|
[4438] | 89 | Vector move = accel * time; |
---|
| 90 | this->shiftCoor (move); |
---|
[4597] | 91 | |
---|
[4438] | 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); |
---|
[4326] | 96 | } |
---|
[4418] | 97 | |
---|
[4448] | 98 | /** |
---|
[4836] | 99 | * handles events |
---|
| 100 | * @param event the event that occured |
---|
[4448] | 101 | */ |
---|
[4418] | 102 | void PilotNode::process( const Event &event) |
---|
| 103 | { |
---|
[6997] | 104 | if( event.type == KeyMapper::PEV_FORWARD) |
---|
[4423] | 105 | { |
---|
| 106 | this->bUp = event.bPressed; |
---|
| 107 | } |
---|
[6997] | 108 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[4423] | 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 | { |
---|
[4424] | 122 | this->pitch = event.x - 400; |
---|
| 123 | this->roll = event.y - 300; |
---|
[4423] | 124 | } |
---|
[4418] | 125 | } |
---|