| 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 | /* local coordinate system of space ship at the beginning: |
|---|
| 29 | |
|---|
| 30 | y |
|---|
| 31 | + z |
|---|
| 32 | | + |
|---|
| 33 | | / |
|---|
| 34 | |/ |
|---|
| 35 | x +------O |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include <OgreOverlayManager.h> |
|---|
| 39 | #include <OgreOverlayElement.h> |
|---|
| 40 | #include <OgrePanelOverlayElement.h> |
|---|
| 41 | #include <OgreStringConverter.h> |
|---|
| 42 | #include "RadarOverlayElement.h" |
|---|
| 43 | #include "GraphicsEngine.h" |
|---|
| 44 | |
|---|
| 45 | namespace orxonox |
|---|
| 46 | { |
|---|
| 47 | using namespace Ogre; |
|---|
| 48 | |
|---|
| 49 | RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | RadarOverlayElement::~RadarOverlayElement(){ |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void RadarOverlayElement::initialise(){ |
|---|
| 56 | PanelOverlayElement::initialise(); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ |
|---|
| 60 | count_ = 0; |
|---|
| 61 | dimRel_ = dimRel; |
|---|
| 62 | leftRel_ = leftRel; |
|---|
| 63 | topRel_ = topRel; |
|---|
| 64 | container_ = container; |
|---|
| 65 | |
|---|
| 66 | shipPos_ = Vector3(0.0, 0.0, 0.0); |
|---|
| 67 | targetPos_ = Vector3(1337.0, 0.0, 0.0); |
|---|
| 68 | initialDir_ = Vector3(1.0, 0.0, 0.0); |
|---|
| 69 | currentDir_ = initialDir_; |
|---|
| 70 | initialOrth_ = Vector3(0.0, 0.0, 1.0); |
|---|
| 71 | currentOrth_ = initialOrth_; |
|---|
| 72 | |
|---|
| 73 | setMetricsMode(Ogre::GMM_PIXELS); |
|---|
| 74 | setMaterialName("Orxonox/Radar"); |
|---|
| 75 | resize(); |
|---|
| 76 | |
|---|
| 77 | om = &Ogre::OverlayManager::getSingleton(); |
|---|
| 78 | point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point")); |
|---|
| 79 | point->show(); |
|---|
| 80 | container->addChild(this); |
|---|
| 81 | container->addChild(point); |
|---|
| 82 | point->setMaterialName("Orxonox/RedDot"); |
|---|
| 83 | point->setDimensions(5,5); |
|---|
| 84 | point->setMetricsMode(Ogre::GMM_PIXELS); |
|---|
| 85 | |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void RadarOverlayElement::resize() { |
|---|
| 89 | // if window is resized, we must adapt these... |
|---|
| 90 | windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); |
|---|
| 91 | windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); |
|---|
| 92 | dim_ = dimRel_*windowH_; |
|---|
| 93 | left_ = leftRel_*windowW_-dim_/2; |
|---|
| 94 | top_ = topRel_*windowH_-dim_/2; |
|---|
| 95 | setPosition(left_, top_); |
|---|
| 96 | setDimensions(dim_,dim_); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | void RadarOverlayElement::update() { |
|---|
| 100 | shipPos_ = SpaceShip::instance_s->getPosition(); |
|---|
| 101 | currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni.... |
|---|
| 102 | currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; |
|---|
| 103 | |
|---|
| 104 | radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length())); |
|---|
| 105 | phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length())); |
|---|
| 106 | if((currentDir_.crossProduct(currentOrth_)).dotProduct(targetPos_ - shipPos_) > 0) right_ = true; |
|---|
| 107 | else right_=false; |
|---|
| 108 | |
|---|
| 109 | if (right_){ |
|---|
| 110 | point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2); |
|---|
| 111 | } |
|---|
| 112 | else { |
|---|
| 113 | point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|