CrystalSpace

Public API Reference

ivaria/dynamics.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2002 Anders Stenberg
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 
00020 #ifndef __CS_IVARIA_DYNAMICS_H__
00021 #define __CS_IVARIA_DYNAMICS_H__
00022 
00027 #include "csutil/scf.h"
00028 
00029 
00030 struct iBodyGroup;
00031 struct iJoint;
00032 struct iMeshWrapper;
00033 struct iLight;
00034 struct iCamera;
00035 struct iObject;
00036 struct iRigidBody;
00037 
00038 class csMatrix3;
00039 class csOrthoTransform;
00040 class csPlane3;
00041 class csVector3;
00042 
00043 struct iDynamicsCollisionCallback;
00044 struct iDynamicsMoveCallback;
00045 struct iDynamicSystem;
00046 
00047 
00051 struct iDynamicsStepCallback : public virtual iBase
00052 {
00053   SCF_INTERFACE (iDynamicsStepCallback, 0, 0, 1);
00054 
00055   virtual void Step (float stepsize) = 0;
00056 };
00057 
00071 struct iDynamics : public virtual iBase
00072 {
00073   SCF_INTERFACE(iDynamics,0,0,2);
00075   virtual csPtr<iDynamicSystem> CreateSystem () = 0;
00076 
00078   virtual void RemoveSystem (iDynamicSystem* system) = 0;
00079 
00081   virtual void RemoveSystems () = 0;
00082 
00084   virtual iDynamicSystem* FindSystem (const char *name) = 0;
00085 
00087   virtual void Step (float stepsize) = 0;
00088 
00092   virtual void AddStepCallback (iDynamicsStepCallback *callback) = 0;
00093 
00097   virtual void RemoveStepCallback (iDynamicsStepCallback *callback) = 0;
00098 };
00099 
00100 struct iDynamicsSystemCollider;
00101 
00114 struct iDynamicSystem : public virtual iBase
00115 {
00116   SCF_INTERFACE (iDynamicSystem, 0, 0, 2);
00117 
00119   virtual iObject *QueryObject (void) = 0;
00121   virtual void SetGravity (const csVector3& v) = 0;
00123   virtual const csVector3 GetGravity () const = 0;
00125   virtual void SetLinearDampener (float d) = 0;
00127   virtual float GetLinearDampener () const = 0;
00129   virtual void SetRollingDampener (float d) = 0;
00131   virtual float GetRollingDampener () const = 0;
00132 
00138   virtual void EnableAutoDisable (bool enable) = 0;
00139   virtual bool AutoDisableEnabled () =0;
00149   virtual void SetAutoDisableParams (float linear, float angular, int steps,
00150         float time)=0;
00151 
00153   virtual void Step (float stepsize) = 0;
00154 
00156   virtual csPtr<iRigidBody> CreateBody () = 0;
00157 
00159   virtual void RemoveBody (iRigidBody* body) = 0;
00160 
00162   virtual iRigidBody *FindBody (const char *name) = 0;
00163 
00165   virtual iRigidBody *GetBody (unsigned int index) = 0;
00166 
00168   virtual int GetBodysCount () = 0;
00169 
00171   virtual csPtr<iBodyGroup> CreateGroup () = 0;
00172 
00174   virtual void RemoveGroup (iBodyGroup* group) = 0;
00175 
00177   virtual csPtr<iJoint> CreateJoint () = 0;
00178 
00180   virtual void RemoveJoint (iJoint* joint) = 0;
00181 
00183   virtual iDynamicsMoveCallback* GetDefaultMoveCallback () = 0;
00184 
00198   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
00199     const csOrthoTransform& trans, float friction,
00200     float elasticity, float softness = 0.01f) = 0;
00201 
00216   virtual bool AttachColliderCylinder (float length, float radius,
00217     const csOrthoTransform& trans, float friction,
00218     float elasticity, float softness = 0.01f) = 0;
00219 
00233   virtual bool AttachColliderBox (const csVector3 &size,
00234     const csOrthoTransform& trans, float friction,
00235     float elasticity, float softness = 0.01f) = 0;
00236 
00251   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
00252     float friction, float elasticity, float softness = 0.01f) = 0;
00253 
00266   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
00267     float elasticity, float softness = 0.01f) = 0;
00268 
00270   virtual void DestroyColliders () = 0;
00271 
00273   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
00274 
00276   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
00277 
00283   virtual csRef<iDynamicsSystemCollider> CreateCollider () = 0;
00284 
00286   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
00287 
00289   virtual int GetColliderCount () = 0;
00290 };
00291 
00303 struct iDynamicsMoveCallback : public virtual iBase
00304 {
00305   SCF_INTERFACE (iDynamicsMoveCallback, 0, 0, 1);
00306 
00307   virtual void Execute (iMeshWrapper* mesh, csOrthoTransform& t) = 0;
00308   virtual void Execute (iLight* light, csOrthoTransform& t) = 0;
00309   virtual void Execute (iCamera* camera, csOrthoTransform& t) = 0;
00310   virtual void Execute (csOrthoTransform& t) = 0;
00311 };
00312 
00323 struct iDynamicsCollisionCallback : public virtual iBase
00324 {
00325   SCF_INTERFACE (iDynamicsCollisionCallback, 0, 0, 2);
00326 
00335   virtual void Execute (iRigidBody *thisbody, iRigidBody *otherbody,
00336       const csVector3& pos, const csVector3& normal, float depth) = 0;
00337 };
00338 
00355 struct iBodyGroup : public virtual iBase
00356 {
00357   SCF_INTERFACE (iBodyGroup, 0, 1, 0);
00358 
00360   virtual void AddBody (iRigidBody *body) = 0;
00362   virtual void RemoveBody (iRigidBody *body) = 0;
00364   virtual bool BodyInGroup (iRigidBody *body) = 0;
00365 };
00366 
00382 struct iRigidBody : public virtual iBase
00383 {
00384   SCF_INTERFACE (iRigidBody, 0, 0, 2);
00385 
00387   virtual iObject *QueryObject (void) = 0;
00393   virtual bool MakeStatic (void) = 0;
00395   virtual bool MakeDynamic (void) = 0;
00397   virtual bool IsStatic (void) = 0;
00401   virtual bool Disable (void) = 0;
00403   virtual bool Enable (void) = 0;
00405   virtual bool IsEnabled (void) = 0;  
00406 
00408   virtual csRef<iBodyGroup> GetGroup (void) = 0;
00409 
00425   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
00426     const csOrthoTransform& trans, float friction, float density,
00427     float elasticity, float softness = 0.01f) = 0;
00428 
00445   virtual bool AttachColliderCylinder (float length, float radius,
00446     const csOrthoTransform& trans, float friction, float density,
00447     float elasticity, float softness = 0.01f) = 0;
00448 
00464   virtual bool AttachColliderBox (const csVector3 &size,
00465     const csOrthoTransform& trans, float friction, float density,
00466     float elasticity, float softness = 0.01f) = 0;
00467 
00483   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
00484     float friction, float density, float elasticity,
00485     float softness = 0.01f) = 0;
00486 
00501   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
00502     float density, float elasticity, float softness = 0.01f) = 0;
00503 
00510   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
00511 
00513   virtual void DestroyColliders () = 0;
00514 
00516   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
00517 
00519   virtual void SetPosition (const csVector3& trans) = 0;
00521   virtual const csVector3 GetPosition () const = 0;
00523   virtual void SetOrientation (const csMatrix3& trans) = 0;
00525   virtual const csMatrix3 GetOrientation () const = 0;
00527   virtual void SetTransform (const csOrthoTransform& trans) = 0;
00529   virtual const csOrthoTransform GetTransform () const = 0;
00531   virtual void SetLinearVelocity (const csVector3& vel) = 0;
00533   virtual const csVector3 GetLinearVelocity () const = 0;
00535   virtual void SetAngularVelocity (const csVector3& vel) = 0;
00537   virtual const csVector3 GetAngularVelocity () const = 0;
00538 
00540   virtual void SetProperties (float mass, const csVector3& center,
00541     const csMatrix3& inertia) = 0;
00543   virtual void GetProperties (float* mass, csVector3* center,
00544     csMatrix3* inertia) = 0;
00546   virtual float GetMass () = 0;
00548   virtual csVector3 GetCenter () = 0;
00550   virtual csMatrix3 GetInertia () = 0;
00551 
00553   virtual void AdjustTotalMass (float targetmass) = 0;
00554 
00556   virtual void AddForce (const csVector3& force) = 0;
00558   virtual void AddTorque (const csVector3& force) = 0;
00560   virtual void AddRelForce (const csVector3& force) = 0;
00562   virtual void AddRelTorque (const csVector3& force) = 0 ;
00567   virtual void AddForceAtPos (const csVector3& force, const csVector3& pos) = 0;
00572   virtual void AddForceAtRelPos (const csVector3& force,
00573     const csVector3& pos) = 0;
00578   virtual void AddRelForceAtPos (const csVector3& force,
00579     const csVector3& pos) = 0;
00584   virtual void AddRelForceAtRelPos (const csVector3& force,
00585     const csVector3& pos) = 0;
00586 
00588   virtual const csVector3 GetForce () const = 0;
00590   virtual const csVector3 GetTorque () const = 0;
00591 
00592   /*
00594   virtual const csVector3& GetRelForce () const = 0;
00596   virtual const csVector3& GetRelTorque () const = 0;
00597   */
00598 
00599   /*
00601   virtual int GetJointCount () const = 0;
00602   */
00603 
00605   virtual void AttachMesh (iMeshWrapper* mesh) = 0;
00607   virtual iMeshWrapper* GetAttachedMesh () = 0;
00609   virtual void AttachLight (iLight* light) = 0;
00611   virtual iLight* GetAttachedLight () = 0;
00613   virtual void AttachCamera (iCamera* camera) = 0;
00615   virtual iCamera* GetAttachedCamera () = 0;
00616 
00621   virtual void SetMoveCallback (iDynamicsMoveCallback* cb) = 0;
00626   virtual void SetCollisionCallback (iDynamicsCollisionCallback* cb) = 0;
00627 
00635   virtual void Collision (iRigidBody *other, const csVector3& pos,
00636       const csVector3& normal, float depth) = 0;
00637 
00639   virtual void Update () = 0;
00640 
00642   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
00643 
00645   virtual int GetColliderCount () = 0;
00646 };
00647 
00648 enum csColliderGeometryType
00649 {
00650   NO_GEOMETRY,
00651   BOX_COLLIDER_GEOMETRY,
00652   PLANE_COLLIDER_GEOMETRY,
00653   TRIMESH_COLLIDER_GEOMETRY,
00654   CYLINDER_COLLIDER_GEOMETRY,
00655   CAPSULE_COLLIDER_GEOMETRY,
00656   SPHERE_COLLIDER_GEOMETRY
00657 };
00658 
00659 
00669 struct iDynamicsColliderCollisionCallback : public virtual iBase
00670 {
00671   SCF_INTERFACE (iDynamicsColliderCollisionCallback, 0, 0, 1);
00672 
00673   virtual void Execute (iDynamicsSystemCollider *thiscollider, 
00674     iDynamicsSystemCollider *othercollider) = 0;
00675   virtual void Execute (iDynamicsSystemCollider *thiscollider, 
00676     iRigidBody *otherbody) = 0;
00677 };
00678 
00679 
00680 struct iGeneralFactoryState;
00681 class csBox3;
00682 class csSphere;
00683 class csReversibleTransform;
00684 
00704 struct iDynamicsSystemCollider : public virtual iBase
00705 {
00706   SCF_INTERFACE (iDynamicsSystemCollider, 0, 0, 1);
00707 
00709   virtual bool CreateSphereGeometry (const csSphere& sphere) = 0;
00710 
00712   virtual bool CreatePlaneGeometry (const csPlane3& plane) = 0;
00713 
00715   virtual bool CreateMeshGeometry (iMeshWrapper *mesh) = 0;
00716 
00718   virtual bool CreateBoxGeometry (const csVector3& box_size) = 0;
00719 
00724   CS_DEPRECATED_METHOD_MSG("CreateCCylinderGeometry is deprecated, use CreateCapsuleGeometry instead")
00725   virtual bool CreateCCylinderGeometry (float length, float radius) = 0;
00726   
00728   virtual bool CreateCapsuleGeometry (float length, float radius) = 0;
00729 
00730   //FIXME: This should be implememented, but it is not so obvious - it
00731   //should be valid also for static colliders.
00732   virtual void SetCollisionCallback (
00733         iDynamicsColliderCollisionCallback* cb) = 0;
00734 
00736   virtual void SetFriction (float friction) = 0;
00737 
00739   virtual void SetSoftness (float softness) = 0;
00740 
00746   virtual void SetDensity (float density) = 0;
00747 
00749   virtual void SetElasticity (float elasticity) = 0;
00750   
00752   virtual float GetFriction () = 0;
00753 
00755   virtual float GetSoftness () = 0;
00756 
00758   virtual float GetDensity () = 0;
00759 
00761   virtual float GetElasticity () = 0;
00762 
00764   virtual void FillWithColliderGeometry (
00765         csRef<iGeneralFactoryState> genmesh_fact) = 0;
00766 
00768   virtual csColliderGeometryType GetGeometryType () = 0;
00769 
00771   virtual csOrthoTransform GetTransform () = 0;
00772 
00777   virtual csOrthoTransform GetLocalTransform () = 0;
00778 
00783   virtual void SetTransform (const csOrthoTransform& trans) = 0;
00784 
00789   virtual bool GetBoxGeometry (csVector3& size) = 0; 
00790 
00795   virtual bool GetSphereGeometry (csSphere& sphere) = 0;
00796 
00801   virtual bool GetPlaneGeometry (csPlane3& plane) = 0; 
00802 
00807   virtual bool GetCylinderGeometry (float& length, float& radius) = 0; 
00808 
00814   virtual void MakeStatic () = 0;
00815 
00820   virtual void MakeDynamic () = 0;
00821 
00823   virtual bool IsStatic () = 0;
00824 };
00825 
00839 struct iJoint : public virtual iBase
00840 {
00841   SCF_INTERFACE (iJoint, 0, 0, 1);
00842 
00844   virtual void Attach (iRigidBody* body1, iRigidBody* body2) = 0;
00846   virtual csRef<iRigidBody> GetAttachedBody (int body) = 0;
00852   virtual void SetTransform (const csOrthoTransform &trans) = 0;
00854   virtual csOrthoTransform GetTransform () = 0;
00862   virtual void SetTransConstraints (bool X, bool Y, bool Z) = 0;
00864   virtual bool IsXTransConstrained () = 0;
00866   virtual bool IsYTransConstrained () = 0;
00868   virtual bool IsZTransConstrained () = 0;
00870   virtual void SetMinimumDistance (const csVector3 &min) = 0;
00872   virtual csVector3 GetMinimumDistance () = 0;
00874   virtual void SetMaximumDistance (const csVector3 &max) = 0;
00876   virtual csVector3 GetMaximumDistance () = 0;
00882   virtual void SetRotConstraints (bool X, bool Y, bool Z) = 0;
00884   virtual bool IsXRotConstrained () = 0;
00886   virtual bool IsYRotConstrained () = 0;
00888   virtual bool IsZRotConstrained () = 0;
00890   virtual void SetMinimumAngle (const csVector3 &min) = 0;
00892   virtual csVector3 GetMinimumAngle () = 0;
00894   virtual void SetMaximumAngle (const csVector3 &max) = 0;
00896   virtual csVector3 GetMaximumAngle () = 0;
00897 
00898   //Motor parameters
00899 
00905   virtual void SetBounce (const csVector3 & bounce ) = 0;
00907   virtual csVector3 GetBounce () = 0;
00909   virtual void SetDesiredVelocity (const csVector3 &velocity ) = 0;
00910   virtual csVector3 GetDesiredVelocity () = 0;
00912   virtual void SetMaxForce (const csVector3 & maxForce ) = 0;
00913   virtual csVector3 GetMaxForce () = 0;
00915   virtual void SetAngularConstraintAxis (const csVector3 &axis, int body) = 0;
00917   virtual csVector3 GetAngularConstraintAxis (int body) = 0;
00918 
00919 };
00920 
00921 #endif // __CS_IVARIA_DYNAMICS_H__
00922 

Generated for Crystal Space 1.2.1 by doxygen 1.5.3