[Orxonox-commit 1315] r6033 - in code/branches/steering/src/orxonox: controllers graphics

wirthmi at orxonox.net wirthmi at orxonox.net
Wed Nov 4 17:47:31 CET 2009


Author: wirthmi
Date: 2009-11-04 17:47:31 +0100 (Wed, 04 Nov 2009)
New Revision: 6033

Modified:
   code/branches/steering/src/orxonox/controllers/HumanController.cc
   code/branches/steering/src/orxonox/controllers/HumanController.h
   code/branches/steering/src/orxonox/controllers/NewHumanController.cc
   code/branches/steering/src/orxonox/controllers/NewHumanController.h
   code/branches/steering/src/orxonox/graphics/Camera.h
Log:
Added the ability to raytrace on fire to find the object to user wants to aim at.


Modified: code/branches/steering/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/branches/steering/src/orxonox/controllers/HumanController.cc	2009-11-04 16:30:38 UTC (rev 6032)
+++ code/branches/steering/src/orxonox/controllers/HumanController.cc	2009-11-04 16:47:31 UTC (rev 6033)
@@ -142,7 +142,7 @@
             HumanController::localController_s->controllableEntity_->rotateRoll(value);
     }
 
-    void HumanController::fire(unsigned int firemode)
+    void HumanController::doFire(unsigned int firemode)
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
             HumanController::localController_s->controllableEntity_->fire(firemode);

Modified: code/branches/steering/src/orxonox/controllers/HumanController.h
===================================================================
--- code/branches/steering/src/orxonox/controllers/HumanController.h	2009-11-04 16:30:38 UTC (rev 6032)
+++ code/branches/steering/src/orxonox/controllers/HumanController.h	2009-11-04 16:47:31 UTC (rev 6033)
@@ -55,7 +55,8 @@
             virtual void yaw(const Vector2& value);
             virtual void pitch(const Vector2& value);
 
-            static void fire(unsigned int firemode);
+            static void fire(unsigned int firemode) { HumanController::localController_s->doFire(firemode); }
+            virtual void doFire(unsigned int firemode);
             static void reload();
 
             static void boost();
@@ -78,7 +79,7 @@
             //friend class, for mouselook
             friend class Map;
 
-        private:
+        protected:
             static HumanController* localController_s;
     };
 }

Modified: code/branches/steering/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/steering/src/orxonox/controllers/NewHumanController.cc	2009-11-04 16:30:38 UTC (rev 6032)
+++ code/branches/steering/src/orxonox/controllers/NewHumanController.cc	2009-11-04 16:47:31 UTC (rev 6033)
@@ -28,8 +28,10 @@
 
 #include "NewHumanController.h"
 
-#include "core/input/InputManager.h"
-#include "core/input/InputState.h"
+#include <OgreRay.h>
+#include <OgreSceneQuery.h>
+#include <OgreCamera.h>
+#include <OgreSceneManager.h>
 
 #include "core/CoreIncludes.h"
 #include "core/ConsoleCommand.h"
@@ -52,9 +54,11 @@
     {
         RegisterObject(NewHumanController);
 
+        overlaySize = 0.08;
+
         CrossHairOverlay = new OrxonoxOverlay(this);
         CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3");
-        CrossHairOverlay->setSize(Vector2(0.08,0.08));
+        CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize));
         CrossHairOverlay->show();
     }
 
@@ -66,7 +70,7 @@
     }
 
     void NewHumanController::tick(float dt) {
-        CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_), static_cast<float>(this->currentPitch_)));
+        CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2));
 
         HumanController::tick(dt);
     }
@@ -87,13 +91,71 @@
         }
     }*/
     
+    void NewHumanController::doFire(unsigned int firemode)
+    {
+        //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) {
+
+/*
+
+ // Get results, create a node/entity on the position
+ for ( itr = result.begin(); itr != result.end(); itr++ )
+ {
+     if (itr->movable && itr->movable->getName() == "Head")
+     {
+         soundMgr->StopSound( &jaguarSoundChannel );
+         soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
+         break;
+     } // if
+ }
+*/
+
+            Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
+
+std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << "  Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
+
+            Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5);
+
+            rsq->setRay(mouseRay);
+            rsq->setSortByDistance(true);
+
+
+            Ogre::RaySceneQueryResult &result = rsq->execute();
+
+            Ogre::RaySceneQueryResult::iterator itr;
+for ( itr = result.begin(); itr != result.end(); itr++ )
+ {
+     std::cout << "distance: " << itr->distance << "  name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType() << endl;
+if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity") {
+std::cout << " in scene" << endl;
+	itr->movable->getParentSceneNode()->showBoundingBox(true);
+}
+ }
+
+//if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
+// && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
+//result.front().movable->setVisible(false);
+
+std::cout << endl;
+/*
+            if (!result.empty()) {
+            	Ogre::RaySceneQueryResultEntry obj = result.front();
+            	std::cout << "distance: " << obj.distance << "  name: " << obj.movable->getName() << endl;
+            }
+*/
+
+
+            HumanController::localController_s->getControllableEntity()->fire(firemode);
+        //}
+//}
+    }
+
     void NewHumanController::yaw(const Vector2& value)
     {
 //         SUPER(NewHumanController, yaw, value);
         HumanController::yaw(value);
         
         this->currentYaw_ = value.x;
-        std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
+        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
     }
     void NewHumanController::pitch(const Vector2& value)
     {
@@ -101,7 +163,7 @@
         HumanController::pitch(value);
         
         this->currentPitch_ = value.x;
-        std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
+        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
     }
 
 }

Modified: code/branches/steering/src/orxonox/controllers/NewHumanController.h
===================================================================
--- code/branches/steering/src/orxonox/controllers/NewHumanController.h	2009-11-04 16:30:38 UTC (rev 6032)
+++ code/branches/steering/src/orxonox/controllers/NewHumanController.h	2009-11-04 16:47:31 UTC (rev 6033)
@@ -33,6 +33,7 @@
 
 #include "HumanController.h"
 #include "overlays/OrxonoxOverlay.h"
+#include "util/OgreForwardRefs.h"
 
 namespace orxonox
 {
@@ -47,10 +48,13 @@
             virtual void yaw(const Vector2& value);
             virtual void pitch(const Vector2& value);
 
+            virtual void doFire(unsigned int firemode);
+
         private:
             float                       currentYaw_;
             float                       currentPitch_;
             OrxonoxOverlay              *CrossHairOverlay;
+            float			overlaySize;
     };
 }
 

Modified: code/branches/steering/src/orxonox/graphics/Camera.h
===================================================================
--- code/branches/steering/src/orxonox/graphics/Camera.h	2009-11-04 16:30:38 UTC (rev 6032)
+++ code/branches/steering/src/orxonox/graphics/Camera.h	2009-11-04 16:47:31 UTC (rev 6033)
@@ -51,6 +51,9 @@
             void requestFocus();
             void releaseFocus();
 
+            inline Ogre::Camera* getCamera()
+               { return this->camera_; }
+
             inline bool hasFocus()
                 { return this->bHasFocus_; }
 




More information about the Orxonox-commit mailing list