Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/physics/physics_interface.cc @ 8767

Last change on this file since 8767 was 8350, checked in by bensch, 18 years ago

fixed out some warnings

File size: 2.8 KB
RevLine 
[3954]1
2
[4555]3/*
[3954]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
[4555]16
[4375]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"
[4392]23#include "physics_engine.h"
[4376]24
[4377]25#include "field.h"
[4376]26#include "p_node.h"
27
[4121]28#include "string.h"
[3961]29#include "stdincl.h"
[3954]30
31using namespace std;
32
33
34/**
[4836]35 *  standard constructor
[4597]36 */
[4762]37PhysicsInterface::PhysicsInterface ()
[3954]38{
[4597]39  this->setClassID(CL_PHYSICS_INTERFACE, "PhysicsInterface");
[4397]40
[4597]41  this->mass = 1;
42  this->massChildren = 0;
43  this->forceSum = Vector(0, 0, 0);
44  this->bForceApplied = false;
[3954]45}
46
47/**
[4836]48 *  standard deconstructor
[3954]49*/
[4555]50PhysicsInterface::~PhysicsInterface ()
[3954]51{
52}
[4121]53
[4376]54/**
[4836]55 *  recalculates the total mass of all the children of this node
[4376]56
57   (only availiable for PNodes)
58*/
[4375]59void PhysicsInterface::recalcMass()
[4121]60{
[4440]61  /*
[4836]62    PNode* massCalcPNode = dynamic_cast<PNode*>(this);  //! @todo not sure if this will work ....
[4480]63    float massSum = 0;
[4555]64
[4480]65    tIterator<PNode>* iterator = massCalcPNode->children->getIterator();
[5115]66    PNode* pn = iterator->firstElement();
[4555]67    while( pn != NULL)
68    {
[4480]69    // todo: find out if children are PhysicsInterface in an efficient way
70    if (strcmp( pn->getClassName(), "PhysicsInterface")) {
71    massSum += ((PhysicsInterface*)pn)->getTotalMass();
[4121]72    }
[4480]73    pn = iterator->nextElement();
74    }
75    delete iterator;
[4555]76
[4480]77    if (massSum != this->massChildren ) {
[4376]78    this->massChildren = massSum;
79    if (strcmp( massCalcPNode->parent->getClassName(), "PhysicsInterface"))
[4480]80    ((PhysicsInterface*)massCalcPNode->parent)->recalcMass();
81    } else {
[4376]82    this->massChildren = massSum;
[4480]83    }
[4440]84  */
[4121]85}
[4555]86
[4480]87/**
[4836]88 *  applyes a field to this Object
89 * @param field the field to apply
[5255]90 *
91 * this function is virtual, and !must be reimplemented if the Member is !NOT! a PNode
[4480]92*/
[4395]93void PhysicsInterface::applyField(Field* field)
[4221]94{
[4762]95  PNode* tmp = dynamic_cast<PNode*>((BaseObject*)this);
[4555]96  this->forceSum += field->calcForce(tmp->getAbsCoor());
[4558]97  this->bForceApplied = true;
[4221]98}
99
[5257]100void PhysicsInterface::applyForce(const Vector& force)
101{
102  this->forceSum += force;
103  this->bForceApplied = true;
104}
105
[4480]106/**
[4836]107 *  ticks the PhysicsEffect
108 * @param dt: the value about which to tick
[4480]109*/
[4376]110void PhysicsInterface::tickPhys( float dt )
[4221]111{
[4397]112  //  Vector acc = this->forceSum / ( this->massChildren + this->mass );
[4762]113  PNode* coorTick =  dynamic_cast<PNode*>((BaseObject*)this);
[5257]114  if (coorTick != NULL )
115    coorTick->shiftCoor((coorTick->getVelocity()+ this->forceSum/this->mass*dt)*dt);
116
117  if (this->bForceApplied)
[4558]118  {
119    this->bForceApplied = false;
[5257]120    this->forceSum = Vector(0,0,0);
[4558]121  }
[4221]122}
Note: See TracBrowser for help on using the repository browser.