Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4376 in orxonox.OLD


Ignore:
Timestamp:
May 29, 2005, 12:30:54 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: started reimplementing the PhysicsInterface-class. This might just get bad :)

Location:
orxonox/trunk/src/lib/physics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/physics/physics_interface.cc

    r4375 r4376  
    2121
    2222#include "physics_interface.h"
     23
     24#include "p_node.h"
     25
    2326#include "list.h"
    2427#include "string.h"
     
    3336PhysicsInterface::PhysicsInterface ()
    3437{
    35   this->setClassName ("PhysicsInterface");
     38  //  this->setClassName ("PhysicsInterface");
    3639   this->mass = 0;
    3740   this->massChildren = 0;
     
    4952}
    5053
     54/**
     55   \brief recalculates the total mass of all the children of this node
     56
     57   (only availiable for PNodes)
     58*/
    5159void PhysicsInterface::recalcMass()
    5260{
    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)
    5867    {
    59         // todo: find out if children are PhysicsInterface in an efficient way
    60         if (strcmp( pn->getClassName(), "PhysicsInterface")) {
    61                         massSum += ((PhysicsInterface*)pn)->getTotalMass();
    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      }
    6372      pn = iterator->nextElement();
    6473    }
    65         delete iterator;
     74  delete iterator;
    6675       
    67         if (massSum != this->massChildren ) {
    68                 this->massChildren = massSum;
    69                 if (strcmp( parent->getClassName(), "PhysicsInterface"))
    70                         ((PhysicsInterface*)parent)->recalcMass();
    71         } else {
    72                 this->massChildren = massSum;
    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  }
    7483}
    7584       
    7685       
    77 void PhysicsInterface::addForce( Vector force )
     86void PhysicsInterface::applyForce( Vector force )
    7887{
    79         forceSum += force;
     88  this->forceSum += force;
    8089}
    8190
    82 void PhysicsInterface::addForce(Vector force, Vector grip)
     91void PhysicsInterface::tickPhys( float dt )
    8392{
    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
    8895}
    89        
    90 void PhysicsInterface::tick( float dt )
    91 {
    92         Vector acc = forceSum / ( massChildren + mass );
    93         // todo: introduce kinematics
    94 }
  • orxonox/trunk/src/lib/physics/physics_interface.h

    r4375 r4376  
    77#define _PHYSICS_INTERFACE_H
    88
    9 #include "p_node.h"
     9#include "vector.h"
    1010
    1111//! A Physics interface
     
    1313   here can be some longer description of this class
    1414*/
    15 class PhysicsInterface : public PNode {
     15class PhysicsInterface {
    1616
    1717 public:
    1818  PhysicsInterface();
    1919  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
    2729
    2830 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
    3136  float massChildren;           //!< Sum of the masses of the children nodes
    32   Vector forceSum;                      //!< Total central force for this tick
     37  Vector forceSum;              //!< Total central force for this tick
    3338  Quaternion momentumSum;       //!< Total momentum in this tick
    34 
    35  private:
    3639       
    3740
Note: See TracChangeset for help on using the changeset viewer.