Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: fields are now time-independant

File size: 2.2 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#include "physics_engine.h"
24
25#include "field.h"
26#include "p_node.h"
27
28#include "list.h"
29#include "string.h"
30#include "stdincl.h"
31
32using namespace std;
33
34
35/**
36   \brief standard constructor
37*/
38PhysicsInterface::PhysicsInterface () 
39{
40  //   this->setClassName ("PhysicsInterface");
41   this->mass = 0;
42   this->massChildren = 0;
43   this->forceSum = Vector(0, 0, 0);
44
45   PhysicsEngine::getInstance()->addPhysicsInterface(this);
46}
47
48
49/**
50   \brief standard deconstructor
51
52*/
53PhysicsInterface::~PhysicsInterface () 
54{
55   PhysicsEngine::getInstance()->removePhysicsInterface(this);
56}
57
58/**
59   \brief recalculates the total mass of all the children of this node
60
61   (only availiable for PNodes)
62*/
63void PhysicsInterface::recalcMass()
64{
65  PNode* massCalcPNode = dynamic_cast<PNode*>(this);  //! \todo not sure if this will work ....
66  float massSum = 0;
67 
68  tIterator<PNode>* iterator = massCalcPNode->children->getIterator();
69  PNode* pn = iterator->nextElement();
70  while( pn != NULL) 
71    { 
72      // todo: find out if children are PhysicsInterface in an efficient way
73      if (strcmp( pn->getClassName(), "PhysicsInterface")) {
74        massSum += ((PhysicsInterface*)pn)->getTotalMass();
75      }
76      pn = iterator->nextElement();
77    }
78  delete iterator;
79       
80  if (massSum != this->massChildren ) {
81    this->massChildren = massSum;
82    if (strcmp( massCalcPNode->parent->getClassName(), "PhysicsInterface"))
83      ((PhysicsInterface*)massCalcPNode->parent)->recalcMass();
84  } else {
85    this->massChildren = massSum;
86  }
87}
88       
89       
90void PhysicsInterface::applyField(Field* field)
91{
92  //  this->forceSum += force;
93}
94
95void PhysicsInterface::tickPhys( float dt )
96{
97  Vector acc = this->forceSum / ( this->massChildren + this->mass );
98  // todo: introduce kinematics
99}
Note: See TracBrowser for help on using the repository browser.