Revision: 46728 http://brlcad.svn.sourceforge.net/brlcad/?rev=46728&view=rev Author: abhi2011 Date: 2011-09-16 05:02:51 +0000 (Fri, 16 Sep 2011) Log Message: ----------- Added 2 files for containing a RT based contact manifold generator
Added Paths: ----------- brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp brlcad/trunk/src/libged/simulate/simcollisionalgo.h Added: brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp (rev 0) +++ brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp 2011-09-16 05:02:51 UTC (rev 46728) @@ -0,0 +1,143 @@ +/* S I M C O L L I S I O N A L G O . C P P + * BRL-CAD + * + * Copyright (c) 2008-2011 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file libged/simulate/simcollisionalgo.cpp + * + * + * Routines related to performing collision detection using rt + * This is a custom algorithm that replaces the box-box collision algorithm + * in bullet + * + */ + +#include "common.h" + +#ifdef HAVE_BULLET + +#include "simcollisionalgo.h" + + +#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" +#include "BulletCollision/CollisionShapes/btBoxShape.h" +#include "BulletCollision/CollisionDispatch/btCollisionObject.h" +#include "BulletCollision/CollisionDispatch/btBoxBoxDetector.h" + +#define USE_PERSISTENT_CONTACTS 1 + +btRTCollisionAlgorithm::btRTCollisionAlgorithm( + btPersistentManifold* mf, + const btCollisionAlgorithmConstructionInfo& ci, + btCollisionObject* obj0, + btCollisionObject* obj1) +: btActivatingCollisionAlgorithm(ci,obj0,obj1), +m_ownManifold(false), +m_manifoldPtr(mf) +{ + if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0,obj1)) + { + m_manifoldPtr = m_dispatcher->getNewManifold(obj0,obj1); + m_ownManifold = true; + } +} + +btRTCollisionAlgorithm::~btRTCollisionAlgorithm() +{ + if (m_ownManifold) + { + if (m_manifoldPtr) + m_dispatcher->releaseManifold(m_manifoldPtr); + } +} + +void btRTCollisionAlgorithm::processCollision ( + btCollisionObject* body0, + btCollisionObject* body1, + const btDispatcherInfo& dispatchInfo, + btManifoldResult* resultOut) +{ + if (!m_manifoldPtr) + return; + + btCollisionObject* col0 = body0; + btCollisionObject* col1 = body1; + btBoxShape* box0 = (btBoxShape*)col0->getCollisionShape(); + btBoxShape* box1 = (btBoxShape*)col1->getCollisionShape(); + + + + /// report a contact. internally this will be kept persistent, and contact reduction is done + resultOut->setPersistentManifold(m_manifoldPtr); +#ifndef USE_PERSISTENT_CONTACTS + m_manifoldPtr->clearManifold(); +#endif //USE_PERSISTENT_CONTACTS + + btDiscreteCollisionDetectorInterface::ClosestPointInput input; + input.m_maximumDistanceSquared = BT_LARGE_FLOAT; + input.m_transformA = body0->getWorldTransform(); + input.m_transformB = body1->getWorldTransform(); + + //This part will get replaced with a call to rt + btBoxBoxDetector detector(box0,box1); + detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); + +#ifdef USE_PERSISTENT_CONTACTS + // refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added + if (m_ownManifold) + { + resultOut->refreshContactPoints(); + } +#endif //USE_PERSISTENT_CONTACTS + +} + +btScalar btRTCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/,btCollisionObject* /*body1*/,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/) +{ + //not yet + return 1.f; +} + + + + + + + + + + + + + + + + + + + + +#endif + +// Local Variables: +// tab-width: 8 +// mode: C++ +// c-basic-offset: 4 +// indent-tabs-mode: t +// c-file-style: "stroustrup" +// End: +// ex: shiftwidth=4 tabstop=8 Property changes on: brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: propset + svn:eol-style Added: svn:eol-style + native Added: brlcad/trunk/src/libged/simulate/simcollisionalgo.h =================================================================== --- brlcad/trunk/src/libged/simulate/simcollisionalgo.h (rev 0) +++ brlcad/trunk/src/libged/simulate/simcollisionalgo.h 2011-09-16 05:02:51 UTC (rev 46728) @@ -0,0 +1,103 @@ +/* S I M C O L L I S I O N A L G O . H + * BRL-CAD + * + * Copyright (c) 2008-2011 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file libged/simulate/simcollisionalgo.h + * + * + * Routines related to performing collision detection using rt + * This is a custom algorithm that replaces the box-box collision algorithm + * in bullet + * + */ + +#ifndef SIMULATE_COLL_ALGO_H_ +#define SIMULATE_COLL_ALGO_H_ + +#include "common.h" + +#ifdef HAVE_BULLET + +#include <iostream> + +#include "db.h" +#include "vmath.h" +#include "simulate.h" + +#include <btBulletDynamicsCommon.h> + + +#include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h" +#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" +#include "BulletCollision/BroadphaseCollision/btDispatcher.h" +#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h" + +class btPersistentManifold; + +///Raytrace based collision detection +class btRTCollisionAlgorithm : public btActivatingCollisionAlgorithm +{ + bool m_ownManifold; + btPersistentManifold* m_manifoldPtr; + +public: + btRTCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci) + : btActivatingCollisionAlgorithm(ci) {} + + virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); + + virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); + + btRTCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1); + + virtual ~btRTCollisionAlgorithm(); + + virtual void getAllContactManifolds(btManifoldArray& manifoldArray) + { + if (m_manifoldPtr && m_ownManifold) + { + manifoldArray.push_back(m_manifoldPtr); + } + } + + + struct CreateFunc :public btCollisionAlgorithmCreateFunc + { + virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) + { + int bbsize = sizeof(btRTCollisionAlgorithm); + void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize); + return new(ptr) btRTCollisionAlgorithm(0,ci,body0,body1); + } + }; + +}; + + +#endif + +#endif /* SIMULATE_COLL_ALGO_H_ */ + +// Local Variables: +// tab-width: 8 +// mode: C++ +// c-basic-offset: 4 +// indent-tabs-mode: t +// c-file-style: "stroustrup" +// End: +// ex: shiftwidth=4 tabstop=8 Property changes on: brlcad/trunk/src/libged/simulate/simcollisionalgo.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: propset + svn:eol-style Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA http://p.sf.net/sfu/rim-devcon-copy2 _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits