[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){ |
---|
| 52 | |
---|
| 53 | int dirX, dirY, dirZ; //flying direction |
---|
| 54 | int ortX, ortY, ortZ; //orthogonal direction |
---|
| 55 | int dX, dY, dZ; //distance between main ship and the object |
---|
| 56 | int vecX, vecY, vecZ; //vector product dir X ort |
---|
| 57 | double alpha; //defines the radius in the radar |
---|
| 58 | double beta; //defines the angle in the radar |
---|
| 59 | bool right; //checks whether the object is on the right side (since cos is not bijective) |
---|
| 60 | |
---|
| 61 | dirX = 1; |
---|
| 62 | dirY = 0; |
---|
| 63 | dirZ = 0; |
---|
| 64 | |
---|
| 65 | ortX = 0; |
---|
| 66 | ortY = 0; |
---|
| 67 | ortZ = 1; |
---|
| 68 | |
---|
| 69 | dX = 0; |
---|
| 70 | dY = 2; |
---|
| 71 | dZ = 0; |
---|
| 72 | |
---|
| 73 | 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)))); |
---|
| 74 | 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)))); |
---|
| 75 | vecX = dirY*ortZ - dirZ*ortY; |
---|
| 76 | vecY = dirZ*ortX - dirX*ortZ; |
---|
| 77 | vecZ = dirX*ortY - dirY*ortX; |
---|
| 78 | |
---|
| 79 | if((vecX*dX+vecY*dY+vecZ*dZ)>0){right=true;} |
---|
| 80 | else right=false; |
---|
| 81 | |
---|
| 82 | setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 83 | setPosition(left,top); |
---|
| 84 | setDimensions(dim-15,dim-20); |
---|
| 85 | setMaterialName("Orxonox/Radar"); |
---|
| 86 | |
---|
| 87 | Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); |
---|
| 88 | |
---|
| 89 | PanelOverlayElement* point = static_cast<PanelOverlayElement*>(overlayManager.createOverlayElement("Panel", "point")); |
---|
| 90 | point->show(); |
---|
| 91 | |
---|
| 92 | container->addChild(point); |
---|
| 93 | |
---|
| 94 | if (right){ |
---|
| 95 | point->setPosition(sin(beta)*alpha/3.14*dim/2+dim/2,-cos(beta)*alpha/3.14*dim/2+dim/2); |
---|
| 96 | point->setMaterialName("Orxonox/RedPoint"); |
---|
| 97 | point->setDimensions(5,5); |
---|
| 98 | point->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | else { |
---|
| 102 | point->setPosition(-sin(beta)*alpha/3.14*dim/2+dim/2,-cos(beta)*alpha/3.14*dim/2+dim/2); |
---|
| 103 | point->setMaterialName("Orxonox/RedPoint"); |
---|
| 104 | point->setDimensions(5,5); |
---|
| 105 | point->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | |
---|