Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/physics/i_physics.cc @ 4369

Last change on this file since 4369 was 4338, checked in by bensch, 20 years ago

orxonox/trunk: merged branches/physics back to the trunk
merged with command
svn merge -r 3866:HEAD . ../../trunk/
many conflict that i tried to resolv
@patrick: i hope i did not interfere with your stuff :/

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