reflexion 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/application.cpp +5 -5
  3. data/.doc/ext/reflex/body.cpp +167 -0
  4. data/.doc/ext/reflex/capture_event.cpp +4 -4
  5. data/.doc/ext/reflex/draw_event.cpp +4 -4
  6. data/.doc/ext/reflex/event.cpp +4 -4
  7. data/.doc/ext/reflex/fixture.cpp +101 -0
  8. data/.doc/ext/reflex/focus_event.cpp +4 -4
  9. data/.doc/ext/reflex/frame_event.cpp +4 -4
  10. data/.doc/ext/reflex/image_view.cpp +22 -5
  11. data/.doc/ext/reflex/key_event.cpp +4 -4
  12. data/.doc/ext/reflex/native.cpp +6 -0
  13. data/.doc/ext/reflex/pointer_event.cpp +4 -4
  14. data/.doc/ext/reflex/reflex.cpp +2 -3
  15. data/.doc/ext/reflex/scroll_event.cpp +4 -4
  16. data/.doc/ext/reflex/selector.cpp +4 -4
  17. data/.doc/ext/reflex/style.cpp +4 -4
  18. data/.doc/ext/reflex/style_length.cpp +4 -4
  19. data/.doc/ext/reflex/style_length2.cpp +4 -4
  20. data/.doc/ext/reflex/style_length4.cpp +4 -4
  21. data/.doc/ext/reflex/update_event.cpp +4 -4
  22. data/.doc/ext/reflex/view.cpp +110 -8
  23. data/.doc/ext/reflex/wheel_event.cpp +4 -4
  24. data/.doc/ext/reflex/window.cpp +36 -12
  25. data/README.md +2 -2
  26. data/Rakefile +2 -1
  27. data/VERSION +1 -1
  28. data/ext/reflex/application.cpp +8 -8
  29. data/ext/reflex/body.cpp +181 -0
  30. data/ext/reflex/capture_event.cpp +4 -4
  31. data/ext/reflex/draw_event.cpp +4 -4
  32. data/ext/reflex/event.cpp +4 -4
  33. data/ext/reflex/fixture.cpp +108 -0
  34. data/ext/reflex/focus_event.cpp +4 -4
  35. data/ext/reflex/frame_event.cpp +4 -4
  36. data/ext/reflex/image_view.cpp +24 -5
  37. data/ext/reflex/key_event.cpp +4 -4
  38. data/ext/reflex/native.cpp +6 -0
  39. data/ext/reflex/pointer_event.cpp +4 -4
  40. data/ext/reflex/reflex.cpp +2 -3
  41. data/ext/reflex/scroll_event.cpp +4 -4
  42. data/ext/reflex/selector.cpp +4 -4
  43. data/ext/reflex/style.cpp +4 -4
  44. data/ext/reflex/style_length.cpp +4 -4
  45. data/ext/reflex/style_length2.cpp +4 -4
  46. data/ext/reflex/style_length4.cpp +4 -4
  47. data/ext/reflex/update_event.cpp +4 -4
  48. data/ext/reflex/view.cpp +126 -12
  49. data/ext/reflex/wheel_event.cpp +4 -4
  50. data/ext/reflex/window.cpp +39 -12
  51. data/include/reflex/bitmap.h +20 -0
  52. data/include/reflex/body.h +82 -0
  53. data/include/reflex/bounds.h +20 -0
  54. data/include/reflex/color.h +20 -0
  55. data/include/reflex/color_space.h +20 -0
  56. data/include/reflex/defs.h +5 -1
  57. data/include/reflex/event.h +16 -25
  58. data/include/reflex/fixture.h +116 -0
  59. data/include/reflex/font.h +20 -0
  60. data/include/reflex/image.h +20 -0
  61. data/include/reflex/image_view.h +1 -1
  62. data/include/reflex/matrix.h +20 -0
  63. data/include/reflex/painter.h +20 -0
  64. data/include/reflex/point.h +24 -0
  65. data/include/reflex/ruby/application.h +6 -0
  66. data/include/reflex/ruby/body.h +41 -0
  67. data/include/reflex/ruby/event.h +68 -0
  68. data/include/reflex/ruby/fixture.h +41 -0
  69. data/include/reflex/ruby/image_view.h +14 -0
  70. data/include/reflex/ruby/selector.h +14 -0
  71. data/include/reflex/ruby/style.h +14 -0
  72. data/include/reflex/ruby/style_length.h +26 -0
  73. data/include/reflex/ruby/view.h +43 -39
  74. data/include/reflex/ruby/window.h +27 -21
  75. data/include/reflex/ruby.h +2 -0
  76. data/include/reflex/shader.h +20 -0
  77. data/include/reflex/style.h +2 -3
  78. data/include/reflex/texture.h +20 -0
  79. data/include/reflex/view.h +45 -24
  80. data/include/reflex/window.h +11 -14
  81. data/include/reflex.h +3 -0
  82. data/lib/reflex/application.rb +6 -2
  83. data/lib/reflex/body.rb +17 -0
  84. data/lib/reflex/fixture.rb +17 -0
  85. data/lib/reflex/view.rb +16 -1
  86. data/lib/reflex/window.rb +13 -1
  87. data/lib/reflex.rb +2 -0
  88. data/reflex.gemspec +1 -1
  89. data/samples/bats.rb +4 -3
  90. data/samples/checker.rb +4 -3
  91. data/samples/fans.rb +4 -3
  92. data/samples/fps.rb +5 -3
  93. data/samples/grid.rb +5 -4
  94. data/samples/hello.rb +1 -1
  95. data/samples/image.rb +3 -2
  96. data/samples/ios/hello/hello/main.cpp +12 -3
  97. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +376 -123
  98. data/samples/key.rb +5 -4
  99. data/samples/layout.rb +3 -2
  100. data/samples/model.rb +3 -2
  101. data/samples/osx/hello/hello/main.cpp +12 -3
  102. data/samples/osx/hello/hello.xcodeproj/project.pbxproj +375 -120
  103. data/samples/physics.rb +37 -0
  104. data/samples/repl.rb +3 -2
  105. data/samples/shader.rb +4 -4
  106. data/samples/shapes.rb +4 -4
  107. data/samples/text.rb +6 -4
  108. data/samples/tree.rb +5 -4
  109. data/samples/views.rb +3 -2
  110. data/samples/visuals.rb +1 -2
  111. data/src/body.cpp +244 -0
  112. data/src/event.cpp +18 -18
  113. data/src/fixture.cpp +108 -0
  114. data/src/image_view.cpp +1 -1
  115. data/src/ios/native_window.h +2 -0
  116. data/src/ios/native_window.mm +18 -1
  117. data/src/ios/opengl_view.mm +8 -0
  118. data/src/ios/window.mm +24 -3
  119. data/src/ios/window_data.h +3 -3
  120. data/src/osx/native_window.mm +17 -1
  121. data/src/osx/window.mm +24 -3
  122. data/src/osx/window_data.h +3 -3
  123. data/src/physics/Box2D/Box2D.h +68 -0
  124. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.cpp +193 -0
  125. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.h +105 -0
  126. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp +99 -0
  127. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.h +91 -0
  128. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.cpp +138 -0
  129. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.h +74 -0
  130. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.cpp +467 -0
  131. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.h +101 -0
  132. data/src/physics/Box2D/Collision/Shapes/b2Shape.h +101 -0
  133. data/src/physics/Box2D/Collision/b2BroadPhase.cpp +119 -0
  134. data/src/physics/Box2D/Collision/b2BroadPhase.h +257 -0
  135. data/src/physics/Box2D/Collision/b2CollideCircle.cpp +154 -0
  136. data/src/physics/Box2D/Collision/b2CollideEdge.cpp +698 -0
  137. data/src/physics/Box2D/Collision/b2CollidePolygon.cpp +239 -0
  138. data/src/physics/Box2D/Collision/b2Collision.cpp +252 -0
  139. data/src/physics/Box2D/Collision/b2Collision.h +277 -0
  140. data/src/physics/Box2D/Collision/b2Distance.cpp +603 -0
  141. data/src/physics/Box2D/Collision/b2Distance.h +141 -0
  142. data/src/physics/Box2D/Collision/b2DynamicTree.cpp +778 -0
  143. data/src/physics/Box2D/Collision/b2DynamicTree.h +289 -0
  144. data/src/physics/Box2D/Collision/b2TimeOfImpact.cpp +486 -0
  145. data/src/physics/Box2D/Collision/b2TimeOfImpact.h +58 -0
  146. data/src/physics/Box2D/Common/b2BlockAllocator.cpp +215 -0
  147. data/src/physics/Box2D/Common/b2BlockAllocator.h +62 -0
  148. data/src/physics/Box2D/Common/b2Draw.cpp +44 -0
  149. data/src/physics/Box2D/Common/b2Draw.h +86 -0
  150. data/src/physics/Box2D/Common/b2GrowableStack.h +85 -0
  151. data/src/physics/Box2D/Common/b2Math.cpp +94 -0
  152. data/src/physics/Box2D/Common/b2Math.h +720 -0
  153. data/src/physics/Box2D/Common/b2Settings.cpp +44 -0
  154. data/src/physics/Box2D/Common/b2Settings.h +151 -0
  155. data/src/physics/Box2D/Common/b2StackAllocator.cpp +83 -0
  156. data/src/physics/Box2D/Common/b2StackAllocator.h +60 -0
  157. data/src/physics/Box2D/Common/b2Timer.cpp +101 -0
  158. data/src/physics/Box2D/Common/b2Timer.h +50 -0
  159. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp +53 -0
  160. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h +39 -0
  161. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp +53 -0
  162. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h +39 -0
  163. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.cpp +52 -0
  164. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.h +39 -0
  165. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.cpp +247 -0
  166. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.h +349 -0
  167. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +838 -0
  168. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.h +95 -0
  169. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +49 -0
  170. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +39 -0
  171. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +49 -0
  172. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +39 -0
  173. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +49 -0
  174. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +38 -0
  175. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +52 -0
  176. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.h +39 -0
  177. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +260 -0
  178. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.h +169 -0
  179. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +251 -0
  180. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.h +119 -0
  181. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.cpp +419 -0
  182. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.h +125 -0
  183. data/src/physics/Box2D/Dynamics/Joints/b2Joint.cpp +211 -0
  184. data/src/physics/Box2D/Dynamics/Joints/b2Joint.h +226 -0
  185. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.cpp +304 -0
  186. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.h +133 -0
  187. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.cpp +222 -0
  188. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.h +129 -0
  189. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +629 -0
  190. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.h +196 -0
  191. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +348 -0
  192. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.h +152 -0
  193. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +502 -0
  194. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.h +204 -0
  195. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.cpp +241 -0
  196. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.h +114 -0
  197. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.cpp +344 -0
  198. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.h +126 -0
  199. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.cpp +419 -0
  200. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.h +210 -0
  201. data/src/physics/Box2D/Dynamics/b2Body.cpp +549 -0
  202. data/src/physics/Box2D/Dynamics/b2Body.h +860 -0
  203. data/src/physics/Box2D/Dynamics/b2ContactManager.cpp +296 -0
  204. data/src/physics/Box2D/Dynamics/b2ContactManager.h +52 -0
  205. data/src/physics/Box2D/Dynamics/b2Fixture.cpp +303 -0
  206. data/src/physics/Box2D/Dynamics/b2Fixture.h +345 -0
  207. data/src/physics/Box2D/Dynamics/b2Island.cpp +539 -0
  208. data/src/physics/Box2D/Dynamics/b2Island.h +93 -0
  209. data/src/physics/Box2D/Dynamics/b2TimeStep.h +70 -0
  210. data/src/physics/Box2D/Dynamics/b2World.cpp +1339 -0
  211. data/src/physics/Box2D/Dynamics/b2World.h +354 -0
  212. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.cpp +36 -0
  213. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.h +155 -0
  214. data/src/physics/Box2D/Rope/b2Rope.cpp +259 -0
  215. data/src/physics/Box2D/Rope/b2Rope.h +115 -0
  216. data/src/style.cpp +2 -2
  217. data/src/view.cpp +217 -17
  218. data/src/window.cpp +25 -15
  219. data/src/world.cpp +206 -0
  220. data/src/world.h +96 -0
  221. data/task/box2d.rake +25 -0
  222. data/test/test_view.rb +5 -5
  223. metadata +125 -3
