## 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, 1);
    00294
    00305 struct iDynamicsCollisionCallback : public iBase
    00306 {
    00307   virtual void Execute (iRigidBody *thisbody, iRigidBody *otherbody) = 0;
    00308 };
    00309
    00310 SCF_VERSION (iBodyGroup, 0, 0, 1);
    00311
    00328 struct iBodyGroup : public iBase
    00329 {
    00331    virtual void AddBody (iRigidBody *body) = 0;
    00333    virtual void RemoveBody (iRigidBody *body) = 0;
    00335    virtual bool BodyInGroup (iRigidBody *body) = 0;
    00336 };
    00337
    00353 struct iRigidBody : public virtual iBase
    00354 {
    00355   SCF_INTERFACE (iRigidBody, 0, 0, 2);
    00356
    00358   virtual iObject *QueryObject (void) = 0;
    00364   virtual bool MakeStatic (void) = 0;
    00366   virtual bool MakeDynamic (void) = 0;
    00368   virtual bool IsStatic (void) = 0;
    00372   virtual bool Disable (void) = 0;
    00374   virtual bool Enable (void) = 0;
    00376   virtual bool IsEnabled (void) = 0;
    00377
    00379   virtual csRef<iBodyGroup> GetGroup (void) = 0;
    00380
    00396   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
    00397     const csOrthoTransform& trans, float friction, float density,
    00398     float elasticity, float softness = 0.01f) = 0;
    00399
    00416   virtual bool AttachColliderCylinder (float length, float radius,
    00417     const csOrthoTransform& trans, float friction, float density,
    00418     float elasticity, float softness = 0.01f) = 0;
    00419
    00435   virtual bool AttachColliderBox (const csVector3 &size,
    00436     const csOrthoTransform& trans, float friction, float density,
    00437     float elasticity, float softness = 0.01f) = 0;
    00438
    00454   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
    00455     float friction, float density, float elasticity,
    00456     float softness = 0.01f) = 0;
    00457
    00472   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
    00473     float density, float elasticity, float softness = 0.01f) = 0;
    00474
    00481   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
    00482
    00484   virtual void DestroyColliders () = 0;
    00485
    00487   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
    00488
    00490   virtual void SetPosition (const csVector3& trans) = 0;
    00492   virtual const csVector3 GetPosition () const = 0;
    00494   virtual void SetOrientation (const csMatrix3& trans) = 0;
    00496   virtual const csMatrix3 GetOrientation () const = 0;
    00498   virtual void SetTransform (const csOrthoTransform& trans) = 0;
    00500   virtual const csOrthoTransform GetTransform () const = 0;
    00502   virtual void SetLinearVelocity (const csVector3& vel) = 0;
    00504   virtual const csVector3 GetLinearVelocity () const = 0;
    00506   virtual void SetAngularVelocity (const csVector3& vel) = 0;
    00508   virtual const csVector3 GetAngularVelocity () const = 0;
    00509
    00511   virtual void SetProperties (float mass, const csVector3& center,
    00512     const csMatrix3& inertia) = 0;
    00514   virtual void GetProperties (float* mass, csVector3* center,
    00515     csMatrix3* inertia) = 0;
    00517   virtual float GetMass () = 0;
    00519   virtual csVector3 GetCenter () = 0;
    00521   virtual csMatrix3 GetInertia () = 0;
    00522
    00524   virtual void AdjustTotalMass (float targetmass) = 0;
    00525
    00527   virtual void AddForce (const csVector3& force) = 0;
    00529   virtual void AddTorque (const csVector3& force) = 0;
    00531   virtual void AddRelForce (const csVector3& force) = 0;
    00533   virtual void AddRelTorque (const csVector3& force) = 0 ;
    00538   virtual void AddForceAtPos (const csVector3& force, const csVector3& pos) = 0;
    00543   virtual void AddForceAtRelPos (const csVector3& force,
    00544     const csVector3& pos) = 0;
    00549   virtual void AddRelForceAtPos (const csVector3& force,
    00550     const csVector3& pos) = 0;
    00555   virtual void AddRelForceAtRelPos (const csVector3& force,
    00556     const csVector3& pos) = 0;
    00557
    00559   virtual const csVector3 GetForce () const = 0;
    00561   virtual const csVector3 GetTorque () const = 0;
    00562
    00563   /*
    00565   virtual const csVector3& GetRelForce () const = 0;
    00567   virtual const csVector3& GetRelTorque () const = 0;
    00568   */
    00569
    00570   /*
    00572   virtual int GetJointCount () const = 0;
    00573   */
    00574
    00576   virtual void AttachMesh (iMeshWrapper* mesh) = 0;
    00578   virtual iMeshWrapper* GetAttachedMesh () = 0;
    00580   virtual void AttachLight (iLight* light) = 0;
    00582   virtual iLight* GetAttachedLight () = 0;
    00584   virtual void AttachCamera (iCamera* camera) = 0;
    00586   virtual iCamera* GetAttachedCamera () = 0;
    00587
    00592   virtual void SetMoveCallback (iDynamicsMoveCallback* cb) = 0;
    00597   virtual void SetCollisionCallback (iDynamicsCollisionCallback* cb) = 0;
    00598
    00600   virtual void Collision (iRigidBody *other) = 0;
    00601
    00603   virtual void Update () = 0;
    00604
    00606   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
    00607
    00609   virtual int GetColliderCount () = 0;
    00610 };
    00611
    00612 enum csColliderGeometryType
    00613 {
    00614   NO_GEOMETRY,
    00615   BOX_COLLIDER_GEOMETRY,
    00616   PLANE_COLLIDER_GEOMETRY,
    00617   TRIMESH_COLLIDER_GEOMETRY,
    00618   CYLINDER_COLLIDER_GEOMETRY,
    00619   SPHERE_COLLIDER_GEOMETRY
    00620 };
    00621
    00622
    00623 SCF_VERSION (iDynamicsColliderCollisionCallback, 0, 0, 1);
    00624
    00634 struct iDynamicsColliderCollisionCallback : public iBase
    00635 {
    00636   virtual void Execute (iDynamicsSystemCollider *thiscollider,
    00637     iDynamicsSystemCollider *othercollider) = 0;
    00638   virtual void Execute (iDynamicsSystemCollider *thiscollider,
    00639     iRigidBody *otherbody) = 0;
    00640 };
    00641
    00642
    00643 struct iGeneralFactoryState;
    00644 class csBox3;
    00645 class csSphere;
    00646 class csReversibleTransform;
    00647
    00667 struct iDynamicsSystemCollider : public virtual iBase
    00668 {
    00669   SCF_INTERFACE (iDynamicsSystemCollider, 0, 0, 1);
    00670
    00672   virtual bool CreateSphereGeometry (const csSphere& sphere) = 0;
    00673
    00675   virtual bool CreatePlaneGeometry (const csPlane3& plane) = 0;
    00676
    00678   virtual bool CreateMeshGeometry (iMeshWrapper *mesh) = 0;
    00679
    00681   virtual bool CreateBoxGeometry (const csVector3& box_size) = 0;
    00682
    00684   virtual bool CreateCCylinderGeometry (float length, float radius) = 0;
    00685
    00686   //FIXME: This should be implememented, but it is not so obvious - it
    00687   //should be valid also for static colliders.
    00688   virtual void SetCollisionCallback (
    00689         iDynamicsColliderCollisionCallback* cb) = 0;
    00690
    00692   virtual void SetFriction (float friction) = 0;
    00693
    00695   virtual void SetSoftness (float softness) = 0;
    00696
    00702   virtual void SetDensity (float density) = 0;
    00703
    00705   virtual void SetElasticity (float elasticity) = 0;
    00706
    00708   virtual float GetFriction () = 0;
    00709
    00711   virtual float GetSoftness () = 0;
    00712
    00714   virtual float GetDensity () = 0;
    00715
    00717   virtual float GetElasticity () = 0;
    00718
    00720   virtual void FillWithColliderGeometry (
    00721         csRef<iGeneralFactoryState> genmesh_fact) = 0;
    00722
    00724   virtual csColliderGeometryType GetGeometryType () = 0;
    00725
    00727   virtual csOrthoTransform GetTransform () = 0;
    00728
    00733   virtual csOrthoTransform GetLocalTransform () = 0;
    00734
    00739   virtual void SetTransform (const csOrthoTransform& trans) = 0;
    00740
    00745   virtual bool GetBoxGeometry (csVector3& size) = 0;
    00746
    00751   virtual bool GetSphereGeometry (csSphere& sphere) = 0;
    00752
    00757   virtual bool GetPlaneGeometry (csPlane3& plane) = 0;
    00758
    00763   virtual bool GetCylinderGeometry (float& length, float& radius) = 0;
    00764
    00770   virtual void MakeStatic () = 0;
    00771
    00776   virtual void MakeDynamic () = 0;
    00777
    00779   virtual bool IsStatic () = 0;
    00780 };
    00781
    00782 SCF_VERSION (iJoint, 0, 0, 1);
    00783
    00797 struct iJoint : public iBase
    00798 {
    00800   virtual void Attach (iRigidBody* body1, iRigidBody* body2) = 0;
    00802   virtual csRef<iRigidBody> GetAttachedBody (int body) = 0;
    00808   virtual void SetTransform (const csOrthoTransform &trans) = 0;
    00810   virtual csOrthoTransform GetTransform () = 0;
    00818   virtual void SetTransConstraints (bool X, bool Y, bool Z) = 0;
    00820   virtual bool IsXTransConstrained () = 0;
    00822   virtual bool IsYTransConstrained () = 0;
    00824   virtual bool IsZTransConstrained () = 0;
    00826   virtual void SetMinimumDistance (const csVector3 &min) = 0;
    00828   virtual csVector3 GetMinimumDistance () = 0;
    00830   virtual void SetMaximumDistance (const csVector3 &max) = 0;
    00832   virtual csVector3 GetMaximumDistance () = 0;
    00838   virtual void SetRotConstraints (bool X, bool Y, bool Z) = 0;
    00840   virtual bool IsXRotConstrained () = 0;
    00842   virtual bool IsYRotConstrained () = 0;
    00844   virtual bool IsZRotConstrained () = 0;
    00846   virtual void SetMinimumAngle (const csVector3 &min) = 0;
    00848   virtual csVector3 GetMinimumAngle () = 0;
    00850   virtual void SetMaximumAngle (const csVector3 &max) = 0;
    00852   virtual csVector3 GetMaximumAngle () = 0;
    00853
    00859   virtual void SetBounce (const csVector3 & bounce ) = 0;
    00861   virtual csVector3 GetBounce () = 0;
    00863   virtual void SetDesiredVelocity (const csVector3 & velocity ) = 0;
    00864   virtual csVector3 GetDesiredVelocity () = 0;
    00866   virtual void SetMaxForce (const csVector3 & maxForce ) = 0;
    00867   virtual csVector3 GetMaxForce () = 0;
    00868 };
    00869
    00870 #endif // __CS_IVARIA_DYNAMICS_H__
    00871