Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: physicsInterfaces now check in at constuctiontime with the PhysicsEngine

File size: 3.4 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}
37
38/**
39   \brief the singleton reference to this class
40*/
41PhysicsEngine* PhysicsEngine::singletonRef = NULL;
42
43/**
44   \returns a Pointer to this Class
45*/
46PhysicsEngine* PhysicsEngine::getInstance(void)
47{
48  if (!PhysicsEngine::singletonRef)
49    PhysicsEngine::singletonRef = new PhysicsEngine();
50  return PhysicsEngine::singletonRef;
51}
52
53/**
54   \brief standard deconstructor
55
56*/
57PhysicsEngine::~PhysicsEngine () 
58{
59  PhysicsEngine::singletonRef = NULL;
60}
61
62
63/**
64   \brief adds a PhysicsInterface to the list of handeled physicsInterfaces
65   \param physicsInterface the interface to add
66
67   this is normally done in the constructor of any PhysicsInterface
68*/
69void PhysicsEngine::addPhysicsInterface(PhysicsInterface* physicsInterface)
70{
71  this->interfaces->add(physicsInterface);
72}
73
74/**
75   \brief removes a PhysicsInterface from the list of handeled physicsInterfaces
76   \param physicsInterface the interface to remove
77
78   this is normally done in the destructor of any PhysicsInterface
79*/
80void PhysicsEngine::removePhysicsInterface(PhysicsInterface* physicsInterface)
81{
82  this->interfaces->remove(physicsInterface); 
83}
84
85/**
86   \brief adds A Physical Connection to the List of Connections
87   \param connection the Connection to add
88   
89   Usually this is done through the constructor of PhysicshConnections
90*/
91void PhysicsEngine::addConnection(PhysicsConnection* connection)
92{
93  this->connections->add(connection);
94}
95
96/**
97   \brief removes A Physical Connection from the List of Connections
98   \param connection the Connection to remove
99   
100   Usually this is done through the destructor of PhysicsConnections
101*/
102void PhysicsEngine::removeConnection(PhysicsConnection* connection)
103{
104  this->connections->remove(connection);
105}
106
107
108
109
110
111/**
112   \brief Steps through all the Connections and Ticks them
113   \param dt The time Passed in Seconds
114
115   This function brings a flow into the whole animation
116*/
117void PhysicsEngine::tick(float dt)
118{
119  tIterator<PhysicsConnection>* iterator = this->connections->getIterator();
120  PhysicsConnection* enumConn = iterator->nextElement();
121  while (enumConn)
122    {
123      enumConn->apply(dt);
124      enumConn = iterator->nextElement();
125    }
126  delete iterator;
127}
128
129
130
131/**
132   \brief print out interesting debug information of this class
133*/
134void PhysicsEngine::debug(void) const
135{
136  PRINT(0)("====================================\n");
137  PRINT(0)("= Physics-Engine debug information =\n");
138  PRINT(0)("====================================\n");
139  PRINT(0)(" reference: %p\n", this);
140  PRINT(0)(" number of Interfaces: %d\n", this->interfaces->getSize());
141  PRINT(0)(" number of Connections: %d\n", this->connections->getSize());
142
143  PRINT(0)("==============================PHYS==\n");
144}
Note: See TracBrowser for help on using the repository browser.