Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/physics/physics_engine.cc @ 4397

Last change on this file since 4397 was 4396, checked in by bensch, 20 years ago

orxonox/trunk: now Objects should be affected by the PhysicsEngine too

File size: 4.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: ...
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS
17
18#include "physics_engine.h"
19
20#include "debug.h"
21
22#include "list.h"
23
24using namespace std;
25
26
27/**
28   \brief standard constructor
29*/
30PhysicsEngine::PhysicsEngine() 
31{
32   this->setClassName ("PhysicsEngine");
33
34   this->connections = new tList<PhysicsConnection>;
35   this->interfaces = new tList<PhysicsInterface>;
36   this->fields = new tList<Field>;
37}
38
39/**
40   \brief the singleton reference to this class
41*/
42PhysicsEngine* PhysicsEngine::singletonRef = NULL;
43
44/**
45   \returns a Pointer to this Class
46*/
47PhysicsEngine* PhysicsEngine::getInstance(void)
48{
49  if (!PhysicsEngine::singletonRef)
50    PhysicsEngine::singletonRef = new PhysicsEngine();
51  return PhysicsEngine::singletonRef;
52}
53
54/**
55   \brief standard deconstructor
56
57*/
58PhysicsEngine::~PhysicsEngine () 
59{
60  PhysicsEngine::singletonRef = NULL;
61}
62
63
64/**
65   \brief adds a PhysicsInterface to the list of handeled physicsInterfaces
66   \param physicsInterface the interface to add
67
68   this is normally done in the constructor of any PhysicsInterface
69*/
70void PhysicsEngine::addPhysicsInterface(PhysicsInterface* physicsInterface)
71{
72  this->interfaces->add(physicsInterface);
73}
74
75/**
76   \brief removes a PhysicsInterface from the list of handeled physicsInterfaces
77   \param physicsInterface the interface to remove
78
79   this is normally done in the destructor of any PhysicsInterface
80*/
81void PhysicsEngine::removePhysicsInterface(PhysicsInterface* physicsInterface)
82{
83  this->interfaces->remove(physicsInterface); 
84}
85
86/**
87   \brief adds a Field to the list of handeled fields
88   \param field the field to add
89
90   this is normally done in the constructor of any Field
91*/
92void PhysicsEngine::addField(Field* field)
93{
94  this->fields->add(field);
95}
96
97/**
98   \brief removes a Field from the list of handeled fields
99   \param field the field to remove
100
101   this is normally done in the destructor of any Field
102*/
103void PhysicsEngine::removeField(Field* field)
104{
105  this->fields->remove(field);
106}
107
108/**
109   \brief adds A Physical Connection to the List of Connections
110   \param connection the Connection to add
111   
112   Usually this is done through the constructor of PhysicshConnections
113*/
114void PhysicsEngine::addConnection(PhysicsConnection* connection)
115{
116  this->connections->add(connection);
117}
118
119/**
120   \brief removes A Physical Connection from the List of Connections
121   \param connection the Connection to remove
122   
123   Usually this is done through the destructor of PhysicsConnections
124*/
125void PhysicsEngine::removeConnection(PhysicsConnection* connection)
126{
127  this->connections->remove(connection);
128}
129
130
131
132
133
134/**
135   \brief Steps through all the Connections and Ticks them
136   \param dt The time Passed in Seconds
137
138   This function brings a flow into the whole animation
139*/
140void PhysicsEngine::tick(float dt)
141{
142  tIterator<PhysicsConnection>* itPC = this->connections->getIterator();
143  PhysicsConnection* enumPC = itPC->nextElement();
144  while (enumPC)
145    {
146      enumPC->apply();
147      enumPC = itPC->nextElement();
148    }
149  delete itPC;
150
151
152  tIterator<PhysicsInterface>* itPI = this->interfaces->getIterator();
153  PhysicsInterface* enumPI = itPI->nextElement();
154  while (enumPI)
155    {
156      enumPI->tickPhys(dt);
157      enumPI = itPI->nextElement();
158    }
159  delete itPI;
160}
161
162
163
164/**
165   \brief print out interesting debug information of this class
166*/
167void PhysicsEngine::debug(void) const
168{
169  PRINT(0)("====================================\n");
170  PRINT(0)("= Physics-Engine debug information =\n");
171  PRINT(0)("====================================\n");
172  PRINT(0)(" reference: %p\n", this);
173  PRINT(0)(" number of Interfaces: %d\n", this->interfaces->getSize());
174  PRINT(0)(" number of Connections: %d\n", this->connections->getSize());
175
176  PRINT(0)("==============================PHYS==\n");
177}
Note: See TracBrowser for help on using the repository browser.