Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more loading (especially for physics)

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