Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4121 in orxonox.OLD for orxonox/branches/physics/src


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

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

Location:
orxonox/branches/physics/src/util/physics
Files:
2 edited
2 moved

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       
  • orxonox/branches/physics/src/util/physics/i_physics.h

    r3961 r4121  
    11/*!
    22    \file i_physics.h
    3     \brief a physics interface
     3    \brief a physics interface simulating a body with a mass
    44*/
    55
     
    77#define _I_PHYSICS_H
    88
    9 #include "base_object.h"
    10 
    11 
     9#include "p_node.h"
    1210
    1311//! A Physics interface
     
    1513   here can be some longer description of this class
    1614*/
    17 class IPhysics : public BaseObject {
     15class IPhysics : public PNode {
    1816
    1917 public:
    2018  IPhysics();
    2119  virtual ~IPhysics();
     20 
     21  void setMass( float mass );           //!< Set the mass of this node
     22  float getMass( void ) const;          //!< Get the mass of this node
     23  float getTotalMass( void ) const; //!< Get the sum of the masses of this node and all subnodes
     24
     25 protected:
     26  void recalcMass();    //!< Recalculate the mass of the children
     27  float mass;                   //!< Mass of this node
     28  float massChildren;   //!< Sum of the masses of the children nodes
     29 
    2230
    2331 private:
    24 
     32       
    2533
    2634};
  • orxonox/branches/physics/src/util/physics/physics_engine.cc

    r4003 r4121  
    1818#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    1919
    20 #include "proto_class.h"
     20#include "physics_engine.h"
    2121
    2222#include "stdincl.h" // maybe
     
    2929   \todo this constructor is not jet implemented - do it
    3030*/
    31 ProtoClass::ProtoClass ()
     31PhysicsEngine::PhysicsEngine ()
    3232{
    33    this->setClassName ("ProtoClass");
     33   this->setClassName ("PhysicsEngine");
    3434}
    3535
     
    3939
    4040*/
    41 ProtoClass::~ProtoClass ()
     41PhysicsEngine::~PhysicsEngine ()
    4242{
    4343  // delete what has to be deleted here
     
    5151   this is just to show the doxygen abilities (this for example is an extension for a long comment)
    5252*/
    53 bool ProtoClass::doNonSense (int nothing) {}
     53bool PhysicsEngine::doNonSense (int nothing) {}
  • orxonox/branches/physics/src/util/physics/physics_engine.h

    r4003 r4121  
    11/*!
    2     \file proto_class.h
     2    \file physics_engine.h
    33    \brief Definition of the proto class template, used quickly start work
    44    \todo Example: this shows how to use simply add a Marker that here has to be done something.
    55
    6     The Protoclass exists, to help you quikly getting the run for how to develop in orxonox.
     6    The PhysicsEngine exists, to help you quikly getting the run for how to develop in orxonox.
    77    It is an example for the CODING-CONVENTION, and a starting-point for every class.
    88*/
    99
    10 #ifndef _PROTO_CLASS_H
    11 #define _PROTO_CLASS_H
     10#ifndef _PHYSICS_ENGINE_H
     11#define _PHYSICS_ENGINE_H
    1212
    13 #include "what realy has to be included"
    1413#include "base_object.h"
    1514
     
    2423   here can be some longer description of this class
    2524*/
    26 class ProtoClass : public BaseObject {
     25class PhysicsEngine : public BaseObject {
    2726
    2827 public:
    29   ProtoClass();
    30   virtual ~ProtoClass();
     28  PhysicsEngine();
     29  virtual ~PhysicsEngine();
    3130
    3231  bool doNonSense (int nothing);
     
    3736};
    3837
    39 #endif /* _PROTO_CLASS_H */
     38#endif /* _PHYSICS_ENGINE_H */
Note: See TracChangeset for help on using the changeset viewer.