Revision: 7517
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7517&view=rev
Author:   hsujohnhsu
Date:     2009-03-17 01:31:58 +0000 (Tue, 17 Mar 2009)

Log Message:
-----------
function for selecting body (vs. model).

Modified Paths:
--------------
    code/gazebo/branches/ogre-1.4.9/server/rendering/OgreAdaptor.cc

Modified: code/gazebo/branches/ogre-1.4.9/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/rendering/OgreAdaptor.cc     
2009-03-17 01:30:58 UTC (rev 7516)
+++ code/gazebo/branches/ogre-1.4.9/server/rendering/OgreAdaptor.cc     
2009-03-17 01:31:58 UTC (rev 7517)
@@ -35,6 +35,7 @@
 #include <string.h>
 
 #include "Model.hh"
+#include "Body.hh"
 #include "OgreVisual.hh"
 #include "UserCamera.hh"
 #include "MovableText.hh"
@@ -492,7 +493,8 @@
       if (vis && vis->GetEntity())
       {
         entity = vis->GetEntity();
-        entity->GetVisualNode()->ShowSelectionBox(true);
+        //entity->GetVisualNode()->ShowSelectionBox(true);
+        entity->GetVisualNode()->SetTransparency(0.6);
         Model *model = NULL;
         
         do 
@@ -512,6 +514,54 @@
 
 
 
////////////////////////////////////////////////////////////////////////////////
+/// Get an body at a pixel location using a camera. Used for mouse picking. 
+Body *OgreAdaptor::GetBodyAt(OgreCamera *camera, Vector2<int> mousePos) 
+{
+  // these entities are geom's
+  Entity *entity = NULL;
+  Ogre::Camera *ogreCam = camera->GetOgreCamera();
+  Ogre::Vector3 camPos = ogreCam->getPosition();
+
+  Ogre::Ray mouseRay = ogreCam->getCameraToViewportRay(
+      (float)mousePos.x / ogreCam->getViewport()->getActualWidth(), 
+      (float)mousePos.y / ogreCam->getViewport()->getActualHeight() );
+
+  this->raySceneQuery->setRay( mouseRay );
+
+  // Perform the scene query
+  Ogre::RaySceneQueryResult &result = this->raySceneQuery->execute();
+  Ogre::RaySceneQueryResult::iterator iter = result.begin();
+
+  for (iter = result.begin(); iter != result.end(); iter++)
+  {
+    if (iter->movable)
+    {
+
+      OgreVisual *vis = 
dynamic_cast<OgreVisual*>(iter->movable->getUserObject());
+      if (vis && vis->GetEntity())
+      {
+        entity = vis->GetEntity();
+        //entity->GetVisualNode()->ShowSelectionBox(true);
+        entity->GetVisualNode()->SetTransparency(0.6);
+        Body *body = NULL;
+        
+        do 
+        {
+          body = dynamic_cast<Body*>(entity);
+          entity = entity->GetParent();
+        } while (body == NULL);
+
+        return body;
+      }
+    }
+
+  }
+
+  return NULL;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
 /// Get the desired update rate
 double OgreAdaptor::GetUpdateRate()
 {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to