Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5067 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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