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 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | CREATE_FACTORY(PhysicsConnection); |
---|
31 | |
---|
32 | /** |
---|
33 | \brief creates a PhysicsConnection |
---|
34 | */ |
---|
35 | PhysicsConnection::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 | |
---|
46 | PhysicsConnection::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 | \brief standard deconstructor |
---|
64 | |
---|
65 | */ |
---|
66 | PhysicsConnection::~PhysicsConnection () |
---|
67 | { |
---|
68 | PhysicsEngine::getInstance()->removeConnection(this); |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | \param subjectName the name of the Subject for this PhysicsConnection |
---|
73 | */ |
---|
74 | void 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 | */ |
---|
88 | void 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 | \brief applies the Force to some Object. |
---|
102 | */ |
---|
103 | void 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 | } |
---|