data/src/ios/window.mm CHANGED
@@ -2,7 +2,6 @@
2
2
  #include "reflex/window.h"
3
3
 
4
4
 
5
- #include <rays/bounds.h>
6
5
  #include "reflex/event.h"
7
6
  #include "reflex/exception.h"
8
7
  #include "window_data.h"
@@ -111,8 +110,17 @@ namespace Reflex
111
110
  if (!*this)
112
111
  invalid_state_error(__FILE__, __LINE__);
113
112
 
114
- if (--self->hide_count == 0)
113
+ int new_count = self->hide_count - 1;
114
+ if (new_count == 0)
115
+ {
116
+ Event e;
117
+ on_show(&e);
118
+ if (e.is_blocked()) return;
119
+
115
120
  [self->native makeKeyAndVisible];
121
+ }
122
+
123
+ self->hide_count = new_count;
116
124
  }
117
125
 
118
126
  void
@@ -121,8 +129,17 @@ namespace Reflex
121
129
  if (!*this)
122
130
  invalid_state_error(__FILE__, __LINE__);
123
131
 
124
- if (++self->hide_count == 1)
132
+ int new_count = self->hide_count + 1;
133
+ if (new_count == 1)
134
+ {
135
+ Event e;
136
+ on_hide(&e);
137
+ if (e.is_blocked()) return;
138
+
125
139
  not_implemented_error(__FILE__, __LINE__);
140
+ }
141
+
142
+ self->hide_count = new_count;
126
143
  }
