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
RevLine 
[3954]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
[4381]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS
[3954]17
[4121]18#include "physics_engine.h"
[3954]19
[4381]20#include "debug.h"
21
[4183]22#include "list.h"
[3954]23
24using namespace std;
25
26
27/**
28   \brief standard constructor
29*/
[4183]30PhysicsEngine::PhysicsEngine() 
[3954]31{
[4121]32   this->setClassName ("PhysicsEngine");
[4183]33
34   this->connections = new tList<PhysicsConnection>;
[4392]35   this->interfaces = new tList<PhysicsInterface>;
[3954]36}
37
[4183]38/**
39   \brief the singleton reference to this class
40*/
41PhysicsEngine* PhysicsEngine::singletonRef = NULL;
[3954]42
43/**
[4183]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/**
[3954]54   \brief standard deconstructor
55
56*/
[4121]57PhysicsEngine::~PhysicsEngine () 
[3954]58{
[4183]59  PhysicsEngine::singletonRef = NULL;
[3954]60}
61
[4392]62
[3954]63/**
[4392]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/**
[4183]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}
[3954]95
[4183]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
[3954]101*/
[4183]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    {
[4186]123      enumConn->apply(dt);
[4183]124      enumConn = iterator->nextElement();
125    }
126  delete iterator;
127}
[4378]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);
[4392]140  PRINT(0)(" number of Interfaces: %d\n", this->interfaces->getSize());
141  PRINT(0)(" number of Connections: %d\n", this->connections->getSize());
[4378]142
143  PRINT(0)("==============================PHYS==\n");
144}
Note: See TracBrowser for help on using the repository browser.