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