Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/physics/physics_interface.cc @ 4376

Last change on this file since 4376 was 4376, checked in by bensch, 19 years ago

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

File size: 2.1 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer: Benjamin Grauer
16   
17   bensch: renamed the file
18*/
19
20#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS
21
22#include "physics_interface.h"
23
24#include "p_node.h"
25
26#include "list.h"
27#include "string.h"
28#include "stdincl.h"
29
30using namespace std;
31
32
33/**
34   \brief standard constructor
35*/
36PhysicsInterface::PhysicsInterface () 
37{
38  //   this->setClassName ("PhysicsInterface");
39   this->mass = 0;
40   this->massChildren = 0;
41   this->forceSum = Vector(0, 0, 0);
42}
43
44
45/**
46   \brief standard deconstructor
47
48*/
49PhysicsInterface::~PhysicsInterface () 
50{
51  // delete what has to be deleted here
52}
53
54/**
55   \brief recalculates the total mass of all the children of this node
56
57   (only availiable for PNodes)
58*/
59void PhysicsInterface::recalcMass()
60{
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) 
67    { 
68      // todo: find out if children are PhysicsInterface in an efficient way
69      if (strcmp( pn->getClassName(), "PhysicsInterface")) {
70        massSum += ((PhysicsInterface*)pn)->getTotalMass();
71      }
72      pn = iterator->nextElement();
73    }
74  delete iterator;
75       
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  }
83}
84       
85       
86void PhysicsInterface::applyForce( Vector force )
87{
88  this->forceSum += force;
89}
90
91void PhysicsInterface::tickPhys( float dt )
92{
93  Vector acc = this->forceSum / ( this->massChildren + this->mass );
94  // todo: introduce kinematics
95}
Note: See TracBrowser for help on using the repository browser.