[3954] | 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: |
---|
[3961] | 14 | main-programmer: Patrick Boenzli |
---|
[4375] | 15 | co-programmer: Benjamin Grauer |
---|
| 16 | |
---|
| 17 | bensch: renamed the file |
---|
[3954] | 18 | */ |
---|
| 19 | |
---|
[3961] | 20 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS |
---|
[3954] | 21 | |
---|
[4375] | 22 | #include "physics_interface.h" |
---|
[4376] | 23 | |
---|
| 24 | #include "p_node.h" |
---|
| 25 | |
---|
[4121] | 26 | #include "list.h" |
---|
| 27 | #include "string.h" |
---|
[3961] | 28 | #include "stdincl.h" |
---|
[3954] | 29 | |
---|
| 30 | using namespace std; |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | \brief standard constructor |
---|
| 35 | */ |
---|
[4375] | 36 | PhysicsInterface::PhysicsInterface () |
---|
[3954] | 37 | { |
---|
[4376] | 38 | // this->setClassName ("PhysicsInterface"); |
---|
[4121] | 39 | this->mass = 0; |
---|
| 40 | this->massChildren = 0; |
---|
[4221] | 41 | this->forceSum = Vector(0, 0, 0); |
---|
[3954] | 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | \brief standard deconstructor |
---|
| 47 | |
---|
| 48 | */ |
---|
[4375] | 49 | PhysicsInterface::~PhysicsInterface () |
---|
[3954] | 50 | { |
---|
| 51 | // delete what has to be deleted here |
---|
| 52 | } |
---|
[4121] | 53 | |
---|
[4376] | 54 | /** |
---|
| 55 | \brief recalculates the total mass of all the children of this node |
---|
| 56 | |
---|
| 57 | (only availiable for PNodes) |
---|
| 58 | */ |
---|
[4375] | 59 | void PhysicsInterface::recalcMass() |
---|
[4121] | 60 | { |
---|
[4376] | 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) |
---|
[4121] | 67 | { |
---|
[4376] | 68 | // todo: find out if children are PhysicsInterface in an efficient way |
---|
| 69 | if (strcmp( pn->getClassName(), "PhysicsInterface")) { |
---|
| 70 | massSum += ((PhysicsInterface*)pn)->getTotalMass(); |
---|
| 71 | } |
---|
[4121] | 72 | pn = iterator->nextElement(); |
---|
| 73 | } |
---|
[4376] | 74 | delete iterator; |
---|
[4121] | 75 | |
---|
[4376] | 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 | } |
---|
[4121] | 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
[4376] | 86 | void PhysicsInterface::applyForce( Vector force ) |
---|
[4221] | 87 | { |
---|
[4376] | 88 | this->forceSum += force; |
---|
[4221] | 89 | } |
---|
| 90 | |
---|
[4376] | 91 | void PhysicsInterface::tickPhys( float dt ) |
---|
[4221] | 92 | { |
---|
[4376] | 93 | Vector acc = this->forceSum / ( this->massChildren + this->mass ); |
---|
| 94 | // todo: introduce kinematics |
---|
[4221] | 95 | } |
---|