Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 28, 2005, 11:56:46 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more loading (especially for physics)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/physics/physics_connection.cc

    r4597 r4728  
    2424#include "physics_interface.h"
    2525
     26#include "factory.h"
     27
    2628using namespace std;
     29
     30CREATE_FACTORY(PhysicsConnection);
    2731
    2832/**
     
    3943}
    4044
     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}
    4158
    4259/**
     
    5067
    5168/**
     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/**
    5289    \brief applies the Force to some Object.
    5390*/
    5491void PhysicsConnection::apply(void) const
    5592{
    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))
    5795      this->subject->applyField(this->field);
    5896  else ;
Note: See TracChangeset for help on using the changeset viewer.