Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: new Executor construct, that is much more typesafe, faster, and easier to extend…

Also changed the LoadParam process, and adapted ScriptEngine calls

Then at the end, some missing headers appeared, and appended them to all the cc-files again.

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