[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" |
---|
[4121] | 23 | #include "list.h" |
---|
| 24 | #include "string.h" |
---|
[3961] | 25 | #include "stdincl.h" |
---|
[3954] | 26 | |
---|
| 27 | using namespace std; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | \brief standard constructor |
---|
| 32 | */ |
---|
[4375] | 33 | PhysicsInterface::PhysicsInterface () |
---|
[3954] | 34 | { |
---|
[4375] | 35 | this->setClassName ("PhysicsInterface"); |
---|
[4121] | 36 | this->mass = 0; |
---|
| 37 | this->massChildren = 0; |
---|
[4221] | 38 | this->forceSum = Vector(0, 0, 0); |
---|
[3954] | 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | \brief standard deconstructor |
---|
| 44 | |
---|
| 45 | */ |
---|
[4375] | 46 | PhysicsInterface::~PhysicsInterface () |
---|
[3954] | 47 | { |
---|
| 48 | // delete what has to be deleted here |
---|
| 49 | } |
---|
[4121] | 50 | |
---|
[4375] | 51 | void PhysicsInterface::recalcMass() |
---|
[4121] | 52 | { |
---|
| 53 | float massSum = 0; |
---|
| 54 | |
---|
| 55 | tIterator<PNode>* iterator = this->children->getIterator(); |
---|
| 56 | PNode* pn = iterator->nextElement(); |
---|
| 57 | while( pn != NULL) |
---|
| 58 | { |
---|
[4375] | 59 | // todo: find out if children are PhysicsInterface in an efficient way |
---|
| 60 | if (strcmp( pn->getClassName(), "PhysicsInterface")) { |
---|
| 61 | massSum += ((PhysicsInterface*)pn)->getTotalMass(); |
---|
[4121] | 62 | } |
---|
| 63 | pn = iterator->nextElement(); |
---|
| 64 | } |
---|
| 65 | delete iterator; |
---|
| 66 | |
---|
| 67 | if (massSum != this->massChildren ) { |
---|
| 68 | this->massChildren = massSum; |
---|
[4375] | 69 | if (strcmp( parent->getClassName(), "PhysicsInterface")) |
---|
| 70 | ((PhysicsInterface*)parent)->recalcMass(); |
---|
[4121] | 71 | } else { |
---|
| 72 | this->massChildren = massSum; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
[4375] | 77 | void PhysicsInterface::addForce( Vector force ) |
---|
[4221] | 78 | { |
---|
| 79 | forceSum += force; |
---|
| 80 | } |
---|
| 81 | |
---|
[4375] | 82 | void PhysicsInterface::addForce(Vector force, Vector grip) |
---|
[4221] | 83 | { |
---|
| 84 | // add central force |
---|
| 85 | forceSum += force; |
---|
| 86 | // add momentum |
---|
| 87 | // todo: some vector math |
---|
| 88 | } |
---|
| 89 | |
---|
[4375] | 90 | void PhysicsInterface::tick( float dt ) |
---|
[4221] | 91 | { |
---|
| 92 | Vector acc = forceSum / ( massChildren + mass ); |
---|
| 93 | // todo: introduce kinematics |
---|
| 94 | } |
---|