Update of /cvsroot/simspark/simspark/spark/plugin/collisionperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv8422 Added Files: Tag: projectx Makefile.am collisionperceptor.cpp collisionperceptor.h collisionperceptor_c.cpp export.cpp forceresistanceperceptor.cpp forceresistanceperceptor.h forceresistanceperceptor_c.cpp perceptorhandler.cpp perceptorhandler.h perceptorhandler_c.cpp touchperceptor.cpp touchperceptor.h touchperceptor_c.cpp touchperceptorhandler.cpp touchperceptorhandler.h touchperceptorhandler_c.cpp Log Message: update from rcssserver3D --- NEW FILE: forceresistanceperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: forceresistanceperceptor.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "forceresistanceperceptor.h" #include <oxygen/physicsserver/odewrapper.h> #include <oxygen/sceneserver/transform.h> using namespace std; using namespace boost; using namespace salt; using namespace oxygen; using namespace zeitgeist; void ForceResistancePerceptor::OnLink() { Perceptor::OnLink(); mBody = shared_static_cast<Transform>(FindParentSupportingClass<Transform>().lock()); if (mBody.get() == 0) GetLog()->Error() << "ForceResistancePerceptor: no suitable parent node found!\n"; } void ForceResistancePerceptor::OnUnlink() { Perceptor::OnUnlink(); mBody.reset(); } void ForceResistancePerceptor::AddTouchInfo(dContact &contact, dJointID contactJointID) { mContactList.push_front(make_pair(contact.geom, contactJointID)); } bool ForceResistancePerceptor::Percept( boost::shared_ptr<oxygen::PredicateList> predList) { if (mContactList.empty()) { return false; } Predicate& predicate = predList->AddPredicate(); predicate.name = "FRP"; predicate.parameter.Clear(); ParameterList& nameElement = predicate.parameter.AddList(); nameElement.AddValue(std::string("n")); nameElement.AddValue(GetName()); Vector3f force(0,0,0); Vector3f pos(0,0,0); float sumLength = 0; for (TContactList::const_iterator i = mContactList.begin(); i!= mContactList.end(); ++i) { dJointFeedback *feedback = dJointGetFeedback(i->second); if (feedback) { Vector3f forceVec(feedback->f1[0], feedback->f1[1], feedback->f1[2]); force += forceVec; pos += Vector3f(i->first.pos[0], i->first.pos[1], i->first.pos[2]) * forceVec.Length(); sumLength += forceVec.Length(); // Sometimes the Percept function is called more than once in a // time step. Double freeing is avoided using this line! dJointSetFeedback(i->second, 0); delete feedback; } } // It should be always true, except when feedback == NULL if (sumLength > 0.001) { mLastPoint = (pos / sumLength ) - mBody->GetLocalTransform().Pos(); mLastForce = force; } ParameterList& posElement = predicate.parameter.AddList(); posElement.AddValue(std::string("c")); posElement.AddValue(mLastPoint.x()); posElement.AddValue(mLastPoint.y()); posElement.AddValue(mLastPoint.z()); ParameterList& forceElement = predicate.parameter.AddList(); forceElement.AddValue(std::string("f")); forceElement.AddValue(mLastForce.x()); forceElement.AddValue(mLastForce.y()); forceElement.AddValue(mLastForce.z()); return true; } void ForceResistancePerceptor::PrePhysicsUpdateInternal(float deltaTime) { mContactList.clear(); } --- NEW FILE: touchperceptorhandler.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: touchperceptorhandler.h,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef TOUCHPERCEPTORHANDLER_H_ #define TOUCHPERCEPTORHANDLER_H_ #include <oxygen/physicsserver/contactjointhandler.h> class ForceResistancePerceptor; /** \class TouchPerceptorHandler is a ContactJointHandler that provides * enough information for the ForceResistancePerceptor */ class TouchPerceptorHandler : public oxygen::ContactJointHandler { public: virtual void HandleCollision(boost::shared_ptr<oxygen::Collider> collidee, dContact& contact); protected: virtual void OnLink(); virtual void OnUnlink(); protected: //! reference to the collision perecptor boost::shared_ptr<ForceResistancePerceptor> mForceResistancePercept; }; DECLARE_CLASS(TouchPerceptorHandler); #endif /*TOUCHPERCEPTORHANDLER_H_*/ --- NEW FILE: touchperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef TOUCHPERCEPTOR_H #define TOUCHPERCEPTOR_H #include "collisionperceptor.h" /** \class */ class TouchPerceptor: public CollisionPerceptor { public: /** \param predicate set "collidees" as a TLeafList as arguments of predicate \return true if data is available */ bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); }; DECLARE_CLASS(TouchPerceptor); #endif //TOUCHPERCEPTOR_H --- NEW FILE: forceresistanceperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: forceresistanceperceptor.h,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef FORCERESISTANCEPERCEPTOR_H_ #define FORCERESISTANCEPERCEPTOR_H_ #include <oxygen/agentaspect/perceptor.h> #include <oxygen/physicsserver/odewrapper.h> #include <oxygen/sceneserver/transform.h> #include <salt/vector.h> #include <list> #include <utility> class ForceResistancePerceptor : public oxygen::Perceptor { protected: typedef std::list<std::pair<dContactGeom, dJointID> > TContactList; public: /** adds new touch information */ void AddTouchInfo(dContact &contact, dJointID contactJointID); /** adds touch information to predList \return true if data is available */ bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); protected: virtual void OnLink(); virtual void OnUnlink(); /** removes old information left over from the previous cycles */ virtual void PrePhysicsUpdateInternal(float deltaTime); protected: TContactList mContactList; //! reference to the parent Transform node boost::shared_ptr<oxygen::Transform> mBody; // These are required while the Percept function can be called more than // once in a time step! //! last calculated point salt::Vector3f mLastPoint; //! last calculated force salt::Vector3f mLastForce; }; DECLARE_CLASS(ForceResistancePerceptor); #endif /*FORCERESISTANCEPERCEPTOR_H_*/ --- NEW FILE: touchperceptorhandler_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: touchperceptorhandler_c.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "touchperceptorhandler.h" using namespace oxygen; void CLASS(TouchPerceptorHandler)::DefineClass() { DEFINE_BASECLASS(oxygen/ContactJointHandler); } --- NEW FILE: export.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: export.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "collisionperceptor.h" #include "perceptorhandler.h" #include "touchperceptor.h" #include "touchperceptorhandler.h" #include "forceresistanceperceptor.h" ZEITGEIST_EXPORT_BEGIN() ZEITGEIST_EXPORT(CollisionPerceptor); ZEITGEIST_EXPORT(PerceptorHandler); ZEITGEIST_EXPORT(TouchPerceptor); ZEITGEIST_EXPORT(TouchPerceptorHandler); ZEITGEIST_EXPORT(ForceResistancePerceptor); ZEITGEIST_EXPORT_END() --- NEW FILE: touchperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "touchperceptor.h" #include <string> using namespace boost; using namespace oxygen; using namespace zeitgeist; bool TouchPerceptor::Percept(shared_ptr<PredicateList> predList) { Predicate& predicate = predList->AddPredicate(); predicate.name = "TCH"; predicate.parameter.Clear(); ParameterList& nameElement = predicate.parameter.AddList(); nameElement.AddValue(std::string("n")); nameElement.AddValue(GetName()); std::string val; if (GetCollidees().size()) val = std::string("1"); else val = std::string("0"); ParameterList & valElement = predicate.parameter.AddList(); valElement.AddValue(std::string("val")); valElement.AddValue(val); return true; } --- NEW FILE: perceptorhandler.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: perceptorhandler.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "perceptorhandler.h" #include "collisionperceptor.h" #include <oxygen/physicsserver/collider.h> #include <oxygen/sceneserver/transform.h> using namespace oxygen; using namespace boost; void PerceptorHandler::OnLink() { // find the first CollisionPerceptor below our closest Transform node shared_ptr<Transform> transformParent = shared_static_cast<Transform> (FindParentSupportingClass<Transform>().lock()); if (transformParent.get() == 0) { return; } //shared_ptr<CollisionPerceptor> perceptor = // shared_static_cast<CollisionPerceptor> // (transformParent->GetChildOfClass("CollisionPerceptor", true)); mColPercept = shared_dynamic_cast<CollisionPerceptor> (transformParent->GetChildSupportingClass("CollisionPerceptor", true)); if (mColPercept.get() == 0) { GetLog()->Error() << "PerceptorHandler: no suitable child node found!\n"; return; } } void PerceptorHandler::OnUnlink() { mColPercept.reset(); } void PerceptorHandler::HandleCollision (boost::shared_ptr<Collider> collidee, dContact& /*contact*/) { if (mColPercept.get() == 0) return; // now find the closest Transform node above the collidee shared_ptr<Transform> colTransformParent = shared_static_cast<Transform> (collidee->FindParentSupportingClass<Transform>().lock()); if (colTransformParent.get() == 0) { return; } // notify the CollisionPerceptor mColPercept->AddCollidee(colTransformParent); } --- NEW FILE: collisionperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: collisionperceptor.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "collisionperceptor.h" using namespace boost; using namespace oxygen; bool CollisionPerceptor::Percept(shared_ptr<PredicateList> predList) { if (mCollidees.empty()) { return false; } Predicate& predicate = predList->AddPredicate(); predicate.name = "collision"; predicate.parameter.Clear(); for ( TLeafList::const_iterator i = GetCollidees().begin(); i != GetCollidees().end(); ++i ) { predicate.parameter.AddValue(*i); } return true; } void CollisionPerceptor::PrePhysicsUpdateInternal(float /*deltaTime*/) { mCollidees.clear(); } void CollisionPerceptor::AddCollidee(boost::shared_ptr<Node> collidee) { if (collidee.get() == 0) { return; } mCollidees.push_back(collidee); } --- NEW FILE: perceptorhandler_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: perceptorhandler_c.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "perceptorhandler.h" using namespace oxygen; void CLASS(PerceptorHandler)::DefineClass() { DEFINE_BASECLASS(oxygen/CollisionHandler); } --- NEW FILE: perceptorhandler.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: perceptorhandler.h,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef PERCEPTORHANDLER_H #define PERCEPTORHANDLER_H #include <oxygen/physicsserver/collisionhandler.h> class CollisionPerceptor; /** \class PerceptorHandler is a CollisionHandler that passes collision information on to a CollisionPerceptor. */ class PerceptorHandler : public oxygen::CollisionHandler { public: PerceptorHandler() : CollisionHandler() {}; virtual ~PerceptorHandler() {}; /** searches for a CollisionPerceptor below the closest Transform node on the way up the hierarchy and notifies it that a collision has occured. \param collidee is the geom ID of the colliders collision partner \param holds the contact points between the two affected geoms as returned from the ODE dCollide function */ virtual void HandleCollision (boost::shared_ptr<oxygen::Collider> collidee, dContact& contact); protected: virtual void OnLink(); virtual void OnUnlink(); protected: //! reference to the collision perecptor boost::shared_ptr<CollisionPerceptor> mColPercept; }; DECLARE_CLASS(PerceptorHandler); #endif // PERCEPTORHANDLER_H --- NEW FILE: Makefile.am --- pkglib_LTLIBRARIES = collisionperceptor.la collisionperceptor_la_SOURCES = export.cpp \ collisionperceptor.h \ collisionperceptor.cpp \ collisionperceptor_c.cpp \ perceptorhandler.h \ perceptorhandler.cpp \ perceptorhandler_c.cpp \ touchperceptor.h \ touchperceptor.cpp \ touchperceptor_c.cpp \ touchperceptorhandler.h \ touchperceptorhandler.cpp \ touchperceptorhandler_c.cpp \ forceresistanceperceptor.h \ forceresistanceperceptor.cpp \ forceresistanceperceptor_c.cpp # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name collisionperceptor_la_LDFLAGS = -module -version-info 0:0:0 AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ --- NEW FILE: forceresistanceperceptor_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: forceresistanceperceptor_c.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "forceresistanceperceptor.h" using namespace boost; using namespace oxygen; void CLASS(ForceResistancePerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); } --- NEW FILE: touchperceptorhandler.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: touchperceptorhandler.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "touchperceptorhandler.h" #include <oxygen/physicsserver/collider.h> #include <oxygen/sceneserver/transform.h> #include <oxygen/physicsserver/world.h> #include <oxygen/physicsserver/space.h> #include "forceresistanceperceptor.h" using namespace oxygen; using namespace boost; void TouchPerceptorHandler::OnLink() { ContactJointHandler::OnLink(); // find the first CollisionPerceptor below our closest Transform node shared_ptr<Transform> transformParent = shared_static_cast<Transform> (FindParentSupportingClass<Transform>().lock()); if (transformParent.get() == 0) { return; } mForceResistancePercept = shared_dynamic_cast<ForceResistancePerceptor>( transformParent->GetChildSupportingClass("ForceResistancePerceptor", true)); if (mForceResistancePercept.get() == 0) GetLog()->Error() << "TouchPerceptorHandler: no suitable child node found!\n"; } void TouchPerceptorHandler::OnUnlink() { ContactJointHandler::OnUnlink(); mForceResistancePercept.reset(); } void TouchPerceptorHandler::HandleCollision( boost::shared_ptr<Collider> collidee, dContact& contact) { if (mCollider.get() == 0 || mWorld.get() == 0 || mSpace.get() == 0) return; // to create a contact joint it we must have at least one body to // attach it to. dBodyID myBody = dGeomGetBody(mCollider->GetODEGeom()); dBodyID collideeBody = dGeomGetBody(collidee->GetODEGeom()); if (myBody == 0 && collideeBody == 0) return; shared_ptr<ContactJointHandler> handler = collidee->FindChildSupportingClass<ContactJointHandler>(); if (handler.get() == 0) return; CalcSurfaceParam(contact.surface,handler->GetSurfaceParameter()); dJointID joint = dJointCreateContact(mWorld->GetODEWorld(), mSpace->GetODEJointGroup(), &contact); dJointAttach (joint, myBody, collideeBody); // Can we avoid dynamic allocation to increase performance?! dJointSetFeedback(joint, new dJointFeedback()); if (mForceResistancePercept.get() != 0) mForceResistancePercept->AddTouchInfo(contact, joint); } --- NEW FILE: collisionperceptor_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: collisionperceptor_c.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "collisionperceptor.h" using namespace boost; using namespace oxygen; void CLASS(CollisionPerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); } --- NEW FILE: collisionperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: collisionperceptor.h,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef COLLISIONPERCEPTOR_H #define COLLISIONPERCEPTOR_H #include <oxygen/agentaspect/perceptor.h> /** \class CollisionPerceptor is used to store collisions as they occur within the scenegraph. It is inteded to be used together with the PerceptorHandler that passes collision information from the physics system on to this perceptor. */ class CollisionPerceptor : public oxygen::Perceptor { public: /** \param predicate set "collidees" as a TLeafList as arguments of predicate \return true if data is available */ virtual bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); /** returns the stored list of collidees */ const zeitgeist::Leaf::TLeafList& GetCollidees() { return mCollidees; } /** stores a new collidee */ void AddCollidee(boost::shared_ptr<zeitgeist::Node> collidee); protected: /** removes old collidees left over from the previous cycles */ virtual void PrePhysicsUpdateInternal(float deltaTime); protected: zeitgeist::Leaf::TLeafList mCollidees; }; DECLARE_CLASS(CollisionPerceptor); #endif //COLLISIONPERCEPTOR_H --- NEW FILE: touchperceptor_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: touchperceptor_c.cpp,v 1.1.2.1 2007/06/22 14:14:48 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "touchperceptor.h" using namespace boost; using namespace oxygen; void CLASS(TouchPerceptor)::DefineClass() { DEFINE_BASECLASS(CollisionPerceptor); } |