Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/physics/physics_connection.cc @ 9716

Last change on this file since 9716 was 9716, checked in by bensch, 18 years ago

more renamings

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_PHYSICS
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 "util/loading/factory.h"
27#include "util/loading/load_param.h"
28
29#include "class_id_DEPRECATED.h"
30ObjectListDefinition(PhysicsConnection);
31CREATE_FACTORY(PhysicsConnection);
32/**
33 *  creates a PhysicsConnection
34*/
35PhysicsConnection::PhysicsConnection(PhysicsInterface* subject, Field* field)
36{
37  this->registerObject(this, PhysicsConnection::_objectList);
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->registerObject(this, PhysicsConnection::_objectList);
49  this->type = PCON_PhysIField;
50
51  BaseObject::loadParams(root);
52
53  LoadParam(root, "subject", this, PhysicsConnection, setSubject)
54      .describe("set the subject by a name");
55
56  LoadParam(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 std::string& 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.c_str());
80  }
81  else
82    PRINTF(5)("subject::%s\n", this->subject->getCName());
83}
84
85/**
86* @param fieldName the Name of the Field for this connection
87*/
88void PhysicsConnection::setField(const std::string& 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.c_str());
94  }
95  else
96    PRINTF(5)("field::%s\n", this->field->getCName());
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.