physics_world.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Arkadiusz Kalinowski
27 */
28 
29 
30 #pragma once
31 
32 #include "../api_physics2d.h"
33 #include "../../Core/Signals/signal_v0.h"
34 #include "../../Core/Signals/signal_v1.h"
35 #include <memory>
36 
37 namespace clan
38 {
41 
42 class Physic;
43 class PhysicsWorldDescription;
44 class PhysicsWorld_Impl;
45 class PhysicsContext;
46 class PhysicsQueryAssistant;
47 
52 class CL_API_PHYSICS PhysicsWorld
53 {
56 public:
58  PhysicsWorld();
59 
63  PhysicsWorld(const PhysicsWorldDescription &description);
64 
65  ~PhysicsWorld();
66 
70 public:
71 
73  Signal_v1<float> &sig_world_step();
74 
76  Signal_v0 &sig_world_destroyed();
77 
79  bool is_null() const { return !impl; }
80 
82  bool is_olm_enabled() const;
83 
85  void throw_if_null() const;
86 
88  std::string get_name() const;
89 
91  double get_timestep() const;
92 
94  int get_velocity_iterations() const;
95 
97  int get_position_iterations() const;
98 
100  int get_physic_scale() const;
101 
103  PhysicsContext &get_pc();
104 
106  PhysicsQueryAssistant &get_qa();
107 
111 public:
112 
114  void set_olm(const bool value = true);
115 
117  void step();
118 
124  void step(float timestep, int velocity_iterations = 8, int position_iterations = 3);
125 
129 
130 private:
131  std::shared_ptr<PhysicsWorld_Impl> impl;
132 
134 
135  friend class PhysicsWorld_Impl;
136  friend class PhysicsContext;
137  friend class PhysicsDebugDraw;
138 
139  friend class PhysicsQueryAssistant;
143  friend class MouseJointDescription;
144 
145  friend class MouseJoint;
146 
147  friend class PolygonShape;
148  friend class ChainShape;
149  friend class CircleShape;
150  friend class EdgeShape;
151 
152  friend class BodyDescription;
153  friend class Body;
154  friend class FixtureDescription;
155  friend class Fixture;
156 
157 };
158 
159 }
160 
MouseJointDescription class.
Definition: mouse_joint_description.h:47
BodyDescription class.
Definition: body_description.h:55
Physics World description class.
Definition: physics_world_description.h:55
Signal_v1.
Definition: signal_v1.h:110
PhysicsDebugDraw class.
Definition: physics_debug_draw.h:65
Circle Shape class.
Definition: circle_shape.h:47
Top-level world class.
Definition: physics_world.h:52
Edge Shape class.
Definition: edge_shape.h:48
PrismaticJointDescription class.
Definition: prismatic_joint_description.h:47
Body class.
Definition: body.h:52
MouseJoint class.
Definition: mouse_joint.h:48
DistanceJointDescription class.
Definition: distance_joint_description.h:47
bool is_null() const
Returns true if this object is invalid.
Definition: physics_world.h:79
Chain Shape class.
Definition: chain_shape.h:52
Definition: physics_context.h:45
Definition: physics_query_assistant.h:45
RevoluteJointDescription class.
Definition: revolute_joint_description.h:47
Signal_v0.
Definition: signal_v0.h:107
int step(int edge, int x)
Definition: cl_math.h:156
Fixture class.
Definition: fixture.h:48
Polygon Shape class.
Definition: polygon_shape.h:52
FixtureDescription class.
Definition: fixture_description.h:40