Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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