hx3d  1
2D/3D Simple Game Framework
attractor.hpp
1 /*
2  Physical attractor.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_PHYSICS_2D_ATTRACTOR
22 #define HX3D_PHYSICS_2D_ATTRACTOR
23 
24 #include "hx3d/utils/ptr.hpp"
25 
26 #include "hx3d/physics/2d/collider.hpp"
27 
28 namespace hx3d {
29 namespace physics2d {
30 
34 struct Attractor {
35 
39  enum class Type {
41  Global = 1,
43  Zone,
45  Point
46  };
47 
51  unsigned int priority;
52 
58  Attractor(Type type);
59 
67  virtual bool overlaps(const Ptr<Collider>& collider) = 0;
68 
75  virtual void computeForce(const Ptr<Collider>& collider, const float dt) = 0;
76 
84  static void setCurrentAttractor(const Ptr<Collider>& collider, const Ptr<Attractor>& attractor, const float dt);
85 
93  static void applyForce(const Ptr<Collider>& collider, const Ptr<Attractor>& attractor, const float dt);
94 };
95 
96 } /* physics2d */
97 } /* hx3d */
98 
99 #endif
Type
Attractor type.
Definition: attractor.hpp:39
virtual bool overlaps(const Ptr< Collider > &collider)=0
Check if a collider overlaps the attractor.
Attractor(Type type)
Create an attractor.
Definition: attractor.cpp:6
static void applyForce(const Ptr< Collider > &collider, const Ptr< Attractor > &attractor, const float dt)
Apply an attractor force on a collider.
Definition: attractor.cpp:18
hx3d framework namespace
Definition: audio.hpp:26
unsigned int priority
Attractor priority.
Definition: attractor.hpp:51
static void setCurrentAttractor(const Ptr< Collider > &collider, const Ptr< Attractor > &attractor, const float dt)
Defines the current attractor on a collider.
Definition: attractor.cpp:13
virtual void computeForce(const Ptr< Collider > &collider, const float dt)=0
Compute the gravity force on a collider.
Physical gravity attractor.
Definition: attractor.hpp:34
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34
Type type
Attractor type.
Definition: attractor.hpp:49