Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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