Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/physics/physics_connection.cc @ 5132

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

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

File size: 2.7 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: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "physics_connection.h"
19
20#include "physics_engine.h"
21
22#include "field.h"
23#include "particle_system.h"
24#include "physics_interface.h"
25
26#include "factory.h"
27
28using namespace std;
29
30CREATE_FACTORY(PhysicsConnection);
31
32/**
33 *  creates a PhysicsConnection
34*/
35PhysicsConnection::PhysicsConnection(PhysicsInterface* subject, Field* field)
36{
37  this->setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");
38  this->type = PCON_PhysIField;
39
40  this->subject = subject;
41  this->field = field;
42
43  PhysicsEngine::getInstance()->addConnection(this);
44}
45
46PhysicsConnection::PhysicsConnection(const TiXmlElement* root)
47{
48  this->setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");
49  this->type = PCON_PhysIField;
50
51  static_cast<BaseObject*>(this)->loadParams(root);
52
53  LoadParam<PhysicsConnection>(root, "subject", this, &PhysicsConnection::setSubject)
54      .describe("set the subject by a name");
55
56  LoadParam<PhysicsConnection>(root, "field", this, &PhysicsConnection::setField)
57      .describe("set the field by name");
58
59  PhysicsEngine::getInstance()->addConnection(this);
60}
61
62/**
63 *  standard deconstructor
64
65*/
66PhysicsConnection::~PhysicsConnection ()
67{
68  PhysicsEngine::getInstance()->removeConnection(this);
69}
70
71/**
72 * @param subjectName the name of the Subject for this PhysicsConnection
73*/
74void PhysicsConnection::setSubject(const char* subjectName)
75{
76  this->subject = PhysicsEngine::getInstance()->getPhysicsInterfaceByName(subjectName);
77  if (this->subject == NULL)
78  {
79    PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName);
80  }
81  else
82    PRINTF(5)("subject::%s\n", this->subject->getName());
83}
84
85/**
86* @param fieldName the Name of the Field for this connection
87*/
88void PhysicsConnection::setField(const char* fieldName)
89{
90  this->field = PhysicsEngine::getInstance()->getFieldByName(fieldName);
91  if (this->field == NULL)
92  {
93        PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName);
94  }
95  else
96    PRINTF(5)("field::%s\n", this->field->getName());
97
98}
99
100/**
101  *  applies the Force to some Object.
102*/
103void PhysicsConnection::apply() const
104{
105  if (likely(this->type == PCON_PhysIField && this->field->getMagnitude() != 0.0
106      && this->subject != NULL && this->field != NULL))
107      this->subject->applyField(this->field);
108  else ;
109}
Note: See TracBrowser for help on using the repository browser.