00001 #ifndef PH_CONSTRAINT_H
00002 #define PH_CONSTRAINT_H
00003
00004 #include <vector>
00005 #include <Base/BaseUtility.h>
00006 #include <Base/TinyVec.h>
00007 #include <Base/TinyMat.h>
00008 #include <FileIO/FIDocScene.h>
00009 #include <SceneGraph/SGScene.h>
00010 #include <Physics/PHSolid.h>
00011
00012 namespace Spr{
00013
00014
00015
00016
00017 class PHConstrainedState{
00018 public:
00019 class DesiredPosture{
00020 public:
00021 double weight;
00022 Vec3d position;
00023 Quaterniond orientation;
00024 };
00025 UTRef<PHSolid> solid;
00026 std::vector<DesiredPosture> desired;
00027 int nConstraints;
00028
00029 PHConstrainedState():nConstraints(0){};
00030 };
00031
00032
00033
00034
00035 class PHConstraint : public SGObject{
00036 public:
00037 UTRef<PHSolid> solid[2];
00038 UTRef<PHConstrainedState> state[2];
00039 size_t idx[2];
00040
00041
00042 virtual size_t NChildObjects();
00043
00044 virtual SGObject* ChildObject(size_t i);
00045
00046 virtual bool AddChildObject(SGObject* o, SGScene* s);
00047
00048 virtual bool DelChildObject(SGObject* o, SGScene* s);
00049
00050 virtual const UTTypeInfo** ChildCandidates();
00051 };
00052
00053 class PHPointConstraint : public PHConstraint{
00054 public:
00055 class Info{
00056 Vec3f pos_l, pos_r;
00057 };
00058 Info info;
00059 };
00060
00061
00062
00063
00064
00065
00066
00067
00068 class PHLineConstraint : public PHConstraint{
00069 Vec3f pos_l, pos_r;
00070 Vec3f dir_l, dir_r;
00071 };
00072
00073 class PHPlaneConstraint : public PHConstraint{
00074 Vec3f pos_l, pos_r;
00075 Vec3f nor_l, nor_r;
00076 };
00077
00078 class PHPararrelConstraint : public PHConstraint{
00079 Vec3f dir_l, dir_r;
00080 };
00081
00082 class PHFixConstraint : public PHConstraint{
00083 Vec3f pos;
00084 Matrix3f rotation;
00085 };
00086
00087 class PHMagnetConstraint : public PHConstraint{
00088
00089 };
00090
00091 class PHContactConstraint : public PHConstraint{
00092
00093 };
00094
00095
00096
00097
00098 typedef std::vector<UTRef<PHConstrainedState> > PHConstrainedStates;
00099 typedef std::vector<UTRef<PHConstraint> > PHConstraints;
00100
00101 class PHConstraintEngine : public SGBehaviorEngine
00102 {
00103 PHConstrainedStates states;
00104 PHConstraints cons;
00105 public:
00106 SGOBJECTDEF(PHConstraintEngine);
00107 int GetPriority() const {return SG_CONSTRAINT;}
00108 void Loaded(SGScene* scene);
00109 void Clear(SGScene* s){}
00110 PHConstraintEngine::PHConstraintEngine(){}
00111
00112 virtual void Step(SGScene* s);
00113 void SolveConstraint();
00114
00115
00116 virtual size_t NChildObjects();
00117
00118 virtual SGObject* ChildObject(size_t i);
00119
00120 virtual bool AddChildObject(SGObject* o, SGScene* s);
00121
00122 virtual bool DelChildObject(SGObject* o, SGScene* s);
00123
00124 virtual const UTTypeInfo** ChildCandidates();
00125 };
00126
00127 }
00128
00129 #endif