Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: PhysicsEngine: doxytags

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   \brief standard constructor
37*/
38PhysicsInterface::PhysicsInterface (void* objectPointer) 
39{
40  this->objectPointer = objectPointer;
41
42  //   this->setClassName ("PhysicsInterface");
43   this->mass = 1;
44   this->massChildren = 0;
45   this->forceSum = Vector(0, 0, 0);
46
47   PhysicsEngine::getInstance()->addPhysicsInterface(this);
48}
49
50/**
51   \brief standard deconstructor
52
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}
101
102/**
103   \brief 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 =  (PNode*)(this->objectPointer);
110  if (coorTick)
111    coorTick->setRelCoor(coorTick->getRelCoor() + this->forceSum/this->mass * dt);
112  this->forceSum = Vector(0,0,0);
113  // todo: introduce kinematics
114}
Note: See TracBrowser for help on using the repository browser.