Changeset 4376 in orxonox.OLD for orxonox/trunk/src/lib/physics
- Timestamp:
- May 29, 2005, 12:30:54 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib/physics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/physics/physics_interface.cc
r4375 r4376 21 21 22 22 #include "physics_interface.h" 23 24 #include "p_node.h" 25 23 26 #include "list.h" 24 27 #include "string.h" … … 33 36 PhysicsInterface::PhysicsInterface () 34 37 { 35 this->setClassName ("PhysicsInterface");38 // this->setClassName ("PhysicsInterface"); 36 39 this->mass = 0; 37 40 this->massChildren = 0; … … 49 52 } 50 53 54 /** 55 \brief recalculates the total mass of all the children of this node 56 57 (only availiable for PNodes) 58 */ 51 59 void PhysicsInterface::recalcMass() 52 60 { 53 float massSum = 0; 54 55 tIterator<PNode>* iterator = this->children->getIterator(); 56 PNode* pn = iterator->nextElement(); 57 while( pn != NULL) 61 PNode* massCalcPNode = dynamic_cast<PNode*>(this); //! \todo not sure if this will work .... 62 float massSum = 0; 63 64 tIterator<PNode>* iterator = massCalcPNode->children->getIterator(); 65 PNode* pn = iterator->nextElement(); 66 while( pn != NULL) 58 67 { 59 60 61 62 68 // todo: find out if children are PhysicsInterface in an efficient way 69 if (strcmp( pn->getClassName(), "PhysicsInterface")) { 70 massSum += ((PhysicsInterface*)pn)->getTotalMass(); 71 } 63 72 pn = iterator->nextElement(); 64 73 } 65 74 delete iterator; 66 75 67 68 69 if (strcmp(parent->getClassName(), "PhysicsInterface"))70 ((PhysicsInterface*)parent)->recalcMass();71 72 73 76 if (massSum != this->massChildren ) { 77 this->massChildren = massSum; 78 if (strcmp( massCalcPNode->parent->getClassName(), "PhysicsInterface")) 79 ((PhysicsInterface*)massCalcPNode->parent)->recalcMass(); 80 } else { 81 this->massChildren = massSum; 82 } 74 83 } 75 84 76 85 77 void PhysicsInterface::a ddForce( Vector force )86 void PhysicsInterface::applyForce( Vector force ) 78 87 { 79 88 this->forceSum += force; 80 89 } 81 90 82 void PhysicsInterface:: addForce(Vector force, Vector grip)91 void PhysicsInterface::tickPhys( float dt ) 83 92 { 84 // add central force 85 forceSum += force; 86 // add momentum 87 // todo: some vector math 93 Vector acc = this->forceSum / ( this->massChildren + this->mass ); 94 // todo: introduce kinematics 88 95 } 89 90 void PhysicsInterface::tick( float dt )91 {92 Vector acc = forceSum / ( massChildren + mass );93 // todo: introduce kinematics94 } -
orxonox/trunk/src/lib/physics/physics_interface.h
r4375 r4376 7 7 #define _PHYSICS_INTERFACE_H 8 8 9 #include " p_node.h"9 #include "vector.h" 10 10 11 11 //! A Physics interface … … 13 13 here can be some longer description of this class 14 14 */ 15 class PhysicsInterface : public PNode{15 class PhysicsInterface { 16 16 17 17 public: 18 18 PhysicsInterface(); 19 19 virtual ~PhysicsInterface(); 20 21 inline void setMass( float mass ) { this->mass = mass; }; //!< Set the mass of this node 22 inline float getMass( void ) const { return mass; }; //!< Get the mass of this node 23 inline float getTotalMass( void ) const { return mass + massChildren; }; //!< Get the sum of the masses of this node and all subnodes 24 void addForce( Vector force ); //!< Add a central force on this rigid body 25 void addForce( Vector force, Vector grip ); //!< Add a decentral force on this rigid body 26 void tick( float dt ); //!< Update kinematics, reset force sum 20 /** \param mass the mass to set for this node. */ 21 inline void setMass( float mass ) { this->mass = mass; }; 22 /** \returns the mass of the node. */ 23 inline float getMass( void ) const { return mass; }; 24 /** \returns the mass of this node plus all its children (only valid for PNodes). */ 25 inline float getTotalMass( void ) const { return mass + massChildren; }; 26 27 virtual void applyForce( Vector force ); //!< Add a central force on this rigid body 28 virtual void tickPhys( float dt ); //!< Update kinematics, reset force sum 27 29 28 30 protected: 29 void recalcMass(); //!< Recalculate the mass of the children 30 float mass; //!< Mass of this node 31 void recalcMass(); 32 33 34 private: 35 float mass; //!< Mass of this object 31 36 float massChildren; //!< Sum of the masses of the children nodes 32 Vector forceSum; 37 Vector forceSum; //!< Total central force for this tick 33 38 Quaternion momentumSum; //!< Total momentum in this tick 34 35 private:36 39 37 40
Note: See TracChangeset
for help on using the changeset viewer.