127
144
 
128
145
  void
@@ -131,6 +148,10 @@ namespace Reflex
131
148
  if (!*this)
132
149
  invalid_state_error(__FILE__, __LINE__);
133
150
 
151
+ Event e;
152
+ on_close(&e);
153
+ if (e.is_blocked()) return;
154
+
134
155
  not_implemented_error(__FILE__, __LINE__);
135
156
  }
136
157
 
@@ -6,8 +6,8 @@
6
6
 
7
7
  #include <map>
8
8
  #include <xot/time.h>
9
- #include <rays/point.h>
10
- #include <rays/painter.h>
9
+ #include <reflex/point.h>
10
+ #include <reflex/painter.h>
11
11
  #include <reflex/window.h>
12
12
  #include <reflex/view.h>
13
13
 
@@ -37,7 +37,7 @@ namespace Reflex
37
37
 
38
38
  View::Ref root, focus;
39
39
 
40
- Rays::Point prev_position, prev_size;
40
+ Point prev_position, prev_size;
41
41
 
42
42
  double prev_time_update, prev_time_draw, prev_fps;
43
43
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  #include <assert.h>
6
6
  #import <Cocoa/Cocoa.h>
7
- #include <rays/bounds.h>
7
+ #include "reflex/bounds.h"
8
8
  #include "reflex/window.h"
