[1283] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Yuning Chai |
---|
| 23 | * Co-authors: |
---|
[1406] | 24 | * Felix Schulthess |
---|
[1283] | 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[1373] | 28 | #include "OrxonoxStableHeaders.h" |
---|
[1283] | 29 | #include "RadarOverlayElement.h" |
---|
| 30 | |
---|
[1406] | 31 | #include <string.h> |
---|
| 32 | #include <OgreOverlayManager.h> |
---|
| 33 | #include <OgreStringConverter.h> |
---|
| 34 | #include <OgrePanelOverlayElement.h> |
---|
| 35 | |
---|
| 36 | #include "GraphicsEngine.h" |
---|
| 37 | #include "core/Tickable.h" |
---|
| 38 | #include "core/ConsoleCommand.h" |
---|
| 39 | #include "objects/SpaceShip.h" |
---|
| 40 | #include "HUD.h" |
---|
| 41 | |
---|
[1283] | 42 | namespace orxonox |
---|
| 43 | { |
---|
[1353] | 44 | |
---|
[1302] | 45 | using namespace Ogre; |
---|
[1283] | 46 | |
---|
[1406] | 47 | RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){ |
---|
[1302] | 48 | } |
---|
[1283] | 49 | |
---|
[1302] | 50 | RadarOverlayElement::~RadarOverlayElement(){ |
---|
| 51 | } |
---|
[1283] | 52 | |
---|
[1406] | 53 | void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ |
---|
[1339] | 54 | // some initial data |
---|
[1406] | 55 | om = &OverlayManager::getSingleton(); |
---|
[1314] | 56 | dimRel_ = dimRel; |
---|
| 57 | leftRel_ = leftRel; |
---|
| 58 | topRel_ = topRel; |
---|
[1302] | 59 | container_ = container; |
---|
[1283] | 60 | |
---|
[1406] | 61 | setMetricsMode(GMM_PIXELS); |
---|
[1310] | 62 | setMaterialName("Orxonox/Radar"); |
---|
[1314] | 63 | resize(); |
---|
[1339] | 64 | |
---|
[1335] | 65 | container_->addChild(this); |
---|
[1283] | 66 | } |
---|
[1302] | 67 | |
---|
[1314] | 68 | void RadarOverlayElement::resize() { |
---|
| 69 | // if window is resized, we must adapt these... |
---|
| 70 | windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); |
---|
| 71 | windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); |
---|
[1342] | 72 | dim_ = (int) (dimRel_*windowH_); |
---|
| 73 | left_ = (int) (leftRel_*windowW_-dim_/2); |
---|
| 74 | top_ = (int) (topRel_*windowH_-dim_/2); |
---|
[1314] | 75 | setPosition(left_, top_); |
---|
| 76 | setDimensions(dim_,dim_); |
---|
| 77 | } |
---|
| 78 | |
---|
[1302] | 79 | void RadarOverlayElement::update() { |
---|
[1406] | 80 | <<<<<<< .working |
---|
[1384] | 81 | shipPos_ = SpaceShip::getLocalShip()->getPosition(); |
---|
| 82 | currentDir_ = SpaceShip::getLocalShip()->getOrientation()*initialDir_; // according to beni.... |
---|
| 83 | currentOrth_ = SpaceShip::getLocalShip()->getOrientation()*initialOrth_; |
---|
[1343] | 84 | plane = Plane(currentDir_, shipPos_); |
---|
[1310] | 85 | |
---|
[1339] | 86 | RadarObject* ro = firstRadarObject_; |
---|
[1406] | 87 | ======= |
---|
| 88 | shipPos_ = SpaceShip::getLocalShip()->getPosition(); |
---|
| 89 | currentDir_ = SpaceShip::getLocalShip()->getDir(); |
---|
| 90 | currentOrth_ = SpaceShip::getLocalShip()->getOrth(); |
---|
| 91 | RadarObject* ro = HUD::getSingleton().getFirstRadarObject(); |
---|
| 92 | >>>>>>> .merge-right.r1401 |
---|
[1339] | 93 | // iterate through all RadarObjects |
---|
| 94 | while(ro != NULL){ |
---|
[1346] | 95 | // calc position on radar... |
---|
[1406] | 96 | float radius = calcRadius(shipPos_, currentDir_, currentOrth_, ro); |
---|
| 97 | float phi = calcPhi(shipPos_, currentDir_, currentOrth_, ro); |
---|
| 98 | bool right = calcRight(shipPos_, currentDir_, currentOrth_, ro); |
---|
[1346] | 99 | |
---|
| 100 | // set size to fit distance... |
---|
| 101 | float d = (ro->pos_-shipPos_).length(); |
---|
| 102 | if(d<4000) ro->panel_->setDimensions(4,4); |
---|
| 103 | else if(d<8000) ro->panel_->setDimensions(3,3); |
---|
[1354] | 104 | else if(d<16000) ro->panel_->setDimensions(2,2); |
---|
[1346] | 105 | else ro->panel_->setDimensions(1,1); |
---|
| 106 | |
---|
[1406] | 107 | if (right){ |
---|
| 108 | ro->panel_->setPosition(sin(phi)*radius/ |
---|
| 109 | 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); |
---|
[1339] | 110 | } |
---|
| 111 | else { |
---|
[1406] | 112 | ro->panel_->setPosition(-sin(phi)*radius/ |
---|
| 113 | 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); |
---|
[1339] | 114 | } |
---|
| 115 | ro = ro->next; |
---|
| 116 | } |
---|
| 117 | } |
---|
[1310] | 118 | |
---|
[1339] | 119 | void RadarOverlayElement::listObjects(){ |
---|
| 120 | int i = 0; |
---|
[1406] | 121 | RadarObject* ro = HUD::getSingleton().getFirstRadarObject(); |
---|
[1339] | 122 | COUT(3) << "List of RadarObjects:\n"; |
---|
| 123 | // iterate through all Radar Objects |
---|
| 124 | while(ro != NULL) { |
---|
| 125 | COUT(3) << i++ << ": " << ro->pos_ << std::endl; |
---|
| 126 | ro = ro->next; |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
[1406] | 130 | float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ |
---|
| 131 | return(acos((dir.dotProduct(obj->pos_ - pos))/ |
---|
| 132 | ((obj->pos_ - pos).length()*dir.length()))); |
---|
[1356] | 133 | } |
---|
| 134 | |
---|
[1406] | 135 | float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ |
---|
[1343] | 136 | // project difference vector on our plane... |
---|
[1406] | 137 | Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos); |
---|
[1343] | 138 | // ...and find out the angle |
---|
[1406] | 139 | return(acos((orth.dotProduct(proj))/ |
---|
| 140 | (orth.length()*proj.length()))); |
---|
[1339] | 141 | } |
---|
| 142 | |
---|
[1406] | 143 | bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ |
---|
| 144 | if((dir.crossProduct(orth)).dotProduct(obj->pos_ - pos) > 0) |
---|
[1339] | 145 | return true; |
---|
| 146 | else return false; |
---|
| 147 | } |
---|
[1283] | 148 | } |
---|