Hello David, On 09/13/2010 02:21 PM, David Antonio Castro MartÃnez wrote: > I've been reading past lists and it looks like someone was able to use > bullet physics with OpenSG.
I've not done it yet - it is on my list for one of our projects... > http://bulletphysics.org/wordpress/ > > I would appreciate if they could share an example of how it is done ...so I don't have an example, but I'd imagine you'd need at the very least a specialization of btMotionState that allows bullet to read and update the position of objects: class OpenSGMotionState : public btMotionState { public: explicit OpenSGMotionState(OSG::Node* xformNode); virtual ~OpenSGMotionState(void); virtual void getWorldTransform(btTransform& xform) const; virtual void setWorldTransform(btTransform const& xform); protected: OSG::NodeRefPtr _xformNode; OSG::TransformRefPtr _xform; }; OpenSGMotionState::OpenSGMotionState(OSG::Node* xformNode) : btMotionState(), _xformNode (xformNode), _xform (dynamic_cast<OSG::Transform*>(xformNode->getCore())) { } OpenSGMotionState::~OpenSGMotionState() { } void OpenSGMotionState::getWorldTransform(btTransform& xform) const { OSG::Matrixr m(_xformNode->getToWorld()); xform.setFromOpenGLMatrix(m.getValues()); } void OpenSGMotionState::setWorldTransform(btTransfrom const& xform) { OSG::Matrixr::ValueType buf[16]; xform.getOpenGLMatrix(buf); OSG::Matrixr m; m.setValue(buf); // convert from world transform to relative transform by // "subtracting" the parents transform OSG::Matrix parent_inv; if(_xformNode->getParent() != NULL) { parent_inv = _xformNode->getParent()->getToWorld(); parent_inv.invert(); } m.multLeft(parent_inv); _xform.editSFMatrix()->setValue(m); } please note that the above is completely untested, but I hope it gives you a starting point. Cheers, Carsten ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users