Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4451 was 4440, checked in by patrick, 20 years ago

orxonox/trunk: pnode enhancement and cleanup, very tight now

File size: 2.5 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 (void* objectPointer) 
39{
40  this->objectPointer = objectPointer;
41
42  //   this->setClassName ("PhysicsInterface");
43   this->mass = 1;
44   this->massChildren = 0;
45   this->forceSum = Vector(0, 0, 0);
46
47   PhysicsEngine::getInstance()->addPhysicsInterface(this);
48}
49
50
51/**
52   \brief standard deconstructor
53
54*/
55PhysicsInterface::~PhysicsInterface () 
56{
57   PhysicsEngine::getInstance()->removePhysicsInterface(this);
58}
59
60/**
61   \brief recalculates the total mass of all the children of this node
62
63   (only availiable for PNodes)
64*/
65void PhysicsInterface::recalcMass()
66{
67  /*
68  PNode* massCalcPNode = dynamic_cast<PNode*>(this);  //! \todo not sure if this will work ....
69  float massSum = 0;
70 
71  tIterator<PNode>* iterator = massCalcPNode->children->getIterator();
72  PNode* pn = iterator->nextElement();
73  while( pn != NULL)
74    {
75      // todo: find out if children are PhysicsInterface in an efficient way
76      if (strcmp( pn->getClassName(), "PhysicsInterface")) {
77        massSum += ((PhysicsInterface*)pn)->getTotalMass();
78      }
79      pn = iterator->nextElement();
80    }
81  delete iterator;
82       
83  if (massSum != this->massChildren ) {
84    this->massChildren = massSum;
85    if (strcmp( massCalcPNode->parent->getClassName(), "PhysicsInterface"))
86      ((PhysicsInterface*)massCalcPNode->parent)->recalcMass();
87  } else {
88    this->massChildren = massSum;
89  }
90  */
91}
92       
93       
94void PhysicsInterface::applyField(Field* field)
95{
96  PNode* tmp = (PNode*) objectPointer;
97  this->forceSum += field->calcForce(tmp->getAbsCoor()); 
98}
99
100
101void PhysicsInterface::tickPhys( float dt )
102{
103  //  Vector acc = this->forceSum / ( this->massChildren + this->mass );
104  PNode* coorTick =  (PNode*)(this->objectPointer);
105  if (coorTick)
106    coorTick->setRelCoor(coorTick->getRelCoor() + this->forceSum/this->mass * dt);
107  this->forceSum = Vector(0,0,0);
108  // todo: introduce kinematics
109}
Note: See TracBrowser for help on using the repository browser.