/* 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 "physics_engine.h" #include "field.h" #include "p_node.h" #include "list.h" #include "string.h" #include "stdincl.h" using namespace std; /** \brief standard constructor */ PhysicsInterface::PhysicsInterface (void* objectPointer) { this->objectPointer = objectPointer; // this->setClassName ("PhysicsInterface"); this->mass = 1; this->massChildren = 0; this->forceSum = Vector(0, 0, 0); this->bForceApplied = false; PhysicsEngine::getInstance()->addPhysicsInterface(this); } /** \brief standard deconstructor */ PhysicsInterface::~PhysicsInterface () { PhysicsEngine::getInstance()->removePhysicsInterface(this); } /** \brief recalculates the total mass of all the children of this node (only availiable for PNodes) */ void PhysicsInterface::recalcMass() { /* PNode* massCalcPNode = dynamic_cast(this); //! \todo not sure if this will work .... float massSum = 0; tIterator* iterator = massCalcPNode->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( massCalcPNode->parent->getClassName(), "PhysicsInterface")) ((PhysicsInterface*)massCalcPNode->parent)->recalcMass(); } else { this->massChildren = massSum; } */ } /** \brief applyes a field to this Object \param field the field to apply */ void PhysicsInterface::applyField(Field* field) { PNode* tmp = (PNode*) objectPointer; this->forceSum += field->calcForce(tmp->getAbsCoor()); this->bForceApplied = true; } /** \brief ticks the PhysicsEffect \param dt: the value about which to tick */ void PhysicsInterface::tickPhys( float dt ) { // Vector acc = this->forceSum / ( this->massChildren + this->mass ); PNode* coorTick = (PNode*)(this->objectPointer); if (this->bForceApplied && coorTick) { coorTick->shiftCoor((coorTick->getVelocity()+ this->forceSum/this->mass * dt)*dt); this->bForceApplied = false; } this->forceSum = Vector(0,0,0); }