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 { 00313 virtual void Execute (iRigidBody *thisbody, iRigidBody *otherbody, 00314 const csVector3& pos, const csVector3& normal, float depth) = 0; 00315 }; 00316 00317 SCF_VERSION (iBodyGroup, 0, 0, 1); 00318 00335 struct iBodyGroup : public iBase 00336 { 00338 virtual void AddBody (iRigidBody *body) = 0; 00340 virtual void RemoveBody (iRigidBody *body) = 0; 00342 virtual bool BodyInGroup (iRigidBody *body) = 0; 00343 }; 00344 00360 struct iRigidBody : public virtual iBase 00361 { 00362 SCF_INTERFACE (iRigidBody, 0, 0, 2); 00363 00365 virtual iObject *QueryObject (void) = 0; 00371 virtual bool MakeStatic (void) = 0; 00373 virtual bool MakeDynamic (void) = 0; 00375 virtual bool IsStatic (void) = 0; 00379 virtual bool Disable (void) = 0; 00381 virtual bool Enable (void) = 0; 00383 virtual bool IsEnabled (void) = 0; 00384 00386 virtual csRef<iBodyGroup> GetGroup (void) = 0; 00387 00403 virtual bool AttachColliderMesh (iMeshWrapper* mesh, 00404 const csOrthoTransform& trans, float friction, float density, 00405 float elasticity, float softness = 0.01f) = 0; 00406 00423 virtual bool AttachColliderCylinder (float length, float radius, 00424 const csOrthoTransform& trans, float friction, float density, 00425 float elasticity, float softness = 0.01f) = 0; 00426 00442 virtual bool AttachColliderBox (const csVector3 &size, 00443 const csOrthoTransform& trans, float friction, float density, 00444 float elasticity, float softness = 0.01f) = 0; 00445 00461 virtual bool AttachColliderSphere (float radius, const csVector3 &offset, 00462 float friction, float density, float elasticity, 00463 float softness = 0.01f) = 0; 00464 00479 virtual bool AttachColliderPlane (const csPlane3 &plane, float friction, 00480 float density, float elasticity, float softness = 0.01f) = 0; 00481 00488 virtual void AttachCollider (iDynamicsSystemCollider* collider) = 0; 00489 00491 virtual void DestroyColliders () = 0; 00492 00494 virtual void DestroyCollider (iDynamicsSystemCollider* collider) = 0; 00495 00497 virtual void SetPosition (const csVector3& trans) = 0; 00499 virtual const csVector3 GetPosition () const = 0; 00501 virtual void SetOrientation (const csMatrix3& trans) = 0; 00503 virtual const csMatrix3 GetOrientation () const = 0; 00505 virtual void SetTransform (const csOrthoTransform& trans) = 0; 00507 virtual const csOrthoTransform GetTransform () const = 0; 00509 virtual void SetLinearVelocity (const csVector3& vel) = 0; 00511 virtual const csVector3 GetLinearVelocity () const = 0; 00513 virtual void SetAngularVelocity (const csVector3& vel) = 0; 00515 virtual const csVector3 GetAngularVelocity () const = 0; 00516 00518 virtual void SetProperties (float mass, const csVector3& center, 00519 const csMatrix3& inertia) = 0; 00521 virtual void GetProperties (float* mass, csVector3* center, 00522 csMatrix3* inertia) = 0; 00524 virtual float GetMass () = 0; 00526 virtual csVector3 GetCenter () = 0; 00528 virtual csMatrix3 GetInertia () = 0; 00529 00531 virtual void AdjustTotalMass (float targetmass) = 0; 00532 00534 virtual void AddForce (const csVector3& force) = 0; 00536 virtual void AddTorque (const csVector3& force) = 0; 00538 virtual void AddRelForce (const csVector3& force) = 0; 00540 virtual void AddRelTorque (const csVector3& force) = 0 ; 00545 virtual void AddForceAtPos (const csVector3& force, const csVector3& pos) = 0; 00550 virtual void AddForceAtRelPos (const csVector3& force, 00551 const csVector3& pos) = 0; 00556 virtual void AddRelForceAtPos (const csVector3& force, 00557 const csVector3& pos) = 0; 00562 virtual void AddRelForceAtRelPos (const csVector3& force, 00563 const csVector3& pos) = 0; 00564 00566 virtual const csVector3 GetForce () const = 0; 00568 virtual const csVector3 GetTorque () const = 0; 00569 00570 /* 00572 virtual const csVector3& GetRelForce () const = 0; 00574 virtual const csVector3& GetRelTorque () const = 0; 00575 */ 00576 00577 /* 00579 virtual int GetJointCount () const = 0; 00580 */ 00581 00583 virtual void AttachMesh (iMeshWrapper* mesh) = 0; 00585 virtual iMeshWrapper* GetAttachedMesh () = 0; 00587 virtual void AttachLight (iLight* light) = 0; 00589 virtual iLight* GetAttachedLight () = 0; 00591 virtual void AttachCamera (iCamera* camera) = 0; 00593 virtual iCamera* GetAttachedCamera () = 0; 00594 00599 virtual void SetMoveCallback (iDynamicsMoveCallback* cb) = 0; 00604 virtual void SetCollisionCallback (iDynamicsCollisionCallback* cb) = 0; 00605 00612 virtual void Collision (iRigidBody *other, const csVector3& pos, 00613 const csVector3& normal, float depth) = 0; 00614 00616 virtual void Update () = 0; 00617 00619 virtual csRef<iDynamicsSystemCollider> GetCollider (unsigned int index) = 0; 00620 00622 virtual int GetColliderCount () = 0; 00623 }; 00624 00625 enum csColliderGeometryType 00626 { 00627 NO_GEOMETRY, 00628 BOX_COLLIDER_GEOMETRY, 00629 PLANE_COLLIDER_GEOMETRY, 00630 TRIMESH_COLLIDER_GEOMETRY, 00631 CYLINDER_COLLIDER_GEOMETRY, 00632 SPHERE_COLLIDER_GEOMETRY 00633 }; 00634 00635 00636 SCF_VERSION (iDynamicsColliderCollisionCallback, 0, 0, 1); 00637 00647 struct iDynamicsColliderCollisionCallback : public iBase 00648 { 00649 virtual void Execute (iDynamicsSystemCollider *thiscollider, 00650 iDynamicsSystemCollider *othercollider) = 0; 00651 virtual void Execute (iDynamicsSystemCollider *thiscollider, 00652 iRigidBody *otherbody) = 0; 00653 }; 00654 00655 00656 struct iGeneralFactoryState; 00657 class csBox3; 00658 class csSphere; 00659 class csReversibleTransform; 00660 00680 struct iDynamicsSystemCollider : public virtual iBase 00681 { 00682 SCF_INTERFACE (iDynamicsSystemCollider, 0, 0, 1); 00683 00685 virtual bool CreateSphereGeometry (const csSphere& sphere) = 0; 00686 00688 virtual bool CreatePlaneGeometry (const csPlane3& plane) = 0; 00689 00691 virtual bool CreateMeshGeometry (iMeshWrapper *mesh) = 0; 00692 00694 virtual bool CreateBoxGeometry (const csVector3& box_size) = 0; 00695 00697 virtual bool CreateCCylinderGeometry (float length, float radius) = 0; 00698 00699 //FIXME: This should be implememented, but it is not so obvious - it 00700 //should be valid also for static colliders. 00701 virtual void SetCollisionCallback ( 00702 iDynamicsColliderCollisionCallback* cb) = 0; 00703 00705 virtual void SetFriction (float friction) = 0; 00706 00708 virtual void SetSoftness (float softness) = 0; 00709 00715 virtual void SetDensity (float density) = 0; 00716 00718 virtual void SetElasticity (float elasticity) = 0; 00719 00721 virtual float GetFriction () = 0; 00722 00724 virtual float GetSoftness () = 0; 00725 00727 virtual float GetDensity () = 0; 00728 00730 virtual float GetElasticity () = 0; 00731 00733 virtual void FillWithColliderGeometry ( 00734 csRef<iGeneralFactoryState> genmesh_fact) = 0; 00735 00737 virtual csColliderGeometryType GetGeometryType () = 0; 00738 00740 virtual csOrthoTransform GetTransform () = 0; 00741 00746 virtual csOrthoTransform GetLocalTransform () = 0; 00747 00752 virtual void SetTransform (const csOrthoTransform& trans) = 0; 00753 00758 virtual bool GetBoxGeometry (csVector3& size) = 0; 00759 00764 virtual bool GetSphereGeometry (csSphere& sphere) = 0; 00765 00770 virtual bool GetPlaneGeometry (csPlane3& plane) = 0; 00771 00776 virtual bool GetCylinderGeometry (float& length, float& radius) = 0; 00777 00783 virtual void MakeStatic () = 0; 00784 00789 virtual void MakeDynamic () = 0; 00790 00792 virtual bool IsStatic () = 0; 00793 }; 00794 00808 struct iJoint : public virtual iBase 00809 { 00810 SCF_INTERFACE (iJoint, 0, 0, 1); 00811 00813 virtual void Attach (iRigidBody* body1, iRigidBody* body2) = 0; 00815 virtual csRef<iRigidBody> GetAttachedBody (int body) = 0; 00821 virtual void SetTransform (const csOrthoTransform &trans) = 0; 00823 virtual csOrthoTransform GetTransform () = 0; 00831 virtual void SetTransConstraints (bool X, bool Y, bool Z) = 0; 00833 virtual bool IsXTransConstrained () = 0; 00835 virtual bool IsYTransConstrained () = 0; 00837 virtual bool IsZTransConstrained () = 0; 00839 virtual void SetMinimumDistance (const csVector3 &min) = 0; 00841 virtual csVector3 GetMinimumDistance () = 0; 00843 virtual void SetMaximumDistance (const csVector3 &max) = 0; 00845 virtual csVector3 GetMaximumDistance () = 0; 00851 virtual void SetRotConstraints (bool X, bool Y, bool Z) = 0; 00853 virtual bool IsXRotConstrained () = 0; 00855 virtual bool IsYRotConstrained () = 0; 00857 virtual bool IsZRotConstrained () = 0; 00859 virtual void SetMinimumAngle (const csVector3 &min) = 0; 00861 virtual csVector3 GetMinimumAngle () = 0; 00863 virtual void SetMaximumAngle (const csVector3 &max) = 0; 00865 virtual csVector3 GetMaximumAngle () = 0; 00866 00867 //Motor parameters 00868 00874 virtual void SetBounce (const csVector3 & bounce ) = 0; 00876 virtual csVector3 GetBounce () = 0; 00878 virtual void SetDesiredVelocity (const csVector3 &velocity ) = 0; 00879 virtual csVector3 GetDesiredVelocity () = 0; 00881 virtual void SetMaxForce (const csVector3 & maxForce ) = 0; 00882 virtual csVector3 GetMaxForce () = 0; 00884 virtual void SetAngularConstraintAxis (const csVector3 &axis, int body) = 0; 00886 virtual csVector3 GetAngularConstraintAxis (int body) = 0; 00887 00888 }; 00889 00890 #endif // __CS_IVARIA_DYNAMICS_H__ 00891
Generated for Crystal Space by doxygen 1.4.7