[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: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include <OgreOverlayManager.h> |
---|
| 29 | #include <OgreOverlayElement.h> |
---|
| 30 | #include <OgrePanelOverlayElement.h> |
---|
| 31 | |
---|
| 32 | #include <OgreStringConverter.h> |
---|
| 33 | #include <math.h> |
---|
| 34 | #include <string.h> |
---|
| 35 | |
---|
| 36 | #include "RadarOverlayElement.h" |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | using namespace Ogre; |
---|
| 42 | |
---|
| 43 | RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){} |
---|
| 44 | |
---|
| 45 | RadarOverlayElement::~RadarOverlayElement(){} |
---|
| 46 | |
---|
| 47 | void RadarOverlayElement::initialise(){ |
---|
| 48 | PanelOverlayElement::initialise(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){ |
---|
[1286] | 52 | |
---|
| 53 | |
---|
[1283] | 54 | |
---|
[1286] | 55 | dirX_ = 1; |
---|
| 56 | dirY_ = 0; |
---|
| 57 | dirZ_ = 0; |
---|
[1283] | 58 | |
---|
[1286] | 59 | ortX_ = 0; |
---|
| 60 | ortY_ = 0; |
---|
| 61 | ortZ_ = 1; |
---|
[1283] | 62 | |
---|
[1286] | 63 | dX_ = 0; |
---|
| 64 | dY_ = 0; |
---|
| 65 | dZ_ = -1; |
---|
[1283] | 66 | |
---|
[1286] | 67 | alpha_ = acos((dirX_*dX_+dirY_*dY_+dirZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(dirX_,2)+pow(dirY_,2)+pow(dirZ_,2)))); |
---|
| 68 | beta_ = acos((ortX_*dX_+ortY_*dY_+ortZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(ortX_,2)+pow(ortY_,2)+pow(ortZ_,2)))); |
---|
| 69 | vecX_ = dirY_*ortZ_ - dirZ_*ortY_; |
---|
| 70 | vecY_ = dirZ_*ortX_ - dirX_*ortZ_; |
---|
| 71 | vecZ_ = dirX_*ortY_ - dirY_*ortX_; |
---|
[1283] | 72 | |
---|
[1286] | 73 | if((vecX_*dX_+vecY_*dY_+vecZ_*dZ_)>0){right_=true;} |
---|
| 74 | else right_=false; |
---|
[1283] | 75 | |
---|
| 76 | setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 77 | setPosition(left,top); |
---|
[1286] | 78 | setDimensions(dim,dim); |
---|
[1283] | 79 | setMaterialName("Orxonox/Radar"); |
---|
| 80 | |
---|
| 81 | Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); |
---|
| 82 | |
---|
| 83 | PanelOverlayElement* point = static_cast<PanelOverlayElement*>(overlayManager.createOverlayElement("Panel", "point")); |
---|
| 84 | point->show(); |
---|
| 85 | |
---|
| 86 | container->addChild(point); |
---|
| 87 | |
---|
[1286] | 88 | if (right_){ |
---|
| 89 | point->setPosition(sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2); |
---|
[1283] | 90 | point->setMaterialName("Orxonox/RedPoint"); |
---|
| 91 | point->setDimensions(5,5); |
---|
| 92 | point->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | else { |
---|
[1286] | 96 | point->setPosition(-sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2); |
---|
[1283] | 97 | point->setMaterialName("Orxonox/RedPoint"); |
---|
| 98 | point->setDimensions(5,5); |
---|
| 99 | point->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 100 | } |
---|
[1286] | 101 | } |
---|
| 102 | |
---|
[1292] | 103 | void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){ |
---|
[1286] | 104 | dirX_=dirX; |
---|
| 105 | dirY_=dirY; |
---|
| 106 | dirZ_=dirZ; |
---|
| 107 | ortX_=ortX; |
---|
| 108 | ortY_=ortY; |
---|
| 109 | ortZ_=ortZ; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
[1283] | 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|