This is a legacy Trac instance left read-only for reference purposes. More info. dev main | home

Changeset 185

Show
Ignore:
Timestamp:
02/27/2010 09:37:51 PM (2 years ago)
Author:
mceier
Message:

CollisionSensor?

Signed-off-by: Mariusz Ceier <mceier@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/waterworld/sim2/Animat.h

    r184 r185  
    1313#include "Types.h" 
    1414#include "ID.h" 
     15#include "IntrusivePtrBase.h" 
    1516#include "ChemicalSignals.h" 
    1617#include "Actuators.h" 
    1718#include "Sensors.h" 
     19#include "ContactPoints.h" 
    1820#include "PhysicalBody.h" 
    19 #include "IntrusivePtrBase.h" 
    2021 
    2122namespace waterworld 
     
    5152                Sensors m_sensors; 
    5253                /** 
     54                 * Contact points with other animats 
     55                 */ 
     56                ContactPoints m_contact_points; 
     57                /** 
    5358                 * Physical body of animat ( "oriented" sphere ) 
    5459                 */ 
    5560                boost::intrusive_ptr<PhysicalBody> m_body; 
    56  
    5761                /** 
    5862                 * Pointer to a function called on collision detect 
    5963                 */ 
    6064                void (*collision)(); 
    61  
    6265                /** 
    6366                 * On/Off collision detection for this body/animat 
    6467                 */ 
    6568                bool cde;       //CollisiondDetectionEnabled 
     69                /** 
     70                 * True if collisions are enabled ... 
     71                 */ 
     72                bool m_enabled_collisions; 
    6673        public: 
    6774                /** 
     
    8693 
    8794                /** 
    88                  * \return constant chemical signals that this animat "emits" 
     95                 * \return constant chemical signals that this animat "emits" ( read-only ) 
    8996                 */ 
    9097                ChemicalSignals const &getChemicalSignals() const; 
    9198                /** 
    92                  * \return constant actuators 
     99                 * \return constant actuators ( read-only ) 
    93100                 */ 
    94101                Actuators const &getActuators() const; 
    95102                /** 
    96                  * \return constant sensors 
     103                 * \return constant sensors ( read-only ) 
    97104                 */ 
    98105                Sensors const &getSensors() const; 
     106                /** 
     107                 * \return contact points ( read-only ) 
     108                 */ 
     109                ContactPoints const &getContactPoints() const; 
    99110                /** 
    100111                 * \return chemical signals that this animat "emits" 
     
    109120                 */ 
    110121                Sensors &getSensors(); 
     122                /** 
     123                 * \return contact points 
     124                 */ 
     125                ContactPoints &getContactPoints(); 
    111126                /** 
    112127                 * \return physical body 
     
    126141                const AnimatID &getParentID() const; 
    127142                /** 
     143                 * Enable collisions - use getContactPoints method to access collision points 
     144                 */ 
     145                void enableCollisions(); 
     146                /** 
     147                 * Disable collisions 
     148                 */ 
     149                void disableCollisions(); 
     150                /** 
     151                 * \return True if detection of collisions for this animat is enabled 
     152                 */ 
     153                bool hasEnabledCollisions() const; 
     154                /** 
    128155                 * Control animat ( invoked after updated sensors and before updating actuators ) 
    129156                 * Default implementation does nothing. 
     
    131158                 * \param dt elapsed time 
    132159                 */ 
    133                 virtual void control(World *world, real_t dt); 
     160                virtual void control(boost::intrusive_ptr<World> world, real_t dt); 
    134161                /** 
    135162                 * Update animat 
     
    137164                 * \param dt elapsed time 
    138165                 */ 
    139                 void update(World *world, real_t dt); 
     166                void update(boost::intrusive_ptr<World> world, real_t dt); 
    140167                Animat(ID const &id); 
    141168                Animat(ID const &id,ID const &parentid); 
  • trunk/include/waterworld/sim2/PhysicalBody.h

    r182 r185  
    3030                PhysicalBody(); 
    3131                PhysicalBody(boost::intrusive_ptr<Animat> animat); 
     32                /** 
     33                 * \return Animat 
     34                 */ 
    3235                boost::intrusive_ptr<Animat> getAnimat() const; 
     36                /** 
     37                 * Set animat 
     38                 */ 
    3339                void setAnimat(boost::intrusive_ptr<Animat> newAnimat); 
     40                /** 
     41                 * Set PAL body 
     42                 */ 
    3443                void setBody(palBody *body); 
     44                /** 
     45                 * \return PAL body 
     46                 */ 
    3547                palBody *getBody() const; 
     48                /** 
     49                 * Applies force 
     50                 */ 
    3651                void applyForce(Force const &force, Position const &position); 
     52                /** 
     53                 * Sets position 
     54                 */ 
    3755                void setPosition(Position const &); 
     56                /** 
     57                 * \return position 
     58                 */ 
    3859                Position getPosition() const; 
    3960                virtual ~PhysicalBody(); 
  • trunk/include/waterworld/sim2/Sensor.h

    r175 r185  
    1919                Sensor(); 
    2020                Sensor(Sensor const &sensor); 
     21                Sensor &operator=(Sensor const &sensor); 
    2122                virtual void update(boost::intrusive_ptr<Animat> animat,  
    2223                        boost::intrusive_ptr<World> world, real_t dt); 
  • trunk/src/waterworld/sim2/Animat.cpp

    r184 r185  
    55         
    66        Animat::Animat(ID const &id) : 
    7                 m_id(id), m_parent_id() 
     7                m_id(id), m_parent_id(), 
     8                m_enabled_collisions(false) 
    89        { 
    910        } 
    1011 
    1112        Animat::Animat(ID const &id, ID const &parentid) : 
    12                 m_id(id), m_parent_id(parentid) 
     13                m_id(id), m_parent_id(parentid), 
     14                m_enabled_collisions(false) 
    1315        { 
    1416        } 
     
    2123                m_signals(chemicalSignals), 
    2224                m_actuators(actuators), 
    23                 m_sensors(sensors) 
     25                m_sensors(sensors), 
     26                m_enabled_collisions(false) 
    2427        { 
    2528        } 
     
    3235                m_signals(chemicalSignals), 
    3336                m_actuators(actuators), 
    34                 m_sensors(sensors) 
     37                m_sensors(sensors), 
     38                m_enabled_collisions(false) 
    3539        { 
    3640        } 
     
    4246                m_actuators(animat.m_actuators), 
    4347                m_sensors(animat.m_sensors), 
    44                 m_body(animat.m_body) 
     48                m_contact_points(animat.m_contact_points), 
     49                m_body(animat.m_body), 
     50                m_enabled_collisions(animat.m_enabled_collisions) 
    4551        { 
    4652        } 
     
    8187        } 
    8288 
     89        ContactPoints const &Animat::getContactPoints() const 
     90        { 
     91                return m_contact_points; 
     92        } 
     93 
    8394        ChemicalSignals &Animat::getChemicalSignals() 
    8495        { 
     
    94105        { 
    95106                return m_sensors; 
     107        } 
     108 
     109        ContactPoints &Animat::getContactPoints() 
     110        { 
     111                return m_contact_points; 
    96112        } 
    97113 
     
    120136        } 
    121137 
    122         void Animat::control(World *world, real_t dt) 
     138        void Animat::enableCollisions() 
     139        { 
     140                m_enabled_collisions = true; 
     141        } 
     142 
     143        void Animat::disableCollisions() 
     144        { 
     145                m_enabled_collisions = false; 
     146        } 
     147 
     148        bool Animat::hasEnabledCollisions() const 
     149        { 
     150                return m_enabled_collisions; 
     151        } 
     152 
     153        void Animat::control(boost::intrusive_ptr<World> world, real_t dt) 
    123154        { 
    124155        } 
    125156 
    126         void Animat::update(World *world, real_t dt) 
     157        void Animat::update(boost::intrusive_ptr<World> world, real_t dt) 
    127158        { 
    128159                for(Sensors::iterator i=m_sensors.begin();i!=m_sensors.end();++i) 
  • trunk/src/waterworld/sim2/CMakeLists.txt

    r175 r185  
    1414        ${S}/EventsThread.cpp 
    1515        ${S}/ID.cpp 
     16        ${S}/ContactPoint.cpp 
     17        ${S}/CollisionSensor.cpp 
    1618        ) 
    1719 
  • trunk/src/waterworld/sim2/Sensor.cpp

    r175 r185  
    1313        } 
    1414 
     15        Sensor &Sensor::operator=(Sensor const &sensor) 
     16        { 
     17                IntrusivePtrBase::operator=(sensor); 
     18                return *this; 
     19        } 
     20 
    1521        void Sensor::update(boost::intrusive_ptr<Animat> animat, boost::intrusive_ptr<World> world, real_t dt) 
    1622        {