Collision.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: Collision class
00018  * Author: Nate Koenig
00019  * Date: 13 Feb 2006
00020  */
00021 
00022 #ifndef COLLISION_HH
00023 #define COLLISION_HH
00024 
00025 #include "common/Event.hh"
00026 #include "common/CommonTypes.hh"
00027 
00028 #include "physics/PhysicsTypes.hh"
00029 #include "physics/Entity.hh"
00030 
00031 namespace gazebo
00032 {
00033     namespace physics
00034   {
00037 
00039     class Collision : public Entity
00040     {
00042       public: Collision(LinkPtr link);
00043     
00045       public: virtual ~Collision();
00046   
00048       public: void Fini();
00049   
00051       public: virtual void Load( sdf::ElementPtr &_sdf );
00052 
00053       public: virtual void Init();
00054 
00056       public: virtual void UpdateParameters( sdf::ElementPtr &_sdf );
00057 
00059       public: void Save(std::string &prefix, std::ostream &stream);
00060    
00062       public: void SetCollision(bool placeable);
00063     
00065       public: bool IsPlaceable() const;
00066       
00069       public: virtual void SetCategoryBits(unsigned int bits) = 0;
00070     
00073       public: virtual void SetCollideBits(unsigned int bits) = 0;
00074     
00076       public: void SetLaserRetro(float retro);
00077     
00079       public: float GetLaserRetro() const;
00080   
00082       public: void ShowBoundingBox(const bool &show);
00083   
00085       public: LinkPtr GetLink() const;
00086   
00088       public: ModelPtr GetModel() const;
00089   
00091       public: virtual math::Box GetBoundingBox() const = 0;
00092   
00094       public: unsigned int GetShapeType();
00095   
00097       public: void SetShape(ShapePtr shape);
00098               
00100       public: ShapePtr GetShape() const;
00101   
00103       public: void SetContactsEnabled(bool _enable);
00104   
00106       public: bool GetContactsEnabled() const;
00107   
00109       public: void AddContact(const Contact &contact);
00110   
00112       public: virtual math::Vector3 GetRelativeLinearVel() const;
00113   
00115       public: virtual math::Vector3 GetWorldLinearVel() const;
00116   
00118       public: virtual math::Vector3 GetRelativeAngularVel() const;
00119   
00121       public: virtual math::Vector3 GetWorldAngularVel() const;
00122   
00124       public: virtual math::Vector3 GetRelativeLinearAccel() const;
00125               
00127       public: virtual math::Vector3 GetWorldLinearAccel() const;
00128   
00130       public: virtual math::Vector3 GetRelativeAngularAccel() const;
00131   
00133       public: virtual math::Vector3 GetWorldAngularAccel() const;
00134   
00135       public: template< typename T>
00136               event::ConnectionPtr ConnectContact( T subscriber )
00137               { return contact.Connect(subscriber); }
00138       public: void DisconnectContact( event::ConnectionPtr &c )
00139               { contact.Disconnect(c); }
00140 
00142       public: void FillCollisionMsg( msgs::Collision &_msg );
00143 
00145       public: void ProcessMsg(const msgs::Collision &_msg);
00146 
00148       private: void EnabledCB(bool enabled);
00149   
00151       private: void CreateBoundingBox();
00152 
00153       private: msgs::Visual CreateCollisionVisual();
00154  
00156       protected: LinkPtr link;
00157     
00158       protected: bool placeable;
00159   
00160       private: float transparency;
00161   
00163       private: std::string bbVisual;
00164   
00165       protected: ShapePtr shape;
00166 
00167       private: bool contactsEnabled;
00168   
00169       public: event::EventT<void (const std::string &,
00170                                   const Contact &)> contact;
00171 
00172       public: SurfaceParamsPtr surface; 
00173       private: std::vector<event::ConnectionPtr> connections;
00174     };
00176   }
00177 }
00178 #endif