00001
00002
00003
00004
00005
00006
00007 #ifndef _IMPULSE_CONTACT_SIMULATOR_H
00008 #define _IMPULSE_CONTACT_SIMULATOR_H
00009
00010 #include <map>
00011 #include <Physsim/sorted_pair>
00012 #include <Physsim/Simulator.h>
00013 #include <Physsim/CollisionMethod.h>
00014 #include <Physsim/ContactData.h>
00015 #include <Physsim/RestingContactMethod.h>
00016
00017 namespace Physsim {
00018
00019 struct ICSMinimalStateStruct;
00020 class Contact;
00021 class CollisionDetection;
00022 class CollisionGeometry;
00023 class RigidBody;
00024 class ArticulatedBody;
00025
00027
00049 class ImpulseContactSimulator : public Simulator
00050 {
00051 public:
00052 ImpulseContactSimulator();
00053 virtual ~ImpulseContactSimulator() {}
00054 virtual void determine_external_forces();
00055 CollisionGeometryPtr find_collision_geometry(const std::string& name) const;
00056 virtual void clone(BasePtr& cloned, bimap<BasePtr, BasePtr>* object_map = NULL) const;
00057 virtual bool is_struct_identical(BaseConstPtr object) const;
00058 virtual void load_state(BaseConstPtr object, bimap<BasePtr, BasePtr>* object_map = NULL);
00059 virtual void save_state(BasePtr object, bimap<BasePtr, BasePtr>* object_map = NULL) const;
00060 virtual void load_from_xml(XMLTreeConstPtr node, std::map<std::string, BasePtr>& id_map);
00061 virtual void save_to_xml(XMLTreePtr node, std::list<BaseConstPtr>& shared_objects) const;
00062 virtual void output_object_state(std::ostream& out) const;
00063
00065 const std::map<sorted_pair<BasePtr>, boost::shared_ptr<ContactData> >& get_contact_data() const { return _contact_data; }
00066
00068 const std::list<ContactPtr>& get_contacts() const { return _contacts; }
00069
00071 void clear_contact_data() { _contact_data.clear(); }
00072
00074 void add_contact_data(boost::shared_ptr<ContactData> cd) { _contact_data[cd->objects] = cd ; }
00075
00077 boost::shared_ptr<CollisionDetection> get_collision_detection() { return _coll_det; }
00078
00080 void set_collision_detection(boost::shared_ptr<CollisionDetection> colldet) { _coll_det = colldet; }
00081
00083
00088 virtual Real step(Real step_size);
00089
00091 void set_callback_function(void (*fn)(ContactPtr)) { _callback_fn = fn; }
00092
00094 void (*get_callback_function())(ContactPtr) { return _callback_fn; }
00095
00097 Real get_collision_tolerance() const { return _collision_tolerance; }
00098
00100 void set_collision_tolerance(Real collision_tolerance) { assert(collision_tolerance >= 0); _collision_tolerance = collision_tolerance; }
00101
00102 protected:
00103 void preprocess_contact(ContactPtr contact) const;
00104 boost::shared_ptr<ContactData> get_contact_data(CollisionGeometryPtr g1, boost::shared_ptr<CollisionGeometry> g2) const;
00105 bool impact_contact(boost::shared_ptr<ICSMinimalStateStruct> state_t0, boost::shared_ptr<ICSMinimalStateStruct> state_tf);
00106 void regress_to_first_TOI(boost::shared_ptr<ICSMinimalStateStruct> state_t0, boost::shared_ptr<ICSMinimalStateStruct> state_tf, Real tolerance);
00107 static void* find_contact(void* arg);
00108 boost::shared_ptr<ICSMinimalStateStruct> clone_minimal() const;
00109 void load_state_minimal(boost::shared_ptr<ICSMinimalStateStruct> mss);
00110 void update_contacts();
00111
00112 std::list<ContactPtr> _contacts;
00113 Real _collision_tolerance;
00114 std::map<sorted_pair<BasePtr>, boost::shared_ptr<ContactData> > _contact_data;
00115 boost::shared_ptr<CollisionDetection> _coll_det;
00116 void (*_callback_fn)(ContactPtr);
00117 };
00118
00119 }
00120
00121 #endif