9
9
  #include "reflex/exception.h"
10
10
  #include "event.h"
@@ -15,6 +15,16 @@
15
15
  #define REF (*pref)
16
16
 
17
17
 
18
+ namespace Reflex
19
+ {
20
+
21
+ void update_view_tree (View* v, const UpdateEvent& e);
22
+
23
+ void draw_view_tree (View* v, const DrawEvent& e, const Point& offset, const Bounds& clip);
24
+
25
+ }// Reflex
26
+
27
+
18
28
  static const NSUInteger WINDOW_STYLE_MASK =
19
29
  NSTitledWindowMask |
20
30
  NSClosableWindowMask |
@@ -131,6 +141,8 @@ static const NSUInteger WINDOW_STYLE_MASK =
131
141
  REF->self->prev_time_update = now;
132
142
 
133
143
  REF->on_update(&e);
144
+ if (!e.is_blocked())
145
+ Reflex::update_view_tree(REF->root(), e);
134
146
 
135
147
  if (REF->self->redraw)
136
148
  {
@@ -164,7 +176,11 @@ static const NSUInteger WINDOW_STYLE_MASK =
164
176
 
165
177
  e.painter->begin();
166
178
  e.painter->clear();
179
+
167
180
  REF->on_draw(&e);
181
+ if (!e.is_blocked())
182
+ draw_view_tree(REF->root(), e, 0, REF->frame().dup().move_to(0));
183
+
168
184
  e.painter->end();
169
185
  }
170
186
 
data/src/osx/window.mm CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
 
5
5
  #import <Cocoa/Cocoa.h>
6
- #include <rays/bounds.h>
7
6
  #include "reflex/event.h"
8
7
  #include "reflex/exception.h"
