Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/physics/physics_connection.cc @ 6281

Last change on this file since 6281 was 5750, checked in by bensch, 19 years ago

orxonox/trunk: merged the WorldEntities into the Trunk.
Merged with command:
svn merge branches/world_entities/ trunk/ -r5516:HEAD

conflics from world_entities changed in favor of branches/world_entity
all other conflict in favor of the trunk

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
[4728]26#include "factory.h"
[5155]27#include "load_param.h"
[4728]28
[1856]29using namespace std;
[1853]30
[5750]31CREATE_FACTORY(PhysicsConnection, CL_PHYSICS_CONNECTION);
[4728]32
[4480]33/**
[4836]34 *  creates a PhysicsConnection
[4480]35*/
[4377]36PhysicsConnection::PhysicsConnection(PhysicsInterface* subject, Field* field)
[3365]37{
[4597]38  this->setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");
[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{
49  this->setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");
50  this->type = PCON_PhysIField;
[1853]51
[4728]52  static_cast<BaseObject*>(this)->loadParams(root);
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*/
75void PhysicsConnection::setSubject(const char* subjectName)
76{
77  this->subject = PhysicsEngine::getInstance()->getPhysicsInterfaceByName(subjectName);
78  if (this->subject == NULL)
[4731]79  {
[4728]80    PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName);
[4731]81  }
82  else
83    PRINTF(5)("subject::%s\n", this->subject->getName());
[4728]84}
85
86/**
[4836]87* @param fieldName the Name of the Field for this connection
[4728]88*/
89void PhysicsConnection::setField(const char* fieldName)
90{
91  this->field = PhysicsEngine::getInstance()->getFieldByName(fieldName);
92  if (this->field == NULL)
[4731]93  {
94        PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName);
95  }
96  else
97    PRINTF(5)("field::%s\n", this->field->getName());
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.