Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/physics/physics_connection.cc @ 9716

Last change on this file since 9716 was 9716, checked in by bensch, 18 years ago

more renamings

File size: 2.7 KB
RevLine 
[4597]1/*
[1853]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.
[1855]10
11   ### File Specific:
[4181]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PHYSICS
[1853]17
[4181]18#include "physics_connection.h"
[1853]19
[4183]20#include "physics_engine.h"
21
[4375]22#include "field.h"
23#include "particle_system.h"
24#include "physics_interface.h"
25
[7193]26#include "util/loading/factory.h"
27#include "util/loading/load_param.h"
[4728]28
[9716]29#include "class_id_DEPRECATED.h"
[9715]30ObjectListDefinition(PhysicsConnection);
[9709]31CREATE_FACTORY(PhysicsConnection);
[4480]32/**
[4836]33 *  creates a PhysicsConnection
[4480]34*/
[4377]35PhysicsConnection::PhysicsConnection(PhysicsInterface* subject, Field* field)
[3365]36{
[9686]37  this->registerObject(this, PhysicsConnection::_objectList);
[4377]38  this->type = PCON_PhysIField;
[4731]39
[4377]40  this->subject = subject;
[4182]41  this->field = field;
[4183]42
43  PhysicsEngine::getInstance()->addConnection(this);
[3365]44}
[1853]45
[4728]46PhysicsConnection::PhysicsConnection(const TiXmlElement* root)
47{
[9686]48  this->registerObject(this, PhysicsConnection::_objectList);
[4728]49  this->type = PCON_PhysIField;
[1853]50
[6512]51  BaseObject::loadParams(root);
[4728]52
[5671]53  LoadParam(root, "subject", this, PhysicsConnection, setSubject)
[4728]54      .describe("set the subject by a name");
55
[5671]56  LoadParam(root, "field", this, PhysicsConnection, setField)
[4728]57      .describe("set the field by name");
[4731]58
59  PhysicsEngine::getInstance()->addConnection(this);
[4728]60}
61
[3245]62/**
[4836]63 *  standard deconstructor
[1853]64
[3245]65*/
[4597]66PhysicsConnection::~PhysicsConnection ()
[3543]67{
[4183]68  PhysicsEngine::getInstance()->removeConnection(this);
[3543]69}
[4181]70
[4597]71/**
[4836]72 * @param subjectName the name of the Subject for this PhysicsConnection
[4728]73*/
[7221]74void PhysicsConnection::setSubject(const std::string& subjectName)
[4728]75{
76  this->subject = PhysicsEngine::getInstance()->getPhysicsInterfaceByName(subjectName);
77  if (this->subject == NULL)
[4731]78  {
[7221]79    PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName.c_str());
[4731]80  }
81  else
[9406]82    PRINTF(5)("subject::%s\n", this->subject->getCName());
[4728]83}
84
85/**
[4836]86* @param fieldName the Name of the Field for this connection
[4728]87*/
[7221]88void PhysicsConnection::setField(const std::string& fieldName)
[4728]89{
90  this->field = PhysicsEngine::getInstance()->getFieldByName(fieldName);
91  if (this->field == NULL)
[4731]92  {
[7221]93    PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName.c_str());
[4731]94  }
95  else
[9406]96    PRINTF(5)("field::%s\n", this->field->getCName());
[4731]97
[4728]98}
99
100/**
[4836]101  *  applies the Force to some Object.
[4182]102*/
[4746]103void PhysicsConnection::apply() const
[4182]104{
[4728]105  if (likely(this->type == PCON_PhysIField && this->field->getMagnitude() != 0.0
106      && this->subject != NULL && this->field != NULL))
[4395]107      this->subject->applyField(this->field);
[4378]108  else ;
[4181]109}
Note: See TracBrowser for help on using the repository browser.