9
8
  #include "window_data.h"
@@ -112,8 +111,17 @@ namespace Reflex
112
111
  if (!*this)
113
112
  invalid_state_error(__FILE__, __LINE__);
114
113
 
115
- if (--self->hide_count == 0)
114
+ int new_count = self->hide_count - 1;
115
+ if (new_count == 0)
116
+ {
117
+ Event e;
118
+ on_show(&e);
119
+ if (e.is_blocked()) return;
120
+
116
121
  [self->native makeKeyAndOrderFront: nil];
122
+ }
123
+
124
+ self->hide_count = new_count;
117
125
  }
118
126
 
119
127
  void
@@ -122,8 +130,17 @@ namespace Reflex
122
130
  if (!*this)
123
131
  invalid_state_error(__FILE__, __LINE__);
124
132
 
125
- if (++self->hide_count == 1)
133
+ int new_count = self->hide_count + 1;
134
+ if (new_count == 1)
135
+ {
136
+ Event e;
137
+ on_hide(&e);
138
+ if (e.is_blocked()) return;
139
+
126
140
  [self->native orderOut: self->native];
141
+ }
142
+
143
+ self->hide_count = new_count;
127
144
  }
128
145
 
129
146
  void
@@ -132,6 +149,10 @@ namespace Reflex
132
149
  if (!*this)
133
150
  invalid_state_error(__FILE__, __LINE__);
134
151
 
152
+ Event e;
153
+ on_close(&e);
154
+ if (e.is_blocked()) return;
155
+
135
156
  [self->native close];
136
157
  }
137
158
 
@@ -6,8 +6,8 @@
6
6
 
7
7
  #include <map>
8
8
  #include <xot/time.h>
9
- #include <rays/point.h>
10
- #include <rays/painter.h>
9
+ #include <reflex/point.h>
10
+ #include <reflex/painter.h>
11
11
  #include <reflex/window.h>
12
12
  #include <reflex/view.h>
13
13
 
@@ -35,7 +35,7 @@ namespace Reflex
35
35
 
36
36
  View::Ref root, focus;
37
37
 
38
- Rays::Point prev_position, prev_size;
38
+ Point prev_position, prev_size;
39
39
 
40
40
  double prev_time_update, prev_time_draw, prev_fps;
