/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: Benjamin Grauer bensch: renamed the file */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS #include "physics_interface.h" #include "list.h" #include "string.h" #include "stdincl.h" using namespace std; /** \brief standard constructor */ PhysicsInterface::PhysicsInterface () { this->setClassName ("PhysicsInterface"); this->mass = 0; this->massChildren = 0; this->forceSum = Vector(0, 0, 0); } /** \brief standard deconstructor */ PhysicsInterface::~PhysicsInterface () { // delete what has to be deleted here } void PhysicsInterface::recalcMass() { float massSum = 0; tIterator* iterator = this->children->getIterator(); PNode* pn = iterator->nextElement(); while( pn != NULL) { // todo: find out if children are PhysicsInterface in an efficient way if (strcmp( pn->getClassName(), "PhysicsInterface")) { massSum += ((PhysicsInterface*)pn)->getTotalMass(); } pn = iterator->nextElement(); } delete iterator; if (massSum != this->massChildren ) { this->massChildren = massSum; if (strcmp( parent->getClassName(), "PhysicsInterface")) ((PhysicsInterface*)parent)->recalcMass(); } else { this->massChildren = massSum; } } void PhysicsInterface::addForce( Vector force ) { forceSum += force; } void PhysicsInterface::addForce(Vector force, Vector grip) { // add central force forceSum += force; // add momentum // todo: some vector math } void PhysicsInterface::tick( float dt ) { Vector acc = forceSum / ( massChildren + mass ); // todo: introduce kinematics }