| 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 | |
|---|
| 44 | namespace orxonox |
|---|
| 45 | { |
|---|
| 46 | using namespace Ogre; |
|---|
| 47 | |
|---|
| 48 | RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | RadarOverlayElement::~RadarOverlayElement(){ |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void RadarOverlayElement::initialise(){ |
|---|
| 55 | PanelOverlayElement::initialise(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){ |
|---|
| 59 | dim_ = dim; |
|---|
| 60 | left_ = left; |
|---|
| 61 | top_ = top; |
|---|
| 62 | count_ = 100; |
|---|
| 63 | container_ = container; |
|---|
| 64 | |
|---|
| 65 | shipPos_ = Vector3(0.0, 0.0, 0.0); |
|---|
| 66 | targetPos_ = Vector3(42.0, 0.0, 0.0); |
|---|
| 67 | initialDir_ = Vector3(1.0, 0.0, 0.0); |
|---|
| 68 | currentDir_ = initialDir_; |
|---|
| 69 | initialOrth_ = Vector3(0.0, 0.0, 1.0); |
|---|
| 70 | currentOrth_ = initialOrth_; |
|---|
| 71 | |
|---|
| 72 | setMetricsMode(Ogre::GMM_PIXELS); |
|---|
| 73 | setPosition(left,top); |
|---|
| 74 | setDimensions(dim_,dim_); |
|---|
| 75 | setMaterialName("Orxonox/Radar"); |
|---|
| 76 | |
|---|
| 77 | om = &Ogre::OverlayManager::getSingleton(); |
|---|
| 78 | point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point")); |
|---|
| 79 | point->show(); |
|---|
| 80 | container->addChild(point); |
|---|
| 81 | point->setMaterialName("Orxonox/RedPoint"); |
|---|
| 82 | point->setDimensions(5,5); |
|---|
| 83 | point->setMetricsMode(Ogre::GMM_PIXELS); |
|---|
| 84 | |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | // void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){ |
|---|
| 88 | // dirX_=dirX; |
|---|
| 89 | // dirY_=dirY; |
|---|
| 90 | // dirZ_=dirZ; |
|---|
| 91 | // ortX_=ortX; |
|---|
| 92 | // ortY_=ortY; |
|---|
| 93 | // ortZ_=ortZ; |
|---|
| 94 | // } |
|---|
| 95 | |
|---|
| 96 | void RadarOverlayElement::update() { |
|---|
| 97 | if(count_++ >= 100) { // for testing purposes |
|---|
| 98 | count_ = 0; |
|---|
| 99 | COUT(3) << "pos: " << shipPos_ << std::endl; |
|---|
| 100 | COUT(3) << "dir: " << currentDir_ << std::endl; |
|---|
| 101 | COUT(3) << "orth: " << currentOrth_ << std::endl << std::endl; |
|---|
| 102 | } |
|---|
| 103 | shipPos_ = SpaceShip::instance_s->getPosition(); |
|---|
| 104 | currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni.... |
|---|
| 105 | currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; |
|---|
| 106 | |
|---|
| 107 | radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length())); |
|---|
| 108 | phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length())); |
|---|
| 109 | vec_ = currentDir_.crossProduct(currentOrth_); |
|---|
| 110 | if(vec_.dotProduct(targetPos_ - shipPos_) > 0) right_ = true; |
|---|
| 111 | else right_=false; |
|---|
| 112 | |
|---|
| 113 | if (right_){ |
|---|
| 114 | point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2); |
|---|
| 115 | } |
|---|
| 116 | else { |
|---|
| 117 | point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|