Physics.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #include <ode/ode.h>
00018 #include "Renderer.h"
00019 #include <set>
00020 
00021 #ifndef FLUXUS_PHYSICS
00022 #define FLUXUS_PHYSICS
00023 
00025 namespace Fluxus
00026 {
00027 
00030 class Physics
00031 {
00032 public:
00033     Physics(Renderer *r);
00034     virtual ~Physics();
00035     
00036     enum BoundingType {BOX,CYLINDER,SPHERE};
00037     enum ObjectType {ACTIVE,PASSIVE};
00038     
00040     void Tick();
00041     
00043     void Render();
00044     
00051     void MakeActive(int ID,float MassBoundingType, BoundingType Bound=BOX);
00052     void MakePassive(int ID,float MassBoundingType, BoundingType Bound=BOX);
00054     
00055     void Free(int ID);
00056     void Clear();
00059     void RegisterRenderer(Renderer* s) { m_Renderer=s; }
00060     void GroundPlane(dVector ori, float off);
00061     void Kick(int ID, dVector v);
00062     void Twist(int ID, dVector v);
00063     void SetMass(int ID, float mass);
00064     void SetCollisions(bool s) { m_Collisions=s; }
00065     void SetGravity(const dVector &g);
00066     void SetGlobalSurfaceParams(float slip1, float slip2, float softerp, float softcfm) 
00067         { m_Slip1=slip1; m_Slip2=slip2; m_SoftErp=softerp; m_SoftCfm=softcfm; }
00068         
00072     int CreateJointFixed(int Ob1);
00073     int CreateJointBall(int Ob1, int Ob2, dVector Anchor);
00074     int CreateJointHinge(int Ob1, int Ob2, dVector Anchor, dVector Hinge);
00075     int CreateJointSlider(int Ob1, int Ob2, dVector Hinge);
00076     int CreateJointHinge2(int Ob1, int Ob2, dVector Anchor, dVector Hinge[2]);
00077     int CreateJointAMotor(int Ob1, int Ob2, dVector Axis);
00078     void SetJointAngle(int ID, float force, float angle); 
00079     void SetJointParam(int ID, const string &Param, float Value);
00081     
00082     int GetMaxObjectCount() { return m_MaxObjectCount; }
00083     void SetMaxObjectCount(int s) { m_MaxObjectCount=s; }
00084 
00085     bool HasCollided(int Ob);
00086     
00087 private:
00088     // helpers that use ode types for convienience, and so it can be built with double support
00089     void DrawLocator(dVector3 pos);
00090     void DrawAxis(dVector3 pos, dVector3 dir);
00091 
00092     enum JointType {BallJoint,HingeJoint,SliderJoint,ContactJoint,UniversalJoint,Hinge2Joint,FixedJoint,AMotorJoint};
00093 
00094     class Object
00095     {
00096     public:
00097         Object();
00098         ~Object();
00099         ObjectType Type;
00100         dBodyID Body;
00101         dGeomID Bound;
00102         Primitive *Prim;
00103     };
00104     
00105     class JointObject
00106     {
00107     public:
00108         JointObject();
00109         ~JointObject();
00110         dJointID Joint;
00111         JointType Type;
00112     };
00113     
00114     void UpdatePrimitives();
00115     
00116     static void NearCallback(void *data, dGeomID o1, dGeomID o2);
00117     void NearCallback_i(dGeomID o1, dGeomID o2);
00118     
00119     dWorldID m_World;
00120     dSpaceID m_Space;
00121     dGeomID m_Ground;
00122     
00123     map<int,Object*>       m_ObjectMap;
00124     map<int,dGeomID>       m_GroupMap;
00125     map<int,JointObject*>  m_JointMap;
00126     deque<int>             m_History;
00127     set<dBodyID>           m_CollisionRecord;
00128     
00129     Renderer *m_Renderer;
00130     int m_MaxObjectCount;
00131     bool m_GroundCreated;
00132     dJointGroupID m_ContactGroup;
00133     int m_NextJointID;
00134     bool m_Collisions;
00135 
00136     float m_Slip1;
00137     float m_Slip2;
00138     float m_SoftErp;
00139     float m_SoftCfm;
00140 };
00141 
00142 };
00143 
00144 #endif

Generated on Tue Sep 4 23:22:18 2007 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1