Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4182 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
May 14, 2005, 1:15:25 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/physics: connection of Physical effects should work on ParticleSystems

Location:
orxonox/branches/physics/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics/src/lib/graphics/particles/particle_system.cc

    r4178 r4182  
    2323#include "material.h"
    2424
     25#include "field.h"
     26
    2527using namespace std;
    2628
     
    3436ParticleSystem::ParticleSystem (unsigned int maxCount, PARTICLE_TYPE type)
    3537{
    36    this->setClassName ("ParticleSystem");
    37    this->material = NULL;
    38    this->name = NULL;
    39    this->maxCount = maxCount;
    40    this->count = 0;
    41    this->particles = NULL;
    42    this->deadList = NULL;
    43    this->setConserve(1);
    44    this->setLifeSpan(1);
    45    this->setInheritSpeed(0);
    46    this->glID = NULL;
    47    this->setRadius(1.0, 1.0, 0.0);
    48    this->setType(type, 1);
    49    ParticleEngine::getInstance()->addSystem(this);
     38  this->setClassName ("ParticleSystem");
     39  this->material = NULL;
     40  this->name = NULL;
     41  this->maxCount = maxCount;
     42  this->count = 0;
     43  this->particles = NULL;
     44  this->deadList = NULL;
     45  this->setConserve(1);
     46  this->setLifeSpan(1);
     47  this->setInheritSpeed(0);
     48  this->glID = NULL;
     49  this->setRadius(1.0, 1.0, 0.0);
     50  this->setType(type, 1);
     51  ParticleEngine::getInstance()->addSystem(this);
    5052}
    5153
     
    207209      tickPart->radius += tickPart->radiusIt * dt;
    208210
     211      // applying force to the System.
     212      tickPart->velocity += tickPart->extForce * tickPart->mass;
     213      tickPart->extForce = Vector(0,0,0);
     214
    209215      // many more to come
    210 
    211216
    212217      if (this->conserve < 1.0)
     
    240245    }
    241246}
     247
     248/**
     249    \brief applies some force to a Particle.
     250 */
     251void ParticleSystem::applyField(Field* field)
     252{
     253  Particle* tickPart = particles;
     254  while (tickPart)
     255    {
     256      tickPart->extForce += field->calcForce(tickPart->position);
     257      tickPart = tickPart->next;
     258    }
     259}
     260
    242261
    243262/**
  • orxonox/branches/physics/src/lib/graphics/particles/particle_system.h

    r4178 r4182  
    3131class Material;
    3232class ParticleEmitter;
    33 
     33class Field;
    3434
    3535//! A struct for one Particle
     
    3939  Vector position;            //!< The current position of this particle.
    4040  Vector velocity;            //!< The current velocity of this particle.
     41  Vector extForce;            //!< The external Force that influences this Particle.
    4142  Quaternion rotation;        //!< The current rotation of this particle.
    4243  float mass;                 //!< The mass of this particle.
     
    6869  void setConserve(float conserve);
    6970  void setMass(float mass, float randomMass);
     71
     72  void applyField(Field* field);
    7073
    7174  void tick(float dt);
  • orxonox/branches/physics/src/util/physics/physics_connection.cc

    r4181 r4182  
    1717
    1818#include "physics_connection.h"
    19 
     19#include "field.h"
     20#include "particle_system.h"
    2021
    2122using namespace std;
    2223
    2324
    24 /**
    25    \brief standard constructor
    26 */
    27 PhysicsConnection::PhysicsConnection ()
     25
     26PhysicsConnection::PhysicsConnection(ParticleSystem* particleSystem, Field* field)
    2827{
    29    this->setClassName ("PhysicsConnection");
    30    connection = NULL;
     28  this->type = PCON_ParticlesField;
     29  this->particleSystem = particleSystem;
     30  this->field = field;
    3131}
    3232
     
    3838PhysicsConnection::~PhysicsConnection ()
    3939{
    40   if (this->connection)
    41     delete this->connection;
     40
    4241}
    4342
     43/**
     44    \brief applies the Force to some Object.
     45*/
     46void PhysicsConnection::apply(void) const
     47{
     48  switch(this->type)
     49    {
     50    case PCON_IPhysField:
     51     
     52      break;
    4453
     54    case PCON_ParticlesField:
     55      this->particleSystem->applyField(this->field);
    4556
     57      break;
     58     
     59    case PCON_IPhysIPhys:
    4660
    47 
    48 
    49 bool PhysicsConnection::addConnection(ParticleSystem* particleSystem, Field* field)
    50 {
    51   if (!this->connection)
    52     {
    53       this->connection = new PhysConnection;
    54       this->connection->type = PCON_ParticlesField;
    55       this->connection->particleSystem = particleSystem;
    56       this->connection->field = field;
     61      break;
    5762    }
    5863}
  • orxonox/branches/physics/src/util/physics/physics_connection.h

    r4181 r4182  
    66#ifndef _PHYSICS_CONNECTION_H
    77#define _PHYSICS_CONNECTION_H
    8 
    9 #include "base_object.h"
    108
    119//! An enumerator for different ConnectionTypes
     
    2018class ParticleSystem;
    2119
     20//! A class that Handles Physical Connection between subjects
     21class PhysicsConnection {
    2222
    23 typedef struct PhysConnection
    24 {
     23 public:
     24  PhysicsConnection(IPhysics* partnerOne, IPhysics* partnerTwo);
     25  PhysicsConnection(IPhysics* subject, Field* field);
     26  PhysicsConnection(ParticleSystem* particleSystem, Field* field);
     27
     28  virtual ~PhysicsConnection();
     29
     30  void apply(void) const;
     31
     32 private:
    2533  PCON_Type type;                    //!< What kind of connection this is.
    26 
     34 
    2735  IPhysics* subject;                 //!< The main Subject of this Connection.
    2836  IPhysics* partner2;                //!< The second partner of this Connection.
    29 
     37 
    3038  ParticleSystem* particleSystem;    //!< A ParticleSystem in this Connection
    3139 
     
    3341};
    3442
    35 //! A class that Handles Physical Connection between subjects
    36 class PhysicsConnection : public BaseObject {
    37 
    38  public:
    39   PhysicsConnection();
    40   virtual ~PhysicsConnection();
    41 
    42   bool addConnection(IPhysics* partnerOne, IPhysics* partnerTwo);
    43   bool addConnection(IPhysics* subject, Field* field);
    44   bool addConnection(ParticleSystem* particleSystem, Field* field);
    45 
    46   inline PhysConnection* getConnection(void) const {return this->connection;}
    47 
    48  private:
    49   PhysConnection* connection;        //!< The Physical Connection.
    50 };
    51 
    5243#endif /* _PHYSICS_CONNECTION_H */
Note: See TracChangeset for help on using the changeset viewer.