Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: renamed iphysics to physics_interface

File size: 1.9 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 "list.h"
24#include "string.h"
25#include "stdincl.h"
26
27using namespace std;
28
29
30/**
31   \brief standard constructor
32*/
33PhysicsInterface::PhysicsInterface () 
34{
35   this->setClassName ("PhysicsInterface");
36   this->mass = 0;
37   this->massChildren = 0;
38   this->forceSum = Vector(0, 0, 0);
39}
40
41
42/**
43   \brief standard deconstructor
44
45*/
46PhysicsInterface::~PhysicsInterface () 
47{
48  // delete what has to be deleted here
49}
50
51void PhysicsInterface::recalcMass()
52{
53        float massSum = 0;
54       
55        tIterator<PNode>* iterator = this->children->getIterator();
56        PNode* pn = iterator->nextElement();
57        while( pn != NULL) 
58    { 
59        // todo: find out if children are PhysicsInterface in an efficient way
60        if (strcmp( pn->getClassName(), "PhysicsInterface")) {
61                        massSum += ((PhysicsInterface*)pn)->getTotalMass();
62        }
63      pn = iterator->nextElement();
64    }
65        delete iterator;
66       
67        if (massSum != this->massChildren ) {
68                this->massChildren = massSum;
69                if (strcmp( parent->getClassName(), "PhysicsInterface"))
70                        ((PhysicsInterface*)parent)->recalcMass();
71        } else {
72                this->massChildren = massSum;
73        }
74}
75       
76       
77void PhysicsInterface::addForce( Vector force )
78{
79        forceSum += force;
80}
81
82void PhysicsInterface::addForce(Vector force, Vector grip)
83{
84        // add central force
85        forceSum += force;
86        // add momentum
87        // todo: some vector math
88}
89       
90void PhysicsInterface::tick( float dt )
91{
92        Vector acc = forceSum / ( massChildren + mass );
93        // todo: introduce kinematics
94}
Note: See TracBrowser for help on using the repository browser.