Changeset 1400
- Timestamp:
- May 24, 2008, 12:24:30 AM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/bin/levels/sample.oxw
r1388 r1400 12 12 <Skybox src="Orxonox/Starbox" /> 13 13 <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"/> 17 17 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/> 18 18 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/> -
code/trunk/src/orxonox/hud/HUD.cc
r1399 r1400 102 102 103 103 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)); 107 107 } 108 108 -
code/trunk/src/orxonox/hud/Navigation.cc
r1399 r1400 30 30 #include <OgreTextAreaOverlayElement.h> 31 31 #include <OgreStringConverter.h> 32 #include <OgreMatrix4.h>33 32 #include <GraphicsEngine.h> 34 #include "core/Iterator.h"35 33 #include "objects/SpaceShip.h" 36 34 #include "objects/CameraHandler.h" … … 56 54 void Navigation::init(){ 57 55 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; 66 57 // create nav text 67 58 navText_ = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "navText")); … … 86 77 void Navigation::update(){ 87 78 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 89 83 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 90 84 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); … … 97 91 navText_->setCaption(Ogre::StringConverter::toString(dist)); 98 92 99 if( cam_ == NULL) cam_ = SpaceShip::getLocalShip()->getCamera()->cam_;93 if(navCam_ == NULL) navCam_ = SpaceShip::getLocalShip()->getCamera()->cam_; 100 94 Vector3 pos = focus_->pos_; 101 95 // transform to screen coordinates 102 pos = cam_->getProjectionMatrix()*cam_->getViewMatrix()*pos;96 pos = navCam_->getProjectionMatrix()*navCam_->getViewMatrix()*pos; 103 97 float xPosRel = 0.5*pos.x+0.5; 104 98 float yPosRel = 1-(0.5*pos.y+0.5); … … 108 102 bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1); 109 103 // 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; 111 105 112 106 if(outOfView){ … … 117 111 // from the angle we find out where to draw the marker 118 112 // 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){ 122 117 // arrow up 123 navMarker_->setPosition(tan(phi )*windowH_/2+windowW_/2, 0);118 navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, 0); 124 119 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 125 120 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); 126 121 navText_->setTop(navMarker_->getHeight()); 127 122 } 128 else if(phi >3.14-phiUpRight){123 else if(phiNav>3.14-phiUpRight){ 129 124 // arrow down 130 navMarker_->setPosition(-tan(phi )*windowH_/2+windowW_/2, windowH_-16);125 navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, windowH_-16); 131 126 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 132 127 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); … … 135 130 else { 136 131 // 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); 138 133 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 139 134 navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth()); … … 142 137 } 143 138 else{ 144 if(phi <phiUpRight) {139 if(phiNav<phiUpRight) { 145 140 // arrow up 146 navMarker_->setPosition(-tan(phi )*windowH_/2+windowW_/2, 0);141 navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0); 147 142 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 148 143 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); 149 144 navText_->setTop(navMarker_->getHeight()); 150 145 } 151 else if(phi >3.14-phiUpRight) {146 else if(phiNav>3.14-phiUpRight) { 152 147 // arrow down 153 navMarker_->setPosition(tan(phi )*windowH_/2+windowW_/2, windowH_-16);148 navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16); 154 149 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 155 150 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); … … 158 153 else { 159 154 // 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); 161 156 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 162 157 navText_->setLeft(navMarker_->getWidth()); … … 197 192 float Navigation::getDist2Focus(){ 198 193 if(focus_ == NULL) return(0.0); 199 return((focus_->pos_- shipPos_).length());194 return((focus_->pos_-SpaceShip::getLocalShip()->getPosition()).length()); 200 195 } 201 196 } -
code/trunk/src/orxonox/hud/Navigation.h
r1399 r1400 31 31 #include <OgrePrerequisites.h> 32 32 #include "../OrxonoxPrereqs.h" 33 #include <OgrePlane.h> 33 34 #include "util/Math.h" 34 35 #include "RadarObject.h" … … 43 44 Ogre::PanelOverlayElement* navMarker_; // the panel used to show the arrow 44 45 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_; 48 50 int windowW_, windowH_; 49 50 51 void init(); 51 52 void updateMarker(); -
code/trunk/src/orxonox/hud/RadarObject.h
r1393 r1400 47 47 int index_; // index number of object 48 48 Vector3 pos_; // position in space 49 Ogre::Real radius_, phi_; // position on radar50 49 Ogre::OverlayContainer* container_; 51 50 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot -
code/trunk/src/orxonox/hud/RadarOverlayElement.cc
r1399 r1400 59 59 container_ = container; 60 60 61 // these have to fit the data in the level62 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 69 61 setMetricsMode(GMM_PIXELS); 70 62 setMaterialName("Orxonox/Radar"); … … 86 78 87 79 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(); 92 83 RadarObject* ro = HUD::getSingleton().getFirstRadarObject(); 93 84 // iterate through all RadarObjects 94 85 while(ro != NULL){ 95 86 // 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); 99 90 100 91 // set size to fit distance... … … 105 96 else ro->panel_->setDimensions(1,1); 106 97 107 if (r o->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); 110 101 } 111 102 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); 114 105 } 115 106 ro = ro->next; … … 128 119 } 129 120 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()))); 133 124 } 134 125 135 float RadarOverlayElement::calcPhi( RadarObject* obj){126 float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 136 127 // project difference vector on our plane... 137 Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);128 Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos); 138 129 // ...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()))); 141 132 } 142 133 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) 145 136 return true; 146 137 else return false; -
code/trunk/src/orxonox/hud/RadarOverlayElement.h
r1393 r1400 41 41 Ogre::OverlayManager* om; // our one and only overlay manager 42 42 Ogre::OverlayContainer* container_; // pointer to the container we're in 43 Vector3 initialDir_; // direction of nose44 43 Vector3 currentDir_; 45 Vector3 initialOrth_; // direction of normal46 44 Vector3 currentOrth_; 47 45 Vector3 shipPos_; // position of ship 48 Ogre::Plane plane; // plane perpendicular to dir49 46 50 47 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension … … 59 56 void update(); 60 57 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); 64 62 }; 65 63 } -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1399 r1400 112 112 this->setConfigValues(); 113 113 114 initialDir_ = Vector3(1.0, 0.0, 0.0); 115 currentDir_ = initialDir_; 116 initialOrth_ = Vector3(0.0, 0.0, 1.0); 117 currentOrth_ = initialOrth_; 114 118 115 119 this->setRotationAxis(1, 0, 0); … … 247 251 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 248 252 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)); 250 254 // Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 251 255 // Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); … … 395 399 } 396 400 397 Vector3 SpaceShip::get SPosition() {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_; 403 407 } 404 408 … … 407 411 void SpaceShip::tick(float dt) 408 412 { 413 currentDir_ = getOrientation()*initialDir_; 414 currentOrth_ = getOrientation()*initialOrth_; 415 409 416 if (this->cam_) 410 417 this->cam_->tick(dt); -
code/trunk/src/orxonox/objects/SpaceShip.h
r1399 r1400 64 64 void setTransDamp(float value); 65 65 void setRotDamp(float value); 66 void getFocus(); 66 67 67 void getFocus();68 Camera* getCamera();69 68 static SpaceShip* instance_s; 70 static Vector3 getSPosition();71 static Quaternion getSOrientation();72 69 static std::string whereAmI(); 73 70 static void setMaxSpeedTest(float value) … … 81 78 82 79 float getMaxSpeed(); 80 Vector3 getDir(); 81 Vector3 getOrth(); 82 Camera* getCamera(); 83 83 84 84 private: … … 86 86 87 87 Vector3 testvector_; 88 Vector3 initialDir_; 89 Vector3 currentDir_; 90 Vector3 initialOrth_; 91 Vector3 currentOrth_; 88 92 bool bInvertYAxis_; 89 93 bool setMouseEventCallback_;
Note: See TracChangeset
for help on using the changeset viewer.