ivaria/dynamics.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

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

- 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 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
    00052 struct iDynamicsStepCallback : public virtual iBase
    00053 {
    00054   SCF_INTERFACE (iDynamicsStepCallback, 0, 0, 1);
    00055
    00060   virtual void Step (float stepsize) = 0;
    00061 };
    00062
    00078 struct iDynamics : public virtual iBase
    00079 {
    00080   SCF_INTERFACE(iDynamics,0,0,2);
    00082   virtual csPtr<iDynamicSystem> CreateSystem () = 0;
    00083
    00085   virtual void RemoveSystem (iDynamicSystem* system) = 0;
    00086
    00088   virtual void RemoveSystems () = 0;
    00089
    00091   virtual iDynamicSystem* FindSystem (const char *name) = 0;
    00092
    00100   virtual void Step (float stepsize) = 0;
    00101
    00105   virtual void AddStepCallback (iDynamicsStepCallback *callback) = 0;
    00106
    00110   virtual void RemoveStepCallback (iDynamicsStepCallback *callback) = 0;
    00111 };
    00112
    00113 struct iDynamicsSystemCollider;
    00114
    00129 struct iDynamicSystem : public virtual iBase
    00130 {
    00131   SCF_INTERFACE (iDynamicSystem, 0, 0, 4);
    00132
    00134   virtual iObject *QueryObject (void) = 0;
    00136   virtual void SetGravity (const csVector3& v) = 0;
    00138   virtual const csVector3 GetGravity () const = 0;
    00139
    00149   virtual void SetLinearDampener (float d) = 0;
    00150
    00152   virtual float GetLinearDampener () const = 0;
    00153
    00163   virtual void SetRollingDampener (float d) = 0;
    00164
    00166   virtual float GetRollingDampener () const = 0;
    00167
    00173   virtual void EnableAutoDisable (bool enable) = 0;
    00175   virtual bool AutoDisableEnabled () = 0;
    00188   virtual void SetAutoDisableParams (float linear, float angular, int steps,
    00189         float time) = 0;
    00190
    00192   virtual void Step (float stepsize) = 0;
    00193
    00195   virtual csPtr<iRigidBody> CreateBody () = 0;
    00196
    00198   virtual void RemoveBody (iRigidBody* body) = 0;
    00199
    00201   virtual iRigidBody *FindBody (const char *name) = 0;
    00202
    00204   virtual iRigidBody *GetBody (unsigned int index) = 0;
    00205
    00207   virtual int GetBodysCount () = 0;
    00208
    00210   virtual csPtr<iBodyGroup> CreateGroup () = 0;
    00211
    00213   virtual void RemoveGroup (iBodyGroup* group) = 0;
    00214
    00216   virtual csPtr<iJoint> CreateJoint () = 0;
    00217
    00219   virtual void RemoveJoint (iJoint* joint) = 0;
    00220
    00222   virtual iDynamicsMoveCallback* GetDefaultMoveCallback () = 0;
    00223
    00238   virtual bool AttachColliderConvexMesh (iMeshWrapper* mesh,
    00239     const csOrthoTransform& trans, float friction,
    00240     float elasticity, float softness = 0.01f) = 0;
    00241
    00259   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
    00260     const csOrthoTransform& trans, float friction,
    00261     float elasticity, float softness = 0.01f) = 0;
    00262
    00278   virtual bool AttachColliderCylinder (float length, float radius,
    00279     const csOrthoTransform& trans, float friction,
    00280     float elasticity, float softness = 0.01f) = 0;
    00281
    00295   virtual bool AttachColliderBox (const csVector3 &size,
    00296     const csOrthoTransform& trans, float friction,
    00297     float elasticity, float softness = 0.01f) = 0;
    00298
    00313   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
    00314     float friction, float elasticity, float softness = 0.01f) = 0;
    00315
    00328   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
    00329     float elasticity, float softness = 0.01f) = 0;
    00330
    00332   virtual void DestroyColliders () = 0;
    00333
    00335   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
    00336
    00338   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
    00339
    00345   virtual csRef<iDynamicsSystemCollider> CreateCollider () = 0;
    00346
    00348   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
    00349
    00351   virtual int GetColliderCount () = 0;
    00352
    00370   virtual bool AttachColliderCapsule (float length, float radius,
    00371     const csOrthoTransform& trans, float friction,
    00372     float elasticity, float softness = 0.01f) = 0;
    00373
    00379   virtual void AddBody (iRigidBody* body) = 0;
    00380
    00384   virtual void AddJoint (iJoint* joint) = 0;
    00385 };
    00386
    00398 struct iDynamicsMoveCallback : public virtual iBase
    00399 {
    00400   SCF_INTERFACE (iDynamicsMoveCallback, 0, 0, 1);
    00401
    00403   virtual void Execute (iMeshWrapper* mesh, csOrthoTransform& t) = 0;
    00404
    00406   virtual void Execute (iLight* light, csOrthoTransform& t) = 0;
    00407
    00409   virtual void Execute (iCamera* camera, csOrthoTransform& t) = 0;
    00410
    00417   virtual void Execute (csOrthoTransform& t) = 0;
    00418 };
    00419
    00430 struct iDynamicsCollisionCallback : public virtual iBase
    00431 {
    00432   SCF_INTERFACE (iDynamicsCollisionCallback, 0, 0, 2);
    00433
    00442   virtual void Execute (iRigidBody *thisbody, iRigidBody *otherbody,
    00443       const csVector3& pos, const csVector3& normal, float depth) = 0;
    00444 };
    00445
    00462 struct iBodyGroup : public virtual iBase
    00463 {
    00464   SCF_INTERFACE (iBodyGroup, 0, 1, 0);
    00465
    00467   virtual void AddBody (iRigidBody *body) = 0;
    00469   virtual void RemoveBody (iRigidBody *body) = 0;
    00471   virtual bool BodyInGroup (iRigidBody *body) = 0;
    00472 };
    00473
    00491 struct iRigidBody : public virtual iBase
    00492 {
    00493   SCF_INTERFACE (iRigidBody, 0, 0, 3);
    00494
    00496   virtual iObject *QueryObject (void) = 0;
    00503   virtual bool MakeStatic (void) = 0;
    00511   virtual bool MakeDynamic (void) = 0;
    00519   virtual bool IsStatic (void) = 0;
    00523   virtual bool Disable (void) = 0;
    00525   virtual bool Enable (void) = 0;
    00527   virtual bool IsEnabled (void) = 0;
    00528
    00530   virtual csRef<iBodyGroup> GetGroup (void) = 0;
    00531
    00548   virtual bool AttachColliderConvexMesh (iMeshWrapper* mesh,
    00549     const csOrthoTransform& trans, float friction, float density,
    00550     float elasticity, float softness = 0.01f) = 0;
    00551
    00571   virtual bool AttachColliderMesh (iMeshWrapper* mesh,
    00572     const csOrthoTransform& trans, float friction, float density,
    00573     float elasticity, float softness = 0.01f) = 0;
    00574
    00591   virtual bool AttachColliderCylinder (float length, float radius,
    00592     const csOrthoTransform& trans, float friction, float density,
    00593     float elasticity, float softness = 0.01f) = 0;
    00594
    00610   virtual bool AttachColliderBox (const csVector3 &size,
    00611     const csOrthoTransform& trans, float friction, float density,
    00612     float elasticity, float softness = 0.01f) = 0;
    00613
    00629   virtual bool AttachColliderSphere (float radius, const csVector3 &offset,
    00630     float friction, float density, float elasticity,
    00631     float softness = 0.01f) = 0;
    00632
    00647   virtual bool AttachColliderPlane (const csPlane3 &plane, float friction,
    00648     float density, float elasticity, float softness = 0.01f) = 0;
    00649
    00656   virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0;
    00657
    00659   virtual void DestroyColliders () = 0;
    00660
    00662   virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0;
    00663
    00665   virtual void SetPosition (const csVector3& trans) = 0;
    00667   virtual const csVector3 GetPosition () const = 0;
    00669   virtual void SetOrientation (const csMatrix3& trans) = 0;
    00671   virtual const csMatrix3 GetOrientation () const = 0;
    00673   virtual void SetTransform (const csOrthoTransform& trans) = 0;
    00675   virtual const csOrthoTransform GetTransform () const = 0;
    00677   virtual void SetLinearVelocity (const csVector3& vel) = 0;
    00679   virtual const csVector3 GetLinearVelocity () const = 0;
    00681   virtual void SetAngularVelocity (const csVector3& vel) = 0;
    00683   virtual const csVector3 GetAngularVelocity () const = 0;
    00684
    00696   virtual void SetProperties (float mass, const csVector3& center,
    00697     const csMatrix3& inertia) = 0;
    00699   virtual void GetProperties (float* mass, csVector3* center,
    00700     csMatrix3* inertia) = 0;
    00702   virtual float GetMass () = 0;
    00704   virtual csVector3 GetCenter () = 0;
    00706   virtual csMatrix3 GetInertia () = 0;
    00707
    00713   virtual void AdjustTotalMass (float targetmass) = 0;
    00714
    00716   virtual void AddForce (const csVector3& force) = 0;
    00718   virtual void AddTorque (const csVector3& force) = 0;
    00720   virtual void AddRelForce (const csVector3& force) = 0;
    00722   virtual void AddRelTorque (const csVector3& force) = 0 ;
    00727   virtual void AddForceAtPos (const csVector3& force, const csVector3& pos) = 0;
    00732   virtual void AddForceAtRelPos (const csVector3& force,
    00733     const csVector3& pos) = 0;
    00738   virtual void AddRelForceAtPos (const csVector3& force,
    00739     const csVector3& pos) = 0;
    00744   virtual void AddRelForceAtRelPos (const csVector3& force,
    00745     const csVector3& pos) = 0;
    00746
    00748   virtual const csVector3 GetForce () const = 0;
    00750   virtual const csVector3 GetTorque () const = 0;
    00751
    00752   /*
    00754   virtual const csVector3& GetRelForce () const = 0;
    00756   virtual const csVector3& GetRelTorque () const = 0;
    00757   */
    00758
    00759   /*
    00761   virtual int GetJointCount () const = 0;
    00762   */
    00763
    00765   virtual void AttachMesh (iMeshWrapper* mesh) = 0;
    00767   virtual iMeshWrapper* GetAttachedMesh () = 0;
    00769   virtual void AttachLight (iLight* light) = 0;
    00771   virtual iLight* GetAttachedLight () = 0;
    00773   virtual void AttachCamera (iCamera* camera) = 0;
    00775   virtual iCamera* GetAttachedCamera () = 0;
    00776
    00781   virtual void SetMoveCallback (iDynamicsMoveCallback* cb) = 0;
    00786   virtual void SetCollisionCallback (iDynamicsCollisionCallback* cb) = 0;
    00787
    00795   virtual void Collision (iRigidBody *other, const csVector3& pos,
    00796       const csVector3& normal, float depth) = 0;
    00797
    00799   virtual void Update () = 0;
    00800
    00802   virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0;
    00803
    00805   virtual int GetColliderCount () = 0;
    00806
    00824   virtual bool AttachColliderCapsule (float length, float radius,
    00825     const csOrthoTransform& trans, float friction, float density,
    00826     float elasticity, float softness = 0.01f) = 0;
    00827 };
    00828
    00829 enum csColliderGeometryType
    00830 {
    00831   NO_GEOMETRY,
    00832   BOX_COLLIDER_GEOMETRY,
    00833   PLANE_COLLIDER_GEOMETRY,
    00834   TRIMESH_COLLIDER_GEOMETRY,
    00835   CONVEXMESH_COLLIDER_GEOMETRY,
    00836   CYLINDER_COLLIDER_GEOMETRY,
    00837   CAPSULE_COLLIDER_GEOMETRY,
    00838   SPHERE_COLLIDER_GEOMETRY
    00839 };
    00840
    00841
    00851 struct iDynamicsColliderCollisionCallback : public virtual iBase
    00852 {
    00853   SCF_INTERFACE (iDynamicsColliderCollisionCallback, 0, 0, 1);
    00854
    00858   virtual void Execute (iDynamicsSystemCollider *thiscollider,
    00859     iDynamicsSystemCollider *othercollider) = 0;
    00860
    00864   virtual void Execute (iDynamicsSystemCollider *thiscollider,
    00865     iRigidBody *otherbody) = 0;
    00866 };
    00867
    00868
    00869 struct iGeneralFactoryState;
    00870 class csBox3;
    00871 class csSphere;
    00872 class csReversibleTransform;
    00873
    00893 struct iDynamicsSystemCollider : public virtual iBase
    00894 {
    00895   SCF_INTERFACE (iDynamicsSystemCollider, 0, 0, 4);
    00896
    00898   virtual bool CreateSphereGeometry (const csSphere& sphere) = 0;
    00899
    00901   virtual bool CreatePlaneGeometry (const csPlane3& plane) = 0;
    00902
    00904   virtual bool CreateConvexMeshGeometry (iMeshWrapper *mesh) = 0;
    00905
    00913   virtual bool CreateMeshGeometry (iMeshWrapper *mesh) = 0;
    00914
    00916   virtual bool CreateBoxGeometry (const csVector3& box_size) = 0;
    00917
    00919   virtual bool CreateCapsuleGeometry (float length, float radius) = 0;
    00920
    00922   virtual bool CreateCylinderGeometry (float length, float radius) = 0;
    00923
    00924   //FIXME: This should be implememented, but it is not so obvious - it
    00925   //should be valid also for static colliders.
    00926   virtual void SetCollisionCallback (
    00927         iDynamicsColliderCollisionCallback* cb) = 0;
    00928
    00930   virtual void SetFriction (float friction) = 0;
    00931
    00933   virtual void SetSoftness (float softness) = 0;
    00934
    00945   virtual void SetDensity (float density) = 0;
    00946
    00948   virtual void SetElasticity (float elasticity) = 0;
    00949
    00951   virtual float GetFriction () = 0;
    00952
    00954   virtual float GetSoftness () = 0;
    00955
    00957   virtual float GetDensity () = 0;
    00958
    00960   virtual float GetElasticity () = 0;
    00961
    00963   virtual void FillWithColliderGeometry (
    00964         csRef<iGeneralFactoryState> genmesh_fact) = 0;
    00965
    00967   virtual csColliderGeometryType GetGeometryType () = 0;
    00968
    00970   virtual csOrthoTransform GetTransform () = 0;
    00971
    00976   virtual csOrthoTransform GetLocalTransform () = 0;
    00977
    00982   virtual void SetTransform (const csOrthoTransform& trans) = 0;
    00983
    00988   virtual bool GetBoxGeometry (csVector3& size) = 0;
    00989
    00994   virtual bool GetSphereGeometry (csSphere& sphere) = 0;
    00995
    01000   virtual bool GetPlaneGeometry (csPlane3& plane) = 0;
    01001
    01006   virtual bool GetCylinderGeometry (float& length, float& radius) = 0;
    01007
    01013   virtual void MakeStatic () = 0;
    01014
    01019   virtual void MakeDynamic () = 0;
    01020
    01022   virtual bool IsStatic () = 0;
    01023
    01028   virtual bool GetCapsuleGeometry (float& length, float& radius) = 0;
    01029
    01045   virtual bool GetMeshGeometry (csVector3*& vertices, size_t& vertexCount,
    01046                                 int*& indices, size_t& triangleCount) = 0;
    01047
    01063   virtual bool GetConvexMeshGeometry (csVector3*& vertices, size_t& vertexCount,
    01064                                       int*& indices, size_t& triangleCount) = 0;
    01065 };
    01066
    01079 struct iJoint : public virtual iBase
    01080 {
    01081   SCF_INTERFACE (iJoint, 0, 0, 1);
    01082
    01087   virtual void Attach (iRigidBody* body1, iRigidBody* body2, bool force_update = true) = 0;
    01089   virtual csRef<iRigidBody> GetAttachedBody (int body) = 0;
    01098   virtual void SetTransform (const csOrthoTransform &trans, bool force_update = true) = 0;
    01100   virtual csOrthoTransform GetTransform () = 0;
    01109   virtual void SetTransConstraints (bool X, bool Y, bool Z, bool force_update = true) = 0;
    01111   virtual bool IsXTransConstrained () = 0;
    01113   virtual bool IsYTransConstrained () = 0;
    01115   virtual bool IsZTransConstrained () = 0;
    01120   virtual void SetMinimumDistance (const csVector3 &min, bool force_update = true) = 0;
    01122   virtual csVector3 GetMinimumDistance () = 0;
    01127   virtual void SetMaximumDistance (const csVector3 &max, bool force_update = true) = 0;
    01129   virtual csVector3 GetMaximumDistance () = 0;
    01138   virtual void SetRotConstraints (bool X, bool Y, bool Z, bool force_update = true) = 0;
    01140   virtual bool IsXRotConstrained () = 0;
    01142   virtual bool IsYRotConstrained () = 0;
    01144   virtual bool IsZRotConstrained () = 0;
    01149   virtual void SetMinimumAngle (const csVector3 &min, bool force_update = true) = 0;
    01151   virtual csVector3 GetMinimumAngle () = 0;
    01156   virtual void SetMaximumAngle (const csVector3 &max, bool force_update = true) = 0;
    01158   virtual csVector3 GetMaximumAngle () = 0;
    01159
    01160   //Motor parameters
    01161
    01167   virtual void SetBounce (const csVector3 & bounce, bool force_update = true) = 0;
    01169   virtual csVector3 GetBounce () = 0;
    01174   virtual void SetDesiredVelocity (const csVector3 &velocity, bool force_update = true) = 0;
    01176   virtual csVector3 GetDesiredVelocity () = 0;
    01181   virtual void SetMaxForce (const csVector3 & maxForce, bool force_update = true) = 0;
    01183   virtual csVector3 GetMaxForce () = 0;
    01188   virtual void SetAngularConstraintAxis (const csVector3 &axis, int body, bool force_update = true) = 0;
    01190   virtual csVector3 GetAngularConstraintAxis (int body) = 0;
    01195   virtual bool RebuildJoint () = 0;
    01196
    01197 };
    01198
    01199 #endif // __CS_IVARIA_DYNAMICS_H__
    01200