Changeset 4728 in orxonox.OLD for orxonox/trunk/src/lib/physics
- Timestamp:
- Jun 28, 2005, 11:56:46 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/physics
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/physics/fields/field.cc
r4394 r4728 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 20 20 #include "physics_engine.h" 21 21 22 #include "factory.h" 23 #include "load_param.h" 22 24 using namespace std; 23 24 25 25 26 /** 26 27 \brief standard constructor 27 \todo this constructor is not jet implemented - do it28 28 */ 29 Field::Field () 29 Field::Field () 30 30 { 31 this->setClassName ("Field"); 32 this->setMagnitude(1); 33 this->setAttenuation(0); 34 35 PhysicsEngine::getInstance()->addField(this); 31 this->init(); 36 32 } 37 33 34 /** 35 \param root The XML-element to load settings from 36 */ 37 Field::Field(const TiXmlElement* root) 38 { 39 this->init(); 40 this->loadParams(root); 41 } 38 42 39 43 /** … … 41 45 42 46 */ 43 Field::~Field () 47 Field::~Field () 44 48 { 45 49 PhysicsEngine::getInstance()->removeField(this); 46 50 } 47 51 52 /** 53 \brief initializes a Field 54 */ 55 void Field::init(void) 56 { 57 this->setClassID(CL_FIELD, "Field"); 58 this->setMagnitude(1); 59 this->setAttenuation(0); 60 61 PhysicsEngine::getInstance()->addField(this); 62 } 63 64 /** 65 \param root The XML-element to load settings from 66 */ 67 void Field::loadParams(const TiXmlElement* root) 68 { 69 static_cast<PNode*>(this)->loadParams(root); 70 71 LoadParam<Field>(root, "magnitude", this, &Field::setMagnitude) 72 .describe("sets the magnitude of this Field"); 73 74 LoadParam<Field>(root, "attenuation", this, &Field::setAttenuation) 75 .describe("sets the attenuation of this Field."); 76 77 } 48 78 49 79 /** 50 80 \param magnitude the magnitude of the Field. 51 81 */ 52 void Field::setMagnitude( const float&magnitude)82 void Field::setMagnitude(float magnitude) 53 83 { 54 84 this->magnitude = magnitude; … … 58 88 \param attenuation The attenuation of the Field (the bigger the smaller the region of influence) 59 89 */ 60 void Field::setAttenuation( const float&attenuation)90 void Field::setAttenuation(float attenuation) 61 91 { 62 92 this->attenuation = attenuation; -
orxonox/trunk/src/lib/physics/fields/field.h
r4481 r4728 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 14 14 */ 15 15 16 /*! 16 /*! 17 17 \file field.h 18 18 \brief abstract definition of a Physical Field 19 19 20 This is a totally abstract class, that only enables different Physical Fields to 20 This is a totally abstract class, that only enables different Physical Fields to 21 21 exist on a common Level. 22 22 */ … … 28 28 29 29 // FORWARD DEFINITION 30 30 class TiXmlElement; 31 31 32 32 33 33 //! An abstract class that represents a Force. 34 class Field : public PNode 34 class Field : public PNode 35 35 { 36 36 public: 37 37 Field(); 38 Field(const TiXmlElement* root); 38 39 virtual ~Field(); 39 40 40 /** 41 void init(void); 42 void loadParams(const TiXmlElement* root); 43 44 /** 41 45 \param data This is the data given to this force, to calculate the ForceVector 42 46 \returns The Force Vector … … 44 48 virtual Vector calcForce(const Vector& data) const = 0; 45 49 46 void setMagnitude( const float&magnitude);50 void setMagnitude(float magnitude); 47 51 /** \returns The Magnitude of the Field */ 48 52 inline const float& getMagnitude(void) const {return this->magnitude;} 49 53 50 void setAttenuation( const float&attenuation);54 void setAttenuation(float attenuation); 51 55 /** \returns The Attenuation of the Fiels */ 52 56 inline const float& getAttenuation(void) const {return this->attenuation;} -
orxonox/trunk/src/lib/physics/fields/gravity.cc
r4396 r4728 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 18 18 #include "gravity.h" 19 19 20 #include "load_param.h" 21 #include "factory.h" 22 20 23 using namespace std; 21 24 25 CREATE_FACTORY(Gravity); 22 26 23 27 /** … … 25 29 \todo this constructor is not jet implemented - do it 26 30 */ 27 Gravity::Gravity () 31 Gravity::Gravity () 28 32 { 29 this->setClassName 33 this->setClassName("Gravity"); 30 34 } 31 35 36 Gravity::Gravity(const TiXmlElement* root) 37 { 38 this->setClassName("Gravity"); 39 40 this->loadParams(root); 41 } 32 42 33 43 /** … … 35 45 36 46 */ 37 Gravity::~Gravity () 47 Gravity::~Gravity () 38 48 { 39 49 // delete what has to be deleted here 50 } 51 52 void Gravity::loadParams(const TiXmlElement* root) 53 { 54 static_cast<Field*>(this)->loadParams(root); 55 40 56 } 41 57 -
orxonox/trunk/src/lib/physics/fields/gravity.h
r4395 r4728 1 /*! 1 /*! 2 2 \file gravity.h 3 3 \brief Definition of ... … … 19 19 public: 20 20 Gravity(); 21 Gravity(const TiXmlElement* root); 21 22 virtual ~Gravity(); 23 24 void loadParams(const TiXmlElement* root); 22 25 23 26 virtual Vector calcForce(const Vector& data) const; -
orxonox/trunk/src/lib/physics/physics_connection.cc
r4597 r4728 24 24 #include "physics_interface.h" 25 25 26 #include "factory.h" 27 26 28 using namespace std; 29 30 CREATE_FACTORY(PhysicsConnection); 27 31 28 32 /** … … 39 43 } 40 44 45 PhysicsConnection::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 } 41 58 42 59 /** … … 50 67 51 68 /** 69 \param subjectName the name of the Subject for this PhysicsConnection 70 */ 71 void 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 */ 81 void 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 /** 52 89 \brief applies the Force to some Object. 53 90 */ 54 91 void PhysicsConnection::apply(void) const 55 92 { 56 if (likely(this->type == PCON_PhysIField && this->field->getMagnitude() != 0.0)) 93 if (likely(this->type == PCON_PhysIField && this->field->getMagnitude() != 0.0 94 && this->subject != NULL && this->field != NULL)) 57 95 this->subject->applyField(this->field); 58 96 else ; -
orxonox/trunk/src/lib/physics/physics_connection.h
r4597 r4728 30 30 PhysicsConnection(PhysicsInterface* subject, Field* field); 31 31 // PhysicsConnection(PhysicsInterface* partnerOne, PhysicsInterface* partnerTwo); 32 PhysicsConnection(const TiXmlElement* root); 32 33 33 34 virtual ~PhysicsConnection(); 35 36 void setSubject(const char* subjectName); 37 void setField(const char* fieldName); 34 38 35 39 void apply(void) const; -
orxonox/trunk/src/lib/physics/physics_engine.cc
r4597 r4728 21 21 22 22 #include "list.h" 23 #include "game_loader.h" 24 #include "tinyxml.h" 23 25 24 26 using namespace std; … … 51 53 } 52 54 55 /** 56 \param root the XML-element to load settings from 57 */ 58 void loadParams(const TiXmlElement* root) 59 { 60 const TiXmlElement* element; 61 62 PRINTF(4)("Loading Physical Fields\n"); 63 element = root->FirstChildElement("Fields"); 64 { 65 element = element->FirstChildElement(); 66 GameLoader::getInstance()->fabricate(element); 67 68 element = element->NextSiblingElement(); 69 } 70 71 PRINTF(4)("Loading Physical Connections\n"); 72 element = root->FirstChildElement("PhysicsConnections"); 73 { 74 element = element->FirstChildElement(); 75 GameLoader::getInstance()->fabricate(element); 76 77 element = element->NextSiblingElement(); 78 } 79 80 } 81 82 83 53 84 54 85 /** … … 75 106 76 107 /** 108 \param physicsInterfaceName the Name of the PhysicsInterface to search for 109 \returns the PhysicsInterface if found, or NULL if not 110 */ 111 PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const char* physicsInterfaceName) const 112 { 113 tIterator<PhysicsInterface>* tmpIt = interfaces->getIterator(); 114 PhysicsInterface* tmpInt = tmpIt->nextElement(); 115 while(tmpInt) 116 { 117 if (!strcmp(physicsInterfaceName, tmpInt->getName())) 118 { 119 delete tmpIt; 120 return tmpInt; 121 } 122 tmpInt = tmpIt->nextElement(); 123 } 124 delete tmpIt; 125 return NULL; 126 } 127 128 /** 77 129 \brief adds a Field to the list of handeled fields 78 130 \param field the field to add … … 97 149 98 150 /** 151 \param FieldName the Name of the PhysicsInterface to search for 152 \returns the Field if found, or NULL if not 153 */ 154 Field* PhysicsEngine::getFieldByName(const char* FieldName) const 155 { 156 tIterator<Field>* tmpIt = fields->getIterator(); 157 Field* tmpField = tmpIt->nextElement(); 158 while(tmpField) 159 { 160 if (!strcmp(FieldName, tmpField->getName())) 161 { 162 delete tmpIt; 163 return tmpField; 164 } 165 tmpField = tmpIt->nextElement(); 166 } 167 delete tmpIt; 168 return NULL; 169 } 170 171 172 173 /** 99 174 \brief adds A Physical Connection to the List of Connections 100 175 \param connection the Connection to add … … 118 193 } 119 194 120 195 /** 196 \param physicsConnectionName the Name of the PhysicsInterface to search for 197 \returns the PhysicsConnection if found, or NULL if not 198 */ 199 PhysicsConnection* PhysicsEngine::getPhysicsConnectionByName(const char* physicsConnectionName) const 200 { 201 tIterator<PhysicsConnection>* tmpIt = connections->getIterator(); 202 PhysicsConnection* tmpConn = tmpIt->nextElement(); 203 while(tmpConn) 204 { 205 if (!strcmp(physicsConnectionName, tmpConn->getName())) 206 { 207 delete tmpIt; 208 return tmpConn; 209 } 210 tmpConn = tmpIt->nextElement(); 211 } 212 delete tmpIt; 213 return NULL; 214 } 121 215 122 216 -
orxonox/trunk/src/lib/physics/physics_engine.h
r4558 r4728 16 16 // Forward Declaration 17 17 template<class T> class tList; 18 18 class TiXmlElement; 19 19 20 20 //! A class, that brings things into motion through Physics. … … 26 26 inline static PhysicsEngine* getInstance(void) { if (!singletonRef) singletonRef = new PhysicsEngine(); return singletonRef; }; 27 27 28 void addPhysicsInterface(PhysicsInterface* physicsInterface); 29 void removePhysicsInterface(PhysicsInterface* physicsInterface); 28 void loadParams(const TiXmlElement* root); 30 29 31 void addField(Field* field); 32 void removeField(Field* field); 30 void addPhysicsInterface(PhysicsInterface* physicsInterface); 31 void removePhysicsInterface(PhysicsInterface* physicsInterface); 32 PhysicsInterface* getPhysicsInterfaceByName(const char* physicsInterfaceName) const; 33 33 34 void addConnection(PhysicsConnection* connection); 35 void removeConnection(PhysicsConnection* connection); 34 void addField(Field* field); 35 void removeField(Field* field); 36 Field* getFieldByName(const char* FieldName) const; 36 37 37 void tick(float dt); 38 void addConnection(PhysicsConnection* connection); 39 void removeConnection(PhysicsConnection* connection); 40 PhysicsConnection* getPhysicsConnectionByName(const char* physicsConnectionName) const; 38 41 39 void debug(void) const; 42 43 void tick(float dt); 44 45 void debug(void) const; 40 46 41 47 private:
Note: See TracChangeset
for help on using the changeset viewer.