Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1400


Ignore:
Timestamp:
May 24, 2008, 12:24:30 AM (16 years ago)
Author:
FelixSchulthess
Message:

moved to spaceship what belonged there

Location:
code/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/bin/levels/sample.oxw

    r1388 r1400  
    1212<Skybox src="Orxonox/Starbox" />
    1313<SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="0,0,0" mesh="assff.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
    14 <Model position="2000,1000,1000" scale="10" mesh="tomato.mesh" yawpitchroll="-40,30,0" rotationAxis="1,0,0" rotationRate="-30"/>
    15 <Model position="0,4200,0" scale="10" mesh="tomato.mesh" yawpitchroll="-50,60,0" rotationAxis="1,0,0" rotationRate="-30"/>
    16 <Model position="0,0,6800" scale="10" mesh="tomato.mesh" yawpitchroll="-50,-30,0" rotationAxis="1,0,0" rotationRate="-30"/>
     14<Model position="2000,0,0" scale="10" mesh="tomato.mesh" yawpitchroll="-40,30,0" rotationAxis="1,0,0" rotationRate="-30"/>
     15<Model position="0,2000,0" scale="10" mesh="tomato.mesh" yawpitchroll="-50,60,0" rotationAxis="1,0,0" rotationRate="-30"/>
     16<Model position="0,0,2000" scale="10" mesh="tomato.mesh" yawpitchroll="-50,-30,0" rotationAxis="1,0,0" rotationRate="-30"/>
    1717<NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
    1818<NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
  • code/trunk/src/orxonox/hud/HUD.cc

    r1399 r1400  
    102102
    103103        radar->init(0.5, 0.9, 0.2, container);
    104         addRadarObject(Vector3(2000.0, 1000.0, 1000.0));
    105         addRadarObject(Vector3(0.0, 4000.0, 0.0));
    106         addRadarObject(Vector3(0.0, 0.0, 6800.0));
     104        addRadarObject(Vector3(2000.0, 0.0, 0.0));
     105        addRadarObject(Vector3(0.0, 2000.0, 0.0));
     106        addRadarObject(Vector3(0.0, 0.0, 2000.0));
    107107    }
    108108
  • code/trunk/src/orxonox/hud/Navigation.cc

    r1399 r1400  
    3030#include <OgreTextAreaOverlayElement.h>
    3131#include <OgreStringConverter.h>
    32 #include <OgreMatrix4.h>
    3332#include <GraphicsEngine.h>
    34 #include "core/Iterator.h"
    3533#include "objects/SpaceShip.h"
    3634#include "objects/CameraHandler.h"
     
    5654    void Navigation::init(){
    5755                om = &OverlayManager::getSingleton();
    58 //              for (Iterator<Model> it = ObjectList<Model>::begin(); it; ++it)
    59 //              {
    60 //            if(it->getPosition() == Vector(2000.0, 1000.0, 1000.0)){
    61 //                COUT(3) << "TARGET FOUND\n";
    62 //
    63 //
    64 //        }
    65                 cam_ = NULL;
     56                navCam_ = NULL;
    6657        // create nav text
    6758        navText_ = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "navText"));
     
    8677        void Navigation::update(){
    8778        if(focus_ == NULL) return;
    88         shipPos_ = SpaceShip::getLocalShip()->getPosition();
     79        navCamPos_ = SpaceShip::getLocalShip()->getPosition();
     80        currentDir_ = SpaceShip::getLocalShip()->getDir();
     81                currentOrth_ = SpaceShip::getLocalShip()->getOrth();
     82
    8983        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
    9084        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     
    9791        navText_->setCaption(Ogre::StringConverter::toString(dist));
    9892
    99         if(cam_ == NULL) cam_ = SpaceShip::getLocalShip()->getCamera()->cam_;
     93        if(navCam_ == NULL) navCam_ = SpaceShip::getLocalShip()->getCamera()->cam_;
    10094        Vector3 pos = focus_->pos_;
    10195        // transform to screen coordinates
    102         pos = cam_->getProjectionMatrix()*cam_->getViewMatrix()*pos;
     96        pos = navCam_->getProjectionMatrix()*navCam_->getViewMatrix()*pos;
    10397        float xPosRel = 0.5*pos.x+0.5;
    10498        float yPosRel = 1-(0.5*pos.y+0.5);
     
    108102        bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1);
    109103        // if object is behind us, it is out of view anyway:
    110         if(!outOfView && focus_->radius_>3.14/2) outOfView = true;
     104        if(!outOfView && RadarOverlayElement::calcRadius(navCamPos_, currentDir_, currentOrth_, focus_)>3.14/2) outOfView = true;
    111105
    112106        if(outOfView){
     
    117111            // from the angle we find out where to draw the marker
    118112            // and which of the four arrows to take
    119             float phi = focus_->phi_;
    120             if(focus_->right_){
    121                 if(phi<phiUpRight){
     113            float phiNav = RadarOverlayElement::calcPhi(navCamPos_, currentDir_, currentOrth_, focus_);
     114            bool right = RadarOverlayElement::calcRight(navCamPos_, currentDir_, currentOrth_, focus_);
     115            if(right){
     116                if(phiNav<phiUpRight){
    122117                    // arrow up
    123                     navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
     118                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, 0);
    124119                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    125120                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
    126121                    navText_->setTop(navMarker_->getHeight());
    127122                }
    128                 else if(phi>3.14-phiUpRight){
     123                else if(phiNav>3.14-phiUpRight){
    129124                    // arrow down
    130                     navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
     125                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
    131126                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    132127                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     
    135130                else {
    136131                    // arrow right
    137                     navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
     132                    navMarker_->setPosition(windowW_-16, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    138133                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
    139134                    navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth());
     
    142137            }
    143138            else{
    144                 if(phi<phiUpRight) {
     139                if(phiNav<phiUpRight) {
    145140                    // arrow up
    146                     navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
     141                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
    147142                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    148143                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
    149144                    navText_->setTop(navMarker_->getHeight());
    150145                }
    151                 else if(phi>3.14-phiUpRight) {
     146                else if(phiNav>3.14-phiUpRight) {
    152147                    // arrow down
    153                     navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
     148                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
    154149                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    155150                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     
    158153                else {
    159154                    // arrow left
    160                     navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
     155                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    161156                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
    162157                    navText_->setLeft(navMarker_->getWidth());
     
    197192        float Navigation::getDist2Focus(){
    198193            if(focus_ == NULL) return(0.0);
    199             return((focus_->pos_-shipPos_).length());
     194            return((focus_->pos_-SpaceShip::getLocalShip()->getPosition()).length());
    200195        }
    201196}
  • code/trunk/src/orxonox/hud/Navigation.h

    r1399 r1400  
    3131#include <OgrePrerequisites.h>
    3232#include "../OrxonoxPrereqs.h"
     33#include <OgrePlane.h>
    3334#include "util/Math.h"
    3435#include "RadarObject.h"
     
    4344            Ogre::PanelOverlayElement* navMarker_;      // the panel used to show the arrow
    4445            Ogre::TextAreaOverlayElement* navText_;     // displaying distance
    45             Ogre::MovableObject* movo_;
    46             Ogre::Camera* cam_;
    47                 Vector3 shipPos_;                           // position of ship
     46            Ogre::Camera* navCam_;
     47                Vector3 navCamPos_;                            // position of ship
     48                Vector3 currentDir_;
     49            Vector3 currentOrth_;
    4850                int windowW_, windowH_;
    49 
    5051                void init();
    5152                void updateMarker();
  • code/trunk/src/orxonox/hud/RadarObject.h

    r1393 r1400  
    4747            int index_;                             // index number of object
    4848                Vector3 pos_;                                                   // position in space
    49                         Ogre::Real radius_, phi_;                               // position on radar
    5049                        Ogre::OverlayContainer* container_;
    5150                        Ogre::PanelOverlayElement* panel_;              // the panel used to show the dot
  • code/trunk/src/orxonox/hud/RadarOverlayElement.cc

    r1399 r1400  
    5959        container_ = container;
    6060
    61         // these have to fit the data in the level
    62         shipPos_ = Vector3(0.0, 0.0, 0.0);
    63         initialDir_ = Vector3(1.0, 0.0, 0.0);
    64         currentDir_ = initialDir_;
    65         initialOrth_ = Vector3(0.0, 0.0, 1.0);
    66         currentOrth_ = initialOrth_;
    67         plane = Plane(currentDir_, shipPos_);
    68 
    6961        setMetricsMode(GMM_PIXELS);
    7062        setMaterialName("Orxonox/Radar");
     
    8678
    8779    void RadarOverlayElement::update() {
    88         shipPos_ = SpaceShip::instance_s->getPosition();
    89         currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;
    90                 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
    91         plane = Plane(currentDir_, shipPos_);
     80        shipPos_ = SpaceShip::getLocalShip()->getPosition();
     81        currentDir_ = SpaceShip::getLocalShip()->getDir();
     82                currentOrth_ = SpaceShip::getLocalShip()->getOrth();
    9283        RadarObject* ro = HUD::getSingleton().getFirstRadarObject();
    9384        // iterate through all RadarObjects
    9485                while(ro != NULL){
    9586                    // calc position on radar...
    96             ro->radius_ = calcRadius(ro);
    97             ro->phi_ = calcPhi(ro);
    98             ro->right_ = calcRight(ro);
     87            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, ro);
     88            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, ro);
     89            bool right = calcRight(shipPos_, currentDir_, currentOrth_, ro);
    9990
    10091            // set size to fit distance...
     
    10596            else ro->panel_->setDimensions(1,1);
    10697
    107             if (ro->right_){
    108                 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
    109                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     98            if (right){
     99                ro->panel_->setPosition(sin(phi)*radius/
     100                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    110101            }
    111102            else {
    112                 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
    113                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     103                ro->panel_->setPosition(-sin(phi)*radius/
     104                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    114105            }
    115106            ro = ro->next;
     
    128119        }
    129120
    130         float RadarOverlayElement::calcRadius(RadarObject* obj){
    131             return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
    132                         ((obj->pos_ - shipPos_).length()*currentDir_.length())));
     121        float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     122            return(acos((dir.dotProduct(obj->pos_ - pos))/
     123                        ((obj->pos_ - pos).length()*dir.length())));
    133124        }
    134125
    135         float RadarOverlayElement::calcPhi(RadarObject* obj){
     126        float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
    136127            // project difference vector on our plane...
    137             Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);
     128            Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos);
    138129            // ...and find out the angle
    139             return(acos((currentOrth_.dotProduct(proj))/
    140             (currentOrth_.length()*proj.length())));
     130            return(acos((orth.dotProduct(proj))/
     131            (orth.length()*proj.length())));
    141132        }
    142133
    143         bool RadarOverlayElement::calcRight(RadarObject* obj){
    144             if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
     134        bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     135            if((dir.crossProduct(orth)).dotProduct(obj->pos_ - pos) > 0)
    145136                return true;
    146137        else return false;
  • code/trunk/src/orxonox/hud/RadarOverlayElement.h

    r1393 r1400  
    4141            Ogre::OverlayManager* om;               // our one and only overlay manager
    4242            Ogre::OverlayContainer* container_;     // pointer to the container we're in
    43             Vector3 initialDir_;                        // direction of nose
    4443            Vector3 currentDir_;
    45             Vector3 initialOrth_;                   // direction of normal
    4644            Vector3 currentOrth_;
    4745            Vector3 shipPos_;                       // position of ship
    48             Ogre::Plane plane;                      // plane perpendicular to dir
    4946
    5047            Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
     
    5956            void update();
    6057            void listObjects();
    61             float calcRadius(RadarObject* obj);
    62             float calcPhi(RadarObject* obj);
    63             bool calcRight(RadarObject* obj);
     58
     59            static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     60            static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     61            static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
    6462        };
    6563}
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1399 r1400  
    112112        this->setConfigValues();
    113113
     114        initialDir_ = Vector3(1.0, 0.0, 0.0);
     115        currentDir_ = initialDir_;
     116        initialOrth_ = Vector3(0.0, 0.0, 1.0);
     117        currentOrth_ = initialOrth_;
    114118
    115119        this->setRotationAxis(1, 0, 0);
     
    247251      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    248252      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
    249       this->camNode_->setPosition(Vector3(-50,0,10));
     253      this->camNode_->setPosition(Vector3(0,0,0));//-50,0,10));
    250254//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    251255//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     
    395399    }
    396400
    397     Vector3 SpaceShip::getSPosition() {
    398         return SpaceShip::getLocalShip()->getPosition();
    399     }
    400 
    401     Quaternion SpaceShip::getSOrientation() {
    402         return SpaceShip::getLocalShip()->getOrientation();
     401    Vector3 SpaceShip::getDir() {
     402        return currentDir_;
     403    }
     404
     405    Vector3 SpaceShip::getOrth(){
     406        return currentOrth_;
    403407    }
    404408
     
    407411    void SpaceShip::tick(float dt)
    408412    {
     413        currentDir_ = getOrientation()*initialDir_;
     414                currentOrth_ = getOrientation()*initialOrth_;
     415
    409416        if (this->cam_)
    410417            this->cam_->tick(dt);
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1399 r1400  
    6464            void setTransDamp(float value);
    6565            void setRotDamp(float value);
     66            void getFocus();
    6667
    67             void getFocus();
    68             Camera* getCamera();
    6968            static SpaceShip* instance_s;
    70             static Vector3 getSPosition();
    71             static Quaternion getSOrientation();
    7269            static std::string whereAmI();
    7370            static void setMaxSpeedTest(float value)
     
    8178
    8279            float getMaxSpeed();
     80            Vector3 getDir();
     81            Vector3 getOrth();
     82            Camera* getCamera();
    8383
    8484        private:
     
    8686
    8787            Vector3 testvector_;
     88            Vector3 initialDir_;
     89            Vector3 currentDir_;
     90            Vector3 initialOrth_;
     91            Vector3 currentOrth_;
    8892            bool bInvertYAxis_;
    8993            bool setMouseEventCallback_;
Note: See TracChangeset for help on using the changeset viewer.