41
41
 
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked as such, and must not be
15
+ * misrepresented as being the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+ #ifndef BOX2D_H
20
+ #define BOX2D_H
21
+
22
+ /**
23
+ \mainpage Box2D API Documentation
24
+
25
+ \section intro_sec Getting Started
26
+
27
+ For documentation please see http://box2d.org/documentation.html
28
+
29
+ For discussion please visit http://box2d.org/forum
30
+ */
31
+
32
+ // These include files constitute the main Box2D API
33
+
34
+ #include <Box2D/Common/b2Settings.h>
35
+ #include <Box2D/Common/b2Draw.h>
36
+ #include <Box2D/Common/b2Timer.h>
37
+
38
+ #include <Box2D/Collision/Shapes/b2CircleShape.h>
39
+ #include <Box2D/Collision/Shapes/b2EdgeShape.h>
40
+ #include <Box2D/Collision/Shapes/b2ChainShape.h>
41
+ #include <Box2D/Collision/Shapes/b2PolygonShape.h>
42
+
43
+ #include <Box2D/Collision/b2BroadPhase.h>
44
+ #include <Box2D/Collision/b2Distance.h>
45
+ #include <Box2D/Collision/b2DynamicTree.h>
46
+ #include <Box2D/Collision/b2TimeOfImpact.h>
47
+
48
+ #include <Box2D/Dynamics/b2Body.h>
49
+ #include <Box2D/Dynamics/b2Fixture.h>
50
+ #include <Box2D/Dynamics/b2WorldCallbacks.h>
51
+ #include <Box2D/Dynamics/b2TimeStep.h>
52
+ #include <Box2D/Dynamics/b2World.h>
53
+
54
+ #include <Box2D/Dynamics/Contacts/b2Contact.h>
55
+
56
+ #include <Box2D/Dynamics/Joints/b2DistanceJoint.h>
57
+ #include <Box2D/Dynamics/Joints/b2FrictionJoint.h>
58
+ #include <Box2D/Dynamics/Joints/b2GearJoint.h>
59
+ #include <Box2D/Dynamics/Joints/b2MotorJoint.h>
60
+ #include <Box2D/Dynamics/Joints/b2MouseJoint.h>
61
+ #include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>
62
+ #include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
63
+ #include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>
64
+ #include <Box2D/Dynamics/Joints/b2RopeJoint.h>
65
+ #include <Box2D/Dynamics/Joints/b2WeldJoint.h>
66
+ #include <Box2D/Dynamics/Joints/b2WheelJoint.h>
67
+
68
+ #endif
@@ -0,0 +1,193 @@
1
+ /*
2
+ * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked as such, and must not be
15
+ * misrepresented as being the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+ #include <Box2D/Collision/Shapes/b2ChainShape.h>
20
+ #include <Box2D/Collision/Shapes/b2EdgeShape.h>
21
+ #include <new>
22
+ #include <string.h>
23
+
24
+ b2ChainShape::~b2ChainShape()
25
+ {
26
+ Clear();
27
+ }
28
+
29
+ void b2ChainShape::Clear()
30
+ {
31
+ b2Free(m_vertices);
32
+ m_vertices = NULL;
33
+ m_count = 0;
34
+ }
35
+
36
+ void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
37
+ {
38
+ b2Assert(m_vertices == NULL && m_count == 0);
39
+ b2Assert(count >= 3);
40
+ for (int32 i = 1; i < count; ++i)
41
+ {
42
+ b2Vec2 v1 = vertices[i-1];
43
+ b2Vec2 v2 = vertices[i];
44
+ // If the code crashes here, it means your vertices are too close together.
45
+ b2Assert(b2DistanceSquared(v1, v2) > b2_linearSlop * b2_linearSlop);
46
+ }
47
+
48
+ m_count = count + 1;
49
+ m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
50
+ memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
51
+ m_vertices[count] = m_vertices[0];
52
+ m_prevVertex = m_vertices[m_count - 2];
53
+ m_nextVertex = m_vertices[1];
54
+ m_hasPrevVertex = true;
55
+ m_hasNextVertex = true;
56
+ }
57
+
58
+ void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
59
+ {
60
+ b2Assert(m_vertices == NULL && m_count == 0);
61
+ b2Assert(count >= 2);
62
+ for (int32 i = 1; i < count; ++i)
63
+ {
64
+ // If the code crashes here, it means your vertices are too close together.
65
+ b2Assert(b2DistanceSquared(vertices[i-1], vertices[i]) > b2_linearSlop * b2_linearSlop);
66
+ }
67
+
68
+ m_count = count;
69
+ m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
70
+ memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
71
+
72
+ m_hasPrevVertex = false;
73
+ m_hasNextVertex = false;
74
+
75
+ m_prevVertex.SetZero();
76
+ m_nextVertex.SetZero();
77
+ }
78
+
79
+ void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
80
+ {
81
+ m_prevVertex = prevVertex;
82
+ m_hasPrevVertex = true;
83
+ }
84
+
85
+ void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
86
+ {
87
+ m_nextVertex = nextVertex;
88
+ m_hasNextVertex = true;
89
+ }
90
+
91
+ b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
92
+ {
93
+ void* mem = allocator->Allocate(sizeof(b2ChainShape));
94
+ b2ChainShape* clone = new (mem) b2ChainShape;
95
+ clone->CreateChain(m_vertices, m_count);
96
+ clone->m_prevVertex = m_prevVertex;
97
+ clone->m_nextVertex = m_nextVertex;
98
+ clone->m_hasPrevVertex = m_hasPrevVertex;
99
+ clone->m_hasNextVertex = m_hasNextVertex;
100
+ return clone;
101
+ }
102
+
103
+ int32 b2ChainShape::GetChildCount() const
104
+ {
105
+ // edge count = vertex count - 1
106
+ return m_count - 1;
107
+ }
108
+
109
+ void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
110
+ {
111
+ b2Assert(0 <= index && index < m_count - 1);
112
+ edge->m_type = b2Shape::e_edge;
113
+ edge->m_radius = m_radius;
114
+
115
+ edge->m_vertex1 = m_vertices[index + 0];
116
+ edge->m_vertex2 = m_vertices[index + 1];
117
+
118
+ if (index > 0)
119
+ {
120
+ edge->m_vertex0 = m_vertices[index - 1];
121
+ edge->m_hasVertex0 = true;
122
+ }
123
+ else
124
+ {
125
+ edge->m_vertex0 = m_prevVertex;
126
+ edge->m_hasVertex0 = m_hasPrevVertex;
127
+ }
128
+
129
+ if (index < m_count - 2)
130
+ {
131
+ edge->m_vertex3 = m_vertices[index + 2];
132
+ edge->m_hasVertex3 = true;
133
+ }
134
+ else
135
+ {
136
+ edge->m_vertex3 = m_nextVertex;
137
+ edge->m_hasVertex3 = m_hasNextVertex;
138
+ }
139
+ }
140
+
141
+ bool b2ChainShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
142
+ {
143
+ B2_NOT_USED(xf);
144
+ B2_NOT_USED(p);
145
+ return false;
146
+ }
147
+
148
+ bool b2ChainShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
149
+ const b2Transform& xf, int32 childIndex) const
150
+ {
151
+ b2Assert(childIndex < m_count);
152
+
153
+ b2EdgeShape edgeShape;
154
+
155
+ int32 i1 = childIndex;
156
+ int32 i2 = childIndex + 1;
157
+ if (i2 == m_count)
158
+ {
159
+ i2 = 0;
160
+ }
161
+
162
+ edgeShape.m_vertex1 = m_vertices[i1];
163
+ edgeShape.m_vertex2 = m_vertices[i2];
164
+
165
+ return edgeShape.RayCast(output, input, xf, 0);
166
+ }
167
+
168
+ void b2ChainShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
169
+ {
170
+ b2Assert(childIndex < m_count);
171
+
172
+ int32 i1 = childIndex;
173
+ int32 i2 = childIndex + 1;
174
+ if (i2 == m_count)
175
+ {
176
+ i2 = 0;
177
+ }
178
+
179
+ b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
180
+ b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
181
+
182
+ aabb->lowerBound = b2Min(v1, v2);
183
+ aabb->upperBound = b2Max(v1, v2);
184
+ }
185
+
186
+ void b2ChainShape::ComputeMass(b2MassData* massData, float32 density) const
187
+ {
188
+ B2_NOT_USED(density);
189
+
190
+ massData->mass = 0.0f;
191
+ massData->center.SetZero();
192
+ massData->I = 0.0f;
193
+ }
@@ -0,0 +1,105 @@
1
+ /*
2
+ * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked as such, and must not be
15
+ * misrepresented as being the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+ #ifndef B2_CHAIN_SHAPE_H
20
+ #define B2_CHAIN_SHAPE_H
21
+
22
+ #include <Box2D/Collision/Shapes/b2Shape.h>
23
+
24
+ class b2EdgeShape;
25
+
26
+ /// A chain shape is a free form sequence of line segments.
27
+ /// The chain has two-sided collision, so you can use inside and outside collision.
28
+ /// Therefore, you may use any winding order.
29
+ /// Since there may be many vertices, they are allocated using b2Alloc.
30
+ /// Connectivity information is used to create smooth collisions.
31
+ /// WARNING: The chain will not collide properly if there are self-intersections.
32
+ class b2ChainShape : public b2Shape
33
+ {
34
+ public:
35
+ b2ChainShape();
36
+
37
+ /// The destructor frees the vertices using b2Free.
38
+ ~b2ChainShape();
39
+
40
+ /// Clear all data.
41
+ void Clear();
42
+
43
+ /// Create a loop. This automatically adjusts connectivity.
44
+ /// @param vertices an array of vertices, these are copied
45
+ /// @param count the vertex count
46
+ void CreateLoop(const b2Vec2* vertices, int32 count);
47
+
48
+ /// Create a chain with isolated end vertices.
49
+ /// @param vertices an array of vertices, these are copied
50
+ /// @param count the vertex count
51
+ void CreateChain(const b2Vec2* vertices, int32 count);
52
+
53
+ /// Establish connectivity to a vertex that precedes the first vertex.
54
+ /// Don't call this for loops.
55
+ void SetPrevVertex(const b2Vec2& prevVertex);
56
+
57
+ /// Establish connectivity to a vertex that follows the last vertex.
58
+ /// Don't call this for loops.
59
+ void SetNextVertex(const b2Vec2& nextVertex);
60
+
61
+ /// Implement b2Shape. Vertices are cloned using b2Alloc.
62
+ b2Shape* Clone(b2BlockAllocator* allocator) const;
63
+
64
+ /// @see b2Shape::GetChildCount
65
+ int32 GetChildCount() const;
66
+
67
+ /// Get a child edge.
68
+ void GetChildEdge(b2EdgeShape* edge, int32 index) const;
69
+
70
+ /// This always return false.
71
+ /// @see b2Shape::TestPoint
72
+ bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
73
+
74
+ /// Implement b2Shape.
75
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
76
+ const b2Transform& transform, int32 childIndex) const;
77
+
78
+ /// @see b2Shape::ComputeAABB
79
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
80
+
81
+ /// Chains have zero mass.
82
+ /// @see b2Shape::ComputeMass
83
+ void ComputeMass(b2MassData* massData, float32 density) const;
84
+
85
+ /// The vertices. Owned by this class.
86
+ b2Vec2* m_vertices;
87
+
88
+ /// The vertex count.
89
+ int32 m_count;
90
+
91
+ b2Vec2 m_prevVertex, m_nextVertex;
92
+ bool m_hasPrevVertex, m_hasNextVertex;
93
+ };
94
+
95
+ inline b2ChainShape::b2ChainShape()
96
+ {
97
+ m_type = e_chain;
98
+ m_radius = b2_polygonRadius;
99
+ m_vertices = NULL;
100
+ m_count = 0;
101
+ m_hasPrevVertex = false;
102
+ m_hasNextVertex = false;
103
+ }
104
+
105
+ #endif
@@ -0,0 +1,99 @@
1
+ /*
2
+ * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked as such, and must not be
15
+ * misrepresented as being the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+ #include <Box2D/Collision/Shapes/b2CircleShape.h>
20
+ #include <new>
21
+
22
+ b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
23
+ {
24
+ void* mem = allocator->Allocate(sizeof(b2CircleShape));
25
+ b2CircleShape* clone = new (mem) b2CircleShape;
26
+ *clone = *this;
27
+ return clone;
28
+ }
29
+
30
+ int32 b2CircleShape::GetChildCount() const
31
+ {
32
+ return 1;
33
+ }
34
+
35
+ bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
36
+ {
37
+ b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
38
+ b2Vec2 d = p - center;
39
+ return b2Dot(d, d) <= m_radius * m_radius;
40
+ }
41
+
42
+ // Collision Detection in Interactive 3D Environments by Gino van den Bergen
43
+ // From Section 3.1.2
44
+ // x = s + a * r
45
+ // norm(x) = radius
46
+ bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
47
+ const b2Transform& transform, int32 childIndex) const
48
+ {
49
+ B2_NOT_USED(childIndex);
50
+
51
+ b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
52
+ b2Vec2 s = input.p1 - position;
53
+ float32 b = b2Dot(s, s) - m_radius * m_radius;
54
+
55
+ // Solve quadratic equation.
56
+ b2Vec2 r = input.p2 - input.p1;
57
+ float32 c = b2Dot(s, r);
58
+ float32 rr = b2Dot(r, r);
59
+ float32 sigma = c * c - rr * b;
60
+
61
+ // Check for negative discriminant and short segment.
62
+ if (sigma < 0.0f || rr < b2_epsilon)
63
+ {
64
+ return false;
65
+ }
66
+
67
+ // Find the point of intersection of the line with the circle.
68
+ float32 a = -(c + b2Sqrt(sigma));
69
+
70
+ // Is the intersection point on the segment?
71
+ if (0.0f <= a && a <= input.maxFraction * rr)
72
+ {
73
+ a /= rr;
74
+ output->fraction = a;
75
+ output->normal = s + a * r;
76
+ output->normal.Normalize();
77
+ return true;
78
+ }
79
+
80
+ return false;
81
+ }
82
+
83
+ void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const
84
+ {
85
+ B2_NOT_USED(childIndex);
86
+
87
+ b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
88
+ aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
89
+ aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
90
+ }
91
+
92
+ void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
93
+ {
94
+ massData->mass = density * b2_pi * m_radius * m_radius;
95
+ massData->center = m_p;
96
+
97
+ // inertia about the local origin
98
+ massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
99
+ }