Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: loadParams is now virtual.
ALL THE CLASSES HAVE TO CALL

SuperClass::loadParams(root);

isntead of:
static_cast<SuperClass*>(this)→loadParams(root);

which was quite stupid anyways

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