Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc @ 1302

Last change on this file since 1302 was 1302, checked in by FelixSchulthess, 16 years ago

using vectors instead of integers now

File size: 3.7 KB
Line 
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
44namespace 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_ = 0;
63        container_ = container;
64
65        shipPos_ = Vector3(0.0, 0.0, 0.0);
66        targetPos_ = Vector3(42.0, 42.0, 0.0);
67        initialDir_ = Vector3(0.0, 0.0, 1.0);
68        currentDir_ = initialDir_;
69        initialOrth_ = Vector3(0.0, 1.0, 0.0);
70        currentOrth_ = initialOrth_;
71
72        alpha_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
73        beta_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
74        vec_ = currentDir_.crossProduct(currentOrth_);
75
76        if(vec_.dotProduct(targetPos_ - shipPos_) > 0)
77            right_ = true;
78        else
79            right_=false;
80
81        setMetricsMode(Ogre::GMM_PIXELS);
82        setPosition(left,top);
83        setDimensions(dim_,dim_);
84        setMaterialName("Orxonox/Radar");
85
86        om = &Ogre::OverlayManager::getSingleton();
87        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
88        point->show();
89        container->addChild(point);
90
91        if (right_){
92            point->setPosition(sin(beta_)*alpha_/3.5*dim_/2+dim_/2+left-2,-cos(beta_)*alpha_/3.5*dim_/2+dim_/2+top-2);
93            point->setMaterialName("Orxonox/RedPoint");
94            point->setDimensions(5,5);
95            point->setMetricsMode(Ogre::GMM_PIXELS);
96        }
97
98        else {
99            point->setPosition(-sin(beta_)*alpha_/3.5*dim_/2+dim_/2+left-2,-cos(beta_)*alpha_/3.5*dim_/2+dim_/2+top-2);
100            point->setMaterialName("Orxonox/RedPoint");
101            point->setDimensions(5,5);
102            point->setMetricsMode(Ogre::GMM_PIXELS);
103        }
104    }
105
106//    void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
107//        dirX_=dirX;
108//        dirY_=dirY;
109//        dirZ_=dirZ;
110//        ortX_=ortX;
111//        ortY_=ortY;
112//        ortZ_=ortZ;
113//    }
114
115    void RadarOverlayElement::update() {
116        shipPos_ = SpaceShip::instance_s->getPosition();
117        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni....
118    }
119
120}
121
122
123
Note: See TracBrowser for help on using the repository browser.