ObjectPicker.cpp
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2013 University of Jaume-I.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the GNU Public License v3.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.gnu.org/licenses/gpl.html
00007  * 
00008  * Contributors:
00009  *     Mario Prats
00010  *     Javier Perez
00011  */
00012 
00013 #include <uwsim/ObjectPicker.h>
00014 #include <uwsim/UWSimUtils.h>
00015 
00016 ObjectPicker::ObjectPicker() :
00017     VirtualRangeSensor()
00018 {
00019 }
00020 
00021 ObjectPicker::ObjectPicker(std::string name, osg::Node *root, osg::Node *trackNode, double range, bool visible,
00022                            boost::shared_ptr<URDFRobot> urdf,unsigned int mask)
00023 {
00024   init(name, root, trackNode, range, visible, urdf, mask);
00025 }
00026 
00027 void ObjectPicker::init(std::string name, osg::Node *root, osg::Node *trackNode, double range, bool visible,
00028                         boost::shared_ptr<URDFRobot> urdf,unsigned int mask)
00029 {
00030   this->name = name;
00031   this->root = root;
00032 
00033   this->trackNode = trackNode;
00034   //Add a switchable frame geometry on the sensor frame
00035   osg::ref_ptr < osg::Node > axis = UWSimGeometry::createSwitchableFrame();
00036   //Add label to switchable frame
00037   axis->asGroup()->addChild(UWSimGeometry::createLabel(name));
00038   this->trackNode->asGroup()->addChild(axis);
00039 
00040   this->range = range;
00041   this->visible = visible;
00042 
00043   //make this virtual ray track the node
00044   node_tracker = new ObjectPickerUpdateCallback(trackNode, range, visible, root, urdf);
00045   trackNode->setUpdateCallback((ObjectPickerUpdateCallback*)(node_tracker.get()));
00046   trackNode->asGroup()->addChild(node_tracker->geode);
00047 
00048   if(node_tracker->geode)
00049     node_tracker->geode->setNodeMask(mask);
00050 }
00051 
00052 /*
00053  bool Hand::closeHand(){
00054 
00055  for(osg::NodePath::iterator i=node_tracker->impact.begin();i!=node_tracker->impact.end();++i){
00056  osg::ref_ptr<NodeDataType> data = dynamic_cast<NodeDataType*> (i[0]->getUserData());
00057  if(data!=NULL && data->catchable){  //Search for "catchable" objects in nodepath
00058  //Get coordinates to change them when changing position in graph
00059  osg::Matrixd *originalpos=getWorldCoords(i[0]);
00060  osg::Matrixd *hand = getWorldCoords(trackNode);
00061  hand->invert(*hand);
00062 
00063  //Turn object to Kinematic state, add callback to move collision shape
00064  if(data->rb)
00065  data->rb->setCollisionFlags( data->rb->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
00066  catched_callback=new BulletPhysics::MirrorTransformCallback(data->rb);
00067  i[0]->setUpdateCallback(catched_callback);
00068 
00069  //ADD node in hand, remove object from original position.
00070  trackNode->asTransform()->addChild(i[0]);
00071  i[0]->getParent(0)->asGroup()->removeChild(i[0]);
00072  osg::Matrixd matrix=*originalpos * *hand;
00073  i[0]->asTransform()->asMatrixTransform()->setMatrix(matrix);
00074  freeHand=0;
00075  catched=i[0];
00076  return 1;
00077  }
00078 
00079  }
00080  return 0;
00081  }
00082 
00083 
00084  void Hand::openHand(){
00085  osg::ref_ptr<NodeDataType> data = dynamic_cast<NodeDataType*> (catched->getUserData());
00086 
00087  osg::Matrixd *originalpos=getWorldCoords(catched);
00088  osg::Matrixd *world = getWorldCoords(root);
00089  world->invert(*world);
00090 
00091  root->asGroup()->addChild(catched);
00092  trackNode->asGroup()->removeChild(catched);
00093  osg::Matrixd matrix=*originalpos * *world;
00094  catched->asTransform()->asMatrixTransform()->setMatrix(matrix);
00095 
00096  //Get collision shape to current position, destroy callback and turn object to Dynamic state again.
00097  catched->removeUpdateCallback(catched_callback);
00098  catched_callback=NULL;
00099  data->rb->setWorldTransform( osgbCollision::asBtTransform(matrix) );
00100  if(data->rb)
00101  data->rb->setCollisionFlags( data->rb->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT );
00102  freeHand=1;
00103  catched=NULL;
00104 
00105  }
00106  */
00107 


uwsim
Author(s): Mario Prats , Javier Perez
autogenerated on Fri Aug 28 2015 13:28:58