1 | /*! |
---|
2 | * @file physics_interface.h |
---|
3 | * a physics interface simulating a body with a mass |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _PHYSICS_INTERFACE_H |
---|
7 | #define _PHYSICS_INTERFACE_H |
---|
8 | |
---|
9 | #include "vector.h" |
---|
10 | #include "base_object.h" |
---|
11 | |
---|
12 | #ifndef NULL |
---|
13 | #define NULL 0 //!< NULL |
---|
14 | #endif |
---|
15 | |
---|
16 | // Forward Declaration |
---|
17 | class Field; |
---|
18 | |
---|
19 | //! A Physics interface |
---|
20 | /** |
---|
21 | The PhysicsInterface is an extension to Any other object, |
---|
22 | that can be used to turn it to be Physcally animated. |
---|
23 | Still you have to connect fields. |
---|
24 | IMPORTANT is, that when using PNodes this baseclass is ok. |
---|
25 | BUT, when using any other class that does not by itself implement |
---|
26 | PNode you __MUST__ implement all the virtual functions by your own |
---|
27 | */ |
---|
28 | class PhysicsInterface : virtual public BaseObject |
---|
29 | { |
---|
30 | public: |
---|
31 | PhysicsInterface(); |
---|
32 | virtual ~PhysicsInterface(); |
---|
33 | /** @param mass the mass to set for this node. */ |
---|
34 | inline void setMass( float mass ) { this->mass = mass; }; |
---|
35 | /** @returns the mass of the node. */ |
---|
36 | inline float getMass( void ) const { return mass; }; |
---|
37 | /** @returns the mass of this node plus all its children (only valid for PNodes). */ |
---|
38 | inline float getTotalMass( void ) const { return mass + massChildren; }; |
---|
39 | |
---|
40 | virtual void applyField(Field* field); |
---|
41 | virtual void tickPhys( float dt ); |
---|
42 | |
---|
43 | protected: |
---|
44 | virtual void recalcMass(); |
---|
45 | |
---|
46 | |
---|
47 | private: |
---|
48 | float mass; //!< Mass of this object |
---|
49 | float massChildren; //!< Sum of the masses of the children nodes |
---|
50 | |
---|
51 | Vector forceSum; //!< Total central force for this tick |
---|
52 | Quaternion momentumSum; //!< Total momentum in this tick |
---|
53 | bool bForceApplied; //!< If a force was applied to this object. |
---|
54 | }; |
---|
55 | |
---|
56 | #endif /* _PHYSICS_INTERFACE_H */ |
---|