| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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 iPolygonMesh;
    00037 struct iRigidBody;
    00038
    00039 class csMatrix3;
    00040 class csOrthoTransform;
    00041 class csPlane3;
    00042 class csVector3;
    00043
    00044 struct iDynamicsCollisionCallback;
    00045 struct iDynamicsMoveCallback;
    00046 struct iDynamicSystem;
    00047
    00061 struct iDynamics : public virtual iBase
    00062 {
    00063   SCF_INTERFACE(iDynamics,0,0,2);
    00065   virtual csPtr<iDynamicSystem> CreateSystem () = 0;
    00066
    00068   virtual void RemoveSystem (iDynamicSystem* system) = 0;
    00069
    00071   virtual void RemoveSystems () = 0;
    00072
    00074   virtual iDynamicSystem* FindSystem (const char *name) = 0;
    00075
    00077   virtual void Step (float stepsize) = 0;
    00078 };
    00079
    00080 struct iDynamicsSystemCollider;
    00081
    00094 struct iDynamicSystem : public virtual iBase
    00095 {
    00096   SCF_INTERFACE (iDynamicSystem, 0, 0, 2);
    00097
    00099   virtual iObject *QueryObject (void) = 0;
    00101   virtual void SetGravity (const csVector3& v) = 0;
    00103   virtual const csVector3 GetGravity () const = 0;
    00105   virtual void SetLinearDampener (float d) = 0;
    00107   virtual float GetLinearDampener () const = 0;
    00109   virtual void SetRollingDampener (float d) = 0;
    00111   virtual float GetRollingDampener () const = 0;
    00112
    00118   virtual void EnableAutoDisable (bool enable) = 0;
    00119   virtual bool AutoDisableEnabled () =0;
    00129   virtual void SetAutoDisableParams (float linear, float angular, int steps,
    00130         float time)=0;
    00131
    00133   virtual void Step (float stepsize) = 0;
    00134
    00136   virtual csPtr<iRigidBody> CreateBody () = 0;
    00137
    00139   virtual void RemoveBody (iRigidBody* body) = 0;
    00140
    00142   virtual iRigidBody *FindBody (const char *name) = 0;
    00143
    00145   virtual iRigidBody *GetBody (unsigned int index) = 0;
    00146
    00148   virtual int GetBodysCount () = 0;
    00149
    00151   virtual csPtr<iBodyGroup> CreateGroup () = 0;
    00152
    00154   virtual void RemoveGroup (iBodyGroup* group) = 0;
    00155
    00157   virtual csPtr<iJoint> CreateJoint () = 0;
    00158
    00160   virtual void RemoveJoint (iJoint* joint) = 0;
    00161
    00163   virtual iDynamicsMoveCallback* GetDefaultMoveCallback () = 0;
    00164
    00178   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
    00179     const csOrthoTransform& trans, float friction,
    00180     float elasticity, float softness = 0.01f) = 0;
    00181
    00196   virtual bool AttachColliderCylinder (float length, float radius,
    00197     const csOrthoTransform& trans, float friction,
    00198     float elasticity, float softness = 0.01f) = 0;
    00199
    00213   virtual bool AttachColliderBox (const csVector3 &size,
    00214     const csOrthoTransform& trans, float friction,
    00215     float elasticity, float softness = 0.01f) = 0;
    00216
    00231   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
    00232     float friction, float elasticity, float softness = 0.01f) = 0;
    00233
    00246   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
    00247     float elasticity, float softness = 0.01f) = 0;
    00248
    00250   virtual void DestroyColliders () = 0;
    00251
    00253   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
    00254
    00256   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
    00257
    00263   virtual csRef<iDynamicsSystemCollider> CreateCollider () = 0;
    00264
    00266   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
    00267
    00269   virtual int GetColliderCount () = 0;
    00270 };
    00271
    00283 struct iDynamicsMoveCallback : public virtual iBase
    00284 {
    00285   SCF_INTERFACE (iDynamicsMoveCallback, 0, 0, 1);
    00286
    00287   virtual void Execute (iMeshWrapper* mesh, csOrthoTransform& t) = 0;
    00288   virtual void Execute (iLight* light, csOrthoTransform& t) = 0;
    00289   virtual void Execute (iCamera* camera, csOrthoTransform& t) = 0;
    00290   virtual void Execute (csOrthoTransform& t) = 0;
    00291 };
    00292
    00293 SCF_VERSION (iDynamicsCollisionCallback, 0, 0, 2);
    00294
    00305 struct iDynamicsCollisionCallback : public iBase
    00306 {
    00315   virtual void Execute (iRigidBody *thisbody, iRigidBody *otherbody,
    00316       const csVector3& pos, const csVector3& normal, float depth) = 0;
    00317 };
    00318
    00319 SCF_VERSION (iBodyGroup, 0, 0, 1);
    00320
    00337 struct iBodyGroup : public iBase
    00338 {
    00340    virtual void AddBody (iRigidBody *body) = 0;
    00342    virtual void RemoveBody (iRigidBody *body) = 0;
    00344    virtual bool BodyInGroup (iRigidBody *body) = 0;
    00345 };
    00346
    00362 struct iRigidBody : public virtual iBase
    00363 {
    00364   SCF_INTERFACE (iRigidBody, 0, 0, 2);
    00365
    00367   virtual iObject *QueryObject (void) = 0;
    00373   virtual bool MakeStatic (void) = 0;
    00375   virtual bool MakeDynamic (void) = 0;
    00377   virtual bool IsStatic (void) = 0;
    00381   virtual bool Disable (void) = 0;
    00383   virtual bool Enable (void) = 0;
    00385   virtual bool IsEnabled (void) = 0;
    00386
    00388   virtual csRef<iBodyGroup> GetGroup (void) = 0;
    00389
    00405   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
    00406     const csOrthoTransform& trans, float friction, float density,
    00407     float elasticity, float softness = 0.01f) = 0;
    00408
    00425   virtual bool AttachColliderCylinder (float length, float radius,
    00426     const csOrthoTransform& trans, float friction, float density,
    00427     float elasticity, float softness = 0.01f) = 0;
    00428
    00444   virtual bool AttachColliderBox (const csVector3 &size,
    00445     const csOrthoTransform& trans, float friction, float density,
    00446     float elasticity, float softness = 0.01f) = 0;
    00447
    00463   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
    00464     float friction, float density, float elasticity,
    00465     float softness = 0.01f) = 0;
    00466
    00481   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
    00482     float density, float elasticity, float softness = 0.01f) = 0;
    00483
    00490   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
    00491
    00493   virtual void DestroyColliders () = 0;
    00494
    00496   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
    00497
    00499   virtual void SetPosition (const csVector3& trans) = 0;
    00501   virtual const csVector3 GetPosition () const = 0;
    00503   virtual void SetOrientation (const csMatrix3& trans) = 0;
    00505   virtual const csMatrix3 GetOrientation () const = 0;
    00507   virtual void SetTransform (const csOrthoTransform& trans) = 0;
    00509   virtual const csOrthoTransform GetTransform () const = 0;
    00511   virtual void SetLinearVelocity (const csVector3& vel) = 0;
    00513   virtual const csVector3 GetLinearVelocity () const = 0;
    00515   virtual void SetAngularVelocity (const csVector3& vel) = 0;
    00517   virtual const csVector3 GetAngularVelocity () const = 0;
    00518
    00520   virtual void SetProperties (float mass, const csVector3& center,
    00521     const csMatrix3& inertia) = 0;
    00523   virtual void GetProperties (float* mass, csVector3* center,
    00524     csMatrix3* inertia) = 0;
    00526   virtual float GetMass () = 0;
    00528   virtual csVector3 GetCenter () = 0;
    00530   virtual csMatrix3 GetInertia () = 0;
    00531
    00533   virtual void AdjustTotalMass (float targetmass) = 0;
    00534
    00536   virtual void AddForce (const csVector3& force) = 0;
    00538   virtual void AddTorque (const csVector3& force) = 0;
    00540   virtual void AddRelForce (const csVector3& force) = 0;
    00542   virtual void AddRelTorque (const csVector3& force) = 0 ;
    00547   virtual void AddForceAtPos (const csVector3& force, const csVector3& pos) = 0;
    00552   virtual void AddForceAtRelPos (const csVector3& force,
    00553     const csVector3& pos) = 0;
    00558   virtual void AddRelForceAtPos (const csVector3& force,
    00559     const csVector3& pos) = 0;
    00564   virtual void AddRelForceAtRelPos (const csVector3& force,
    00565     const csVector3& pos) = 0;
    00566
    00568   virtual const csVector3 GetForce () const = 0;
    00570   virtual const csVector3 GetTorque () const = 0;
    00571
    00572   /*
    00574   virtual const csVector3& GetRelForce () const = 0;
    00576   virtual const csVector3& GetRelTorque () const = 0;
    00577   */
    00578
    00579   /*
    00581   virtual int GetJointCount () const = 0;
    00582   */
    00583
    00585   virtual void AttachMesh (iMeshWrapper* mesh) = 0;
    00587   virtual iMeshWrapper* GetAttachedMesh () = 0;
    00589   virtual void AttachLight (iLight* light) = 0;
    00591   virtual iLight* GetAttachedLight () = 0;
    00593   virtual void AttachCamera (iCamera* camera) = 0;
    00595   virtual iCamera* GetAttachedCamera () = 0;
    00596
    00601   virtual void SetMoveCallback (iDynamicsMoveCallback* cb) = 0;
    00606   virtual void SetCollisionCallback (iDynamicsCollisionCallback* cb) = 0;
    00607
    00615   virtual void Collision (iRigidBody *other, const csVector3& pos,
    00616       const csVector3& normal, float depth) = 0;
    00617
    00619   virtual void Update () = 0;
    00620
    00622   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
    00623
    00625   virtual int GetColliderCount () = 0;
    00626 };
    00627
    00628 enum csColliderGeometryType
    00629 {
    00630   NO_GEOMETRY,
    00631   BOX_COLLIDER_GEOMETRY,
    00632   PLANE_COLLIDER_GEOMETRY,
    00633   TRIMESH_COLLIDER_GEOMETRY,
    00634   CYLINDER_COLLIDER_GEOMETRY,
    00635   SPHERE_COLLIDER_GEOMETRY
    00636 };
    00637
    00638
    00639 SCF_VERSION (iDynamicsColliderCollisionCallback, 0, 0, 1);
    00640
    00650 struct iDynamicsColliderCollisionCallback : public iBase
    00651 {
    00652   virtual void Execute (iDynamicsSystemCollider *thiscollider,
    00653     iDynamicsSystemCollider *othercollider) = 0;
    00654   virtual void Execute (iDynamicsSystemCollider *thiscollider,
    00655     iRigidBody *otherbody) = 0;
    00656 };
    00657
    00658
    00659 struct iGeneralFactoryState;
    00660 class csBox3;
    00661 class csSphere;
    00662 class csReversibleTransform;
    00663
    00683 struct iDynamicsSystemCollider : public virtual iBase
    00684 {
    00685   SCF_INTERFACE (iDynamicsSystemCollider, 0, 0, 1);
    00686
    00688   virtual bool CreateSphereGeometry (const csSphere& sphere) = 0;
    00689
    00691   virtual bool CreatePlaneGeometry (const csPlane3& plane) = 0;
    00692
    00694   virtual bool CreateMeshGeometry (iMeshWrapper *mesh) = 0;
    00695
    00697   virtual bool CreateBoxGeometry (const csVector3& box_size) = 0;
    00698
    00700   virtual bool CreateCCylinderGeometry (float length, float radius) = 0;
    00701
    00702   //FIXME: This should be implememented, but it is not so obvious - it
    00703   //should be valid also for static colliders.
    00704   virtual void SetCollisionCallback (
    00705         iDynamicsColliderCollisionCallback* cb) = 0;
    00706
    00708   virtual void SetFriction (float friction) = 0;
    00709
    00711   virtual void SetSoftness (float softness) = 0;
    00712
    00718   virtual void SetDensity (float density) = 0;
    00719
    00721   virtual void SetElasticity (float elasticity) = 0;
    00722
    00724   virtual float GetFriction () = 0;
    00725
    00727   virtual float GetSoftness () = 0;
    00728
    00730   virtual float GetDensity () = 0;
    00731
    00733   virtual float GetElasticity () = 0;
    00734
    00736   virtual void FillWithColliderGeometry (
    00737         csRef<iGeneralFactoryState> genmesh_fact) = 0;
    00738
    00740   virtual csColliderGeometryType GetGeometryType () = 0;
    00741
    00743   virtual csOrthoTransform GetTransform () = 0;
    00744
    00749   virtual csOrthoTransform GetLocalTransform () = 0;
    00750
    00755   virtual void SetTransform (const csOrthoTransform& trans) = 0;
    00756
    00761   virtual bool GetBoxGeometry (csVector3& size) = 0;
    00762
    00767   virtual bool GetSphereGeometry (csSphere& sphere) = 0;
    00768
    00773   virtual bool GetPlaneGeometry (csPlane3& plane) = 0;
    00774
    00779   virtual bool GetCylinderGeometry (float& length, float& radius) = 0;
    00780
    00786   virtual void MakeStatic () = 0;
    00787
    00792   virtual void MakeDynamic () = 0;
    00793
    00795   virtual bool IsStatic () = 0;
    00796 };
    00797
    00811 struct iJoint : public virtual iBase
    00812 {
    00813   SCF_INTERFACE (iJoint, 0, 0, 1);
    00814
    00816   virtual void Attach (iRigidBody* body1, iRigidBody* body2) = 0;
    00818   virtual csRef<iRigidBody> GetAttachedBody (int body) = 0;
    00824   virtual void SetTransform (const csOrthoTransform &trans) = 0;
    00826   virtual csOrthoTransform GetTransform () = 0;
    00834   virtual void SetTransConstraints (bool X, bool Y, bool Z) = 0;
    00836   virtual bool IsXTransConstrained () = 0;
    00838   virtual bool IsYTransConstrained () = 0;
    00840   virtual bool IsZTransConstrained () = 0;
    00842   virtual void SetMinimumDistance (const csVector3 &min) = 0;
    00844   virtual csVector3 GetMinimumDistance () = 0;
    00846   virtual void SetMaximumDistance (const csVector3 &max) = 0;
    00848   virtual csVector3 GetMaximumDistance () = 0;
    00854   virtual void SetRotConstraints (bool X, bool Y, bool Z) = 0;
    00856   virtual bool IsXRotConstrained () = 0;
    00858   virtual bool IsYRotConstrained () = 0;
    00860   virtual bool IsZRotConstrained () = 0;
    00862   virtual void SetMinimumAngle (const csVector3 &min) = 0;
    00864   virtual csVector3 GetMinimumAngle () = 0;
    00866   virtual void SetMaximumAngle (const csVector3 &max) = 0;
    00868   virtual csVector3 GetMaximumAngle () = 0;
    00869
    00870   //Motor parameters
    00871
    00877   virtual void SetBounce (const csVector3 & bounce ) = 0;
    00879   virtual csVector3 GetBounce () = 0;
    00881   virtual void SetDesiredVelocity (const csVector3 &velocity ) = 0;
    00882   virtual csVector3 GetDesiredVelocity () = 0;
    00884   virtual void SetMaxForce (const csVector3 & maxForce ) = 0;
    00885   virtual csVector3 GetMaxForce () = 0;
    00887   virtual void SetAngularConstraintAxis (const csVector3 &axis, int body) = 0;
    00889   virtual csVector3 GetAngularConstraintAxis (int body) = 0;
    00890
    00891 };
    00892
    00893 #endif // __CS_IVARIA_DYNAMICS_H__
    00894