Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2005, 3:01:57 AM (19 years ago)
Author:
buerlia
Message:

orxonox/branches/physics: IPhyics gets a mass..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics/src/util/physics/i_physics.cc

    r3961 r4121  
    1919
    2020#include "i_physics.h"
    21 
     21#include "list.h"
     22#include "string.h"
    2223#include "stdincl.h"
    2324
     
    3132{
    3233   this->setClassName ("IPhysics");
     34   this->mass = 0;
     35   this->massChildren = 0;
    3336}
    3437
     
    4245  // delete what has to be deleted here
    4346}
     47
     48
     49
     50void IPhysics::setMass( float mass )
     51{
     52        this->mass = mass;
     53}
     54
     55float IPhysics::getMass( void ) const
     56{
     57        return this->mass;
     58}
     59
     60float IPhysics::getTotalMass( void ) const
     61{
     62        return (this->mass + this->massChildren);
     63}
     64
     65void IPhysics::recalcMass()
     66{
     67        float massSum = 0;
     68       
     69        tIterator<PNode>* iterator = this->children->getIterator();
     70        PNode* pn = iterator->nextElement();
     71        while( pn != NULL)
     72    {
     73        // todo: find out if children are IPhysics in an efficient way
     74        if (strcmp( pn->getClassName(), "IPhysics")) {
     75                        massSum += ((IPhysics*)pn)->getTotalMass();
     76        }
     77      pn = iterator->nextElement();
     78    }
     79        delete iterator;
     80       
     81        if (massSum != this->massChildren ) {
     82                this->massChildren = massSum;
     83                if (strcmp( parent->getClassName(), "IPhysics"))
     84                        ((IPhysics*)parent)->recalcMass();
     85        } else {
     86                this->massChildren = massSum;
     87        }
     88}
     89       
     90       
Note: See TracChangeset for help on using the changeset viewer.