joybox 0.0.3

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 (204) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +6 -0
  4. data/Gemfile.lock +27 -0
  5. data/LICENSE +22 -0
  6. data/README.md +86 -0
  7. data/Rakefile +14 -0
  8. data/app/app_delegate.rb +49 -0
  9. data/app/layers/box2d_layer.rb +109 -0
  10. data/app/layers/cocos2d_layer.rb +14 -0
  11. data/app/layers/cocos_motion_layer.rb +145 -0
  12. data/app/layers/menu_layer.rb +59 -0
  13. data/joybox.gemspec +25 -0
  14. data/lib/joybox.rb +47 -0
  15. data/lib/joybox/box2d/body.rb +106 -0
  16. data/lib/joybox/box2d/world.rb +79 -0
  17. data/lib/joybox/cocos2d/actions/actions.rb +7 -0
  18. data/lib/joybox/cocos2d/actions/move.rb +31 -0
  19. data/lib/joybox/cocos2d/actions/repeat.rb +24 -0
  20. data/lib/joybox/cocos2d/actions/rotate.rb +31 -0
  21. data/lib/joybox/cocos2d/actions/scale.rb +31 -0
  22. data/lib/joybox/cocos2d/actions/sequence.rb +22 -0
  23. data/lib/joybox/cocos2d/actions/skew.rb +36 -0
  24. data/lib/joybox/cocos2d/cocos2d.rb +15 -0
  25. data/lib/joybox/cocos2d/common/cg_point.rb +37 -0
  26. data/lib/joybox/cocos2d/common/color.rb +49 -0
  27. data/lib/joybox/cocos2d/common/gc_size.rb +39 -0
  28. data/lib/joybox/cocos2d/common/ns_set.rb +5 -0
  29. data/lib/joybox/cocos2d/common/numeric.rb +14 -0
  30. data/lib/joybox/cocos2d/common/screen.rb +39 -0
  31. data/lib/joybox/cocos2d/common/ui_touch.rb +15 -0
  32. data/lib/joybox/cocos2d/configuration/configuration.rb +68 -0
  33. data/lib/joybox/cocos2d/configuration/file_utils.rb +33 -0
  34. data/lib/joybox/cocos2d/configuration/gl_view.rb +44 -0
  35. data/lib/joybox/cocos2d/configuration/texture_2d.rb +27 -0
  36. data/lib/joybox/cocos2d/core/layer.rb +87 -0
  37. data/lib/joybox/cocos2d/core/node.rb +26 -0
  38. data/lib/joybox/cocos2d/core/physics_sprite.rb +52 -0
  39. data/lib/joybox/cocos2d/core/scene.rb +24 -0
  40. data/lib/joybox/cocos2d/core/sprite.rb +43 -0
  41. data/lib/joybox/cocos2d/core/sprite_batch.rb +24 -0
  42. data/lib/joybox/cocos2d/director.rb +43 -0
  43. data/lib/joybox/cocos2d/macros.rb +234 -0
  44. data/lib/joybox/cocos2d/ui/label.rb +34 -0
  45. data/lib/joybox/cocos2d/ui/menu.rb +25 -0
  46. data/lib/joybox/cocos2d/ui/menu_image.rb +22 -0
  47. data/lib/joybox/cocos2d/ui/menu_label.rb +45 -0
  48. data/lib/joybox/cocos2d/ui/ui.rb +7 -0
  49. data/lib/joybox/version.rb +3 -0
  50. data/resources/box2d/blocks_sprite_sheet.png +0 -0
  51. data/resources/cocos_motion/dot.png +0 -0
  52. data/resources/cocos_motion/dot_selected.png +0 -0
  53. data/resources/cocos_motion/grossini.png +0 -0
  54. data/resources/cocos_motion/grossinis_sister.png +0 -0
  55. data/resources/cocos_motion/grossinis_sister_two.png +0 -0
  56. data/resources/cocos_motion/left_arrow.png +0 -0
  57. data/resources/cocos_motion/left_arrow_selected.png +0 -0
  58. data/resources/cocos_motion/right_arrow.png +0 -0
  59. data/resources/cocos_motion/right_arrow_selected.png +0 -0
  60. data/resources/fps_images-hd.png +0 -0
  61. data/resources/fps_images-ipadhd.png +0 -0
  62. data/resources/fps_images.png +0 -0
  63. data/spec/lib/joybox/cocos2d/cocos2d_spec.rb +7 -0
  64. data/spec/lib/joybox/cocos2d/macros_spec.rb +37 -0
  65. data/spec/main_spec.rb +9 -0
  66. data/vendor/Box2D.framework/Box2D +0 -0
  67. data/vendor/Box2D.framework/Box2D.framework.bridgesupport +166 -0
  68. data/vendor/Box2D.framework/Versions/A/Box2D +0 -0
  69. data/vendor/Box2D.framework/Versions/A/Headers/Collision/B2DContactListener.h +25 -0
  70. data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DEdgeShape.h +17 -0
  71. data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DPolygonShape.h +16 -0
  72. data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DShape.h +15 -0
  73. data/vendor/Box2D.framework/Versions/A/Headers/Dynamics/B2DBody.h +43 -0
  74. data/vendor/Box2D.framework/Versions/A/Headers/Dynamics/B2DWorld.h +41 -0
  75. data/vendor/Box2D.framework/Versions/A/Resources/Box2DConfig.cmake +3 -0
  76. data/vendor/Box2D.framework/Versions/A/Resources/CMakeLists.txt +205 -0
  77. data/vendor/Cocos2D/Cocos2D.bridgesupport +7808 -0
  78. data/vendor/Cocos2D/include/CCAction.h +195 -0
  79. data/vendor/Cocos2D/include/CCActionCamera.h +73 -0
  80. data/vendor/Cocos2D/include/CCActionCatmullRom.h +139 -0
  81. data/vendor/Cocos2D/include/CCActionEase.h +159 -0
  82. data/vendor/Cocos2D/include/CCActionGrid.h +165 -0
  83. data/vendor/Cocos2D/include/CCActionGrid3D.h +205 -0
  84. data/vendor/Cocos2D/include/CCActionInstant.h +227 -0
  85. data/vendor/Cocos2D/include/CCActionInterval.h +431 -0
  86. data/vendor/Cocos2D/include/CCActionManager.h +113 -0
  87. data/vendor/Cocos2D/include/CCActionPageTurn3D.h +42 -0
  88. data/vendor/Cocos2D/include/CCActionProgressTimer.h +59 -0
  89. data/vendor/Cocos2D/include/CCActionTiledGrid.h +211 -0
  90. data/vendor/Cocos2D/include/CCActionTween.h +62 -0
  91. data/vendor/Cocos2D/include/CCAnimation.h +150 -0
  92. data/vendor/Cocos2D/include/CCAnimationCache.h +74 -0
  93. data/vendor/Cocos2D/include/CCArray.h +119 -0
  94. data/vendor/Cocos2D/include/CCAtlasNode.h +96 -0
  95. data/vendor/Cocos2D/include/CCCamera.h +98 -0
  96. data/vendor/Cocos2D/include/CCConfiguration.h +126 -0
  97. data/vendor/Cocos2D/include/CCDirector.h +344 -0
  98. data/vendor/Cocos2D/include/CCDirectorIOS.h +104 -0
  99. data/vendor/Cocos2D/include/CCDrawingPrimitives.h +139 -0
  100. data/vendor/Cocos2D/include/CCES2Renderer.h +83 -0
  101. data/vendor/Cocos2D/include/CCESRenderer.h +54 -0
  102. data/vendor/Cocos2D/include/CCFileUtils.h +188 -0
  103. data/vendor/Cocos2D/include/CCGL.h +72 -0
  104. data/vendor/Cocos2D/include/CCGLProgram.h +150 -0
  105. data/vendor/Cocos2D/include/CCGLView.h +160 -0
  106. data/vendor/Cocos2D/include/CCGrabber.h +44 -0
  107. data/vendor/Cocos2D/include/CCGrid.h +130 -0
  108. data/vendor/Cocos2D/include/CCLabelAtlas.h +68 -0
  109. data/vendor/Cocos2D/include/CCLabelBMFont.h +216 -0
  110. data/vendor/Cocos2D/include/CCLabelTTF.h +132 -0
  111. data/vendor/Cocos2D/include/CCLayer.h +280 -0
  112. data/vendor/Cocos2D/include/CCMenu.h +100 -0
  113. data/vendor/Cocos2D/include/CCMenuItem.h +423 -0
  114. data/vendor/Cocos2D/include/CCMotionStreak.h +87 -0
  115. data/vendor/Cocos2D/include/CCNS.h +54 -0
  116. data/vendor/Cocos2D/include/CCNode+Debug.h +39 -0
  117. data/vendor/Cocos2D/include/CCNode.h +569 -0
  118. data/vendor/Cocos2D/include/CCParallaxNode.h +50 -0
  119. data/vendor/Cocos2D/include/CCParticleBatchNode.h +99 -0
  120. data/vendor/Cocos2D/include/CCParticleExamples.h +95 -0
  121. data/vendor/Cocos2D/include/CCParticleSystem.h +453 -0
  122. data/vendor/Cocos2D/include/CCParticleSystemQuad.h +73 -0
  123. data/vendor/Cocos2D/include/CCProfiling.h +89 -0
  124. data/vendor/Cocos2D/include/CCProgressTimer.h +94 -0
  125. data/vendor/Cocos2D/include/CCProtocols.h +132 -0
  126. data/vendor/Cocos2D/include/CCRenderTexture.h +139 -0
  127. data/vendor/Cocos2D/include/CCScene.h +43 -0
  128. data/vendor/Cocos2D/include/CCScheduler.h +230 -0
  129. data/vendor/Cocos2D/include/CCShaderCache.h +60 -0
  130. data/vendor/Cocos2D/include/CCSprite.h +288 -0
  131. data/vendor/Cocos2D/include/CCSpriteBatchNode.h +138 -0
  132. data/vendor/Cocos2D/include/CCSpriteFrame.h +126 -0
  133. data/vendor/Cocos2D/include/CCSpriteFrameCache.h +121 -0
  134. data/vendor/Cocos2D/include/CCTMXLayer.h +164 -0
  135. data/vendor/Cocos2D/include/CCTMXObjectGroup.h +67 -0
  136. data/vendor/Cocos2D/include/CCTMXTiledMap.h +145 -0
  137. data/vendor/Cocos2D/include/CCTMXXMLParser.h +217 -0
  138. data/vendor/Cocos2D/include/CCTexture2D.h +357 -0
  139. data/vendor/Cocos2D/include/CCTextureAtlas.h +188 -0
  140. data/vendor/Cocos2D/include/CCTextureCache.h +146 -0
  141. data/vendor/Cocos2D/include/CCTexturePVR.h +129 -0
  142. data/vendor/Cocos2D/include/CCTileMapAtlas.h +83 -0
  143. data/vendor/Cocos2D/include/CCTouchDelegateProtocol.h +75 -0
  144. data/vendor/Cocos2D/include/CCTouchDispatcher.h +120 -0
  145. data/vendor/Cocos2D/include/CCTouchHandler.h +93 -0
  146. data/vendor/Cocos2D/include/CCTransition.h +296 -0
  147. data/vendor/Cocos2D/include/CCTransitionPageTurn.h +60 -0
  148. data/vendor/Cocos2D/include/CCTransitionProgress.h +62 -0
  149. data/vendor/Cocos2D/include/CCVertex.h +36 -0
  150. data/vendor/Cocos2D/include/CGPointExtension.h +344 -0
  151. data/vendor/Cocos2D/include/CocosDenshion/CDAudioManager.h +243 -0
  152. data/vendor/Cocos2D/include/CocosDenshion/CDConfig.h +60 -0
  153. data/vendor/Cocos2D/include/CocosDenshion/CDOpenALSupport.h +77 -0
  154. data/vendor/Cocos2D/include/CocosDenshion/CDXPropertyModifierAction.h +45 -0
  155. data/vendor/Cocos2D/include/CocosDenshion/CocosDenshion.h +440 -0
  156. data/vendor/Cocos2D/include/CocosDenshion/SimpleAudioEngine.h +90 -0
  157. data/vendor/Cocos2D/include/NSThread+performBlock.h +22 -0
  158. data/vendor/Cocos2D/include/OpenGL_Internal.h +86 -0
  159. data/vendor/Cocos2D/include/RubyMotionSchedule.h +7 -0
  160. data/vendor/Cocos2D/include/TGAlib.h +55 -0
  161. data/vendor/Cocos2D/include/TransformUtils.h +36 -0
  162. data/vendor/Cocos2D/include/ZipUtils.h +91 -0
  163. data/vendor/Cocos2D/include/base64.h +33 -0
  164. data/vendor/Cocos2D/include/ccCArray.h +229 -0
  165. data/vendor/Cocos2D/include/ccConfig.h +245 -0
  166. data/vendor/Cocos2D/include/ccDeprecated.h +300 -0
  167. data/vendor/Cocos2D/include/ccGLStateCache.h +138 -0
  168. data/vendor/Cocos2D/include/ccMacros.h +353 -0
  169. data/vendor/Cocos2D/include/ccShader_PositionColor_frag.h +12 -0
  170. data/vendor/Cocos2D/include/ccShader_PositionColor_vert.h +17 -0
  171. data/vendor/Cocos2D/include/ccShader_PositionTextureA8Color_frag.h +16 -0
  172. data/vendor/Cocos2D/include/ccShader_PositionTextureA8Color_vert.h +21 -0
  173. data/vendor/Cocos2D/include/ccShader_PositionTextureColorAlphaTest_frag.h +23 -0
  174. data/vendor/Cocos2D/include/ccShader_PositionTextureColor_frag.h +14 -0
  175. data/vendor/Cocos2D/include/ccShader_PositionTextureColor_vert.h +22 -0
  176. data/vendor/Cocos2D/include/ccShader_PositionTexture_frag.h +13 -0
  177. data/vendor/Cocos2D/include/ccShader_PositionTexture_uColor_frag.h +16 -0
  178. data/vendor/Cocos2D/include/ccShader_PositionTexture_uColor_vert.h +18 -0
  179. data/vendor/Cocos2D/include/ccShader_PositionTexture_vert.h +17 -0
  180. data/vendor/Cocos2D/include/ccShader_Position_uColor_frag.h +12 -0
  181. data/vendor/Cocos2D/include/ccShader_Position_uColor_vert.h +19 -0
  182. data/vendor/Cocos2D/include/ccShaders.h +45 -0
  183. data/vendor/Cocos2D/include/ccTypes.h +374 -0
  184. data/vendor/Cocos2D/include/ccUtils.h +36 -0
  185. data/vendor/Cocos2D/include/cocos2d.h +178 -0
  186. data/vendor/Cocos2D/include/kazmath/GL/mat4stack.h +51 -0
  187. data/vendor/Cocos2D/include/kazmath/GL/matrix.h +58 -0
  188. data/vendor/Cocos2D/include/kazmath/aabb.h +53 -0
  189. data/vendor/Cocos2D/include/kazmath/kazmath.h +39 -0
  190. data/vendor/Cocos2D/include/kazmath/mat3.h +75 -0
  191. data/vendor/Cocos2D/include/kazmath/mat4.h +93 -0
  192. data/vendor/Cocos2D/include/kazmath/neon_matrix_impl.h +41 -0
  193. data/vendor/Cocos2D/include/kazmath/plane.h +70 -0
  194. data/vendor/Cocos2D/include/kazmath/quaternion.h +113 -0
  195. data/vendor/Cocos2D/include/kazmath/ray2.h +50 -0
  196. data/vendor/Cocos2D/include/kazmath/utility.h +74 -0
  197. data/vendor/Cocos2D/include/kazmath/vec2.h +64 -0
  198. data/vendor/Cocos2D/include/kazmath/vec3.h +68 -0
  199. data/vendor/Cocos2D/include/kazmath/vec4.h +68 -0
  200. data/vendor/Cocos2D/include/uthash.h +972 -0
  201. data/vendor/Cocos2D/include/utlist.h +490 -0
  202. data/vendor/Cocos2D/libCocosDenshion.a +0 -0
  203. data/vendor/Cocos2D/libcocos2d.a +0 -0
  204. metadata +277 -0
@@ -0,0 +1,60 @@
1
+ /*
2
+ * cocos2d for iPhone: http://www.cocos2d-iphone.org
3
+ *
4
+ * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ *
24
+ */
25
+
26
+
27
+ #import "CCTransition.h"
28
+
29
+ /** CCTransitionPageTurn transition.
30
+ * A transition which peels back the bottom right hand corner of a scene
31
+ * to transition to the scene beneath it simulating a page turn
32
+ *
33
+ * This uses a 3DAction so it is strongly recommended that depth buffering
34
+ * is turned on in CCDirector using:
35
+ *
36
+ * [[CCDirector sharedDirector] setDepthBufferFormat:kCCDepthBuffer16];
37
+ *
38
+ * @since v0.8.2
39
+ */
40
+ @interface CCTransitionPageTurn : CCTransitionScene
41
+ {
42
+ BOOL back_;
43
+ }
44
+ /**
45
+ * creates a base transition with duration and incoming scene
46
+ * if back is TRUE then the effect is reversed to appear as if the incoming
47
+ * scene is being turned from left over the outgoing scene
48
+ */
49
+ +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back;
50
+
51
+ /**
52
+ * creates a base transition with duration and incoming scene
53
+ * if back is TRUE then the effect is reversed to appear as if the incoming
54
+ * scene is being turned from left over the outgoing scene
55
+ */
56
+ -(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back;
57
+
58
+ -(CCActionInterval*) actionWithSize:(ccGridSize) vector;
59
+
60
+ @end
@@ -0,0 +1,62 @@
1
+ /*
2
+ * cocos2d for iPhone: http://www.cocos2d-iphone.org
3
+ *
4
+ * Copyright (c) 2009 Lam Pham
5
+ *
6
+ * Copyright (c) 2012 Ricardo Quesada
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ *
26
+ */
27
+
28
+ #import "CCTransition.h"
29
+
30
+ @interface CCTransitionProgress : CCTransitionScene
31
+ {
32
+ float to_, from_;
33
+ CCScene *sceneToBeModified_;
34
+ }
35
+ @end
36
+
37
+ /** CCTransitionRadialCCW transition.
38
+ A counter colock-wise radial transition to the next scene
39
+ */
40
+ @interface CCTransitionProgressRadialCCW : CCTransitionProgress
41
+ @end
42
+
43
+ /** CCTransitionRadialCW transition.
44
+ A counter colock-wise radial transition to the next scene
45
+ */
46
+ @interface CCTransitionProgressRadialCW : CCTransitionProgress
47
+ @end
48
+
49
+ /** CCTransitionProgressHorizontal transition.
50
+ A colock-wise radial transition to the next scene
51
+ */
52
+ @interface CCTransitionProgressHorizontal : CCTransitionProgress
53
+ @end
54
+
55
+ @interface CCTransitionProgressVertical : CCTransitionProgress
56
+ @end
57
+
58
+ @interface CCTransitionProgressInOut : CCTransitionProgress
59
+ @end
60
+
61
+ @interface CCTransitionProgressOutIn : CCTransitionProgress
62
+ @end
@@ -0,0 +1,36 @@
1
+ /*
2
+ * cocos2d for iPhone: http://www.cocos2d-iphone.org
3
+ *
4
+ * Copyright (c) 2011 ForzeField Studios S.L. http://forzefield.com
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #import "ccTypes.h"
26
+
27
+ /** @file CCVertex.h */
28
+
29
+ /** converts a line to a polygon */
30
+ void ccVertexLineToPolygon(CGPoint *points, float stroke, ccVertex2F *vertices, NSUInteger offset, NSUInteger nuPoints);
31
+
32
+ /** returns wheter or not the line intersects */
33
+ BOOL ccVertexLineIntersect(float Ax, float Ay,
34
+ float Bx, float By,
35
+ float Cx, float Cy,
36
+ float Dx, float Dy, float *T);
@@ -0,0 +1,344 @@
1
+ /* cocos2d for iPhone
2
+ * http://www.cocos2d-iphone.org
3
+ *
4
+ * Copyright (c) 2007 Scott Lembcke
5
+ *
6
+ * Copyright (c) 2010 Lam Pham
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+
27
+ /*
28
+ * Some of the functions were based on Chipmunk's cpVect.h.
29
+ */
30
+
31
+ /**
32
+ @file
33
+ CGPoint extensions based on Chipmunk's cpVect file.
34
+ These extensions work both with CGPoint and cpVect.
35
+
36
+ The "ccp" prefix means: "CoCos2d Point"
37
+
38
+ Examples:
39
+ - ccpAdd( ccp(1,1), ccp(2,2) ); // preferred cocos2d way
40
+ - ccpAdd( CGPointMake(1,1), CGPointMake(2,2) ); // also ok but more verbose
41
+
42
+ - cpvadd( cpv(1,1), cpv(2,2) ); // way of the chipmunk
43
+ - ccpAdd( cpv(1,1), cpv(2,2) ); // mixing chipmunk and cocos2d (avoid)
44
+ - cpvadd( CGPointMake(1,1), CGPointMake(2,2) ); // mixing chipmunk and CG (avoid)
45
+ */
46
+
47
+ #import "ccMacros.h"
48
+
49
+ #ifdef __CC_PLATFORM_IOS
50
+ #import <CoreGraphics/CGGeometry.h>
51
+ #elif defined(__CC_PLATFORM_MAC)
52
+ #import <Foundation/Foundation.h>
53
+ #endif
54
+
55
+ #import <math.h>
56
+ #import <objc/objc.h>
57
+
58
+ #ifdef __cplusplus
59
+ extern "C" {
60
+ #endif
61
+
62
+ /** Helper macro that creates a CGPoint
63
+ @return CGPoint
64
+ @since v0.7.2
65
+ */
66
+ #define ccp(__X__,__Y__) CGPointMake(__X__,__Y__)
67
+
68
+
69
+ /** Returns opposite of point.
70
+ @return CGPoint
71
+ @since v0.7.2
72
+ */
73
+ static inline CGPoint
74
+ ccpNeg(const CGPoint v)
75
+ {
76
+ return ccp(-v.x, -v.y);
77
+ }
78
+
79
+ /** Calculates sum of two points.
80
+ @return CGPoint
81
+ @since v0.7.2
82
+ */
83
+ static inline CGPoint
84
+ ccpAdd(const CGPoint v1, const CGPoint v2)
85
+ {
86
+ return ccp(v1.x + v2.x, v1.y + v2.y);
87
+ }
88
+
89
+ /** Calculates difference of two points.
90
+ @return CGPoint
91
+ @since v0.7.2
92
+ */
93
+ static inline CGPoint
94
+ ccpSub(const CGPoint v1, const CGPoint v2)
95
+ {
96
+ return ccp(v1.x - v2.x, v1.y - v2.y);
97
+ }
98
+
99
+ /** Returns point multiplied by given factor.
100
+ @return CGPoint
101
+ @since v0.7.2
102
+ */
103
+ static inline CGPoint
104
+ ccpMult(const CGPoint v, const CGFloat s)
105
+ {
106
+ return ccp(v.x*s, v.y*s);
107
+ }
108
+
109
+ /** Calculates midpoint between two points.
110
+ @return CGPoint
111
+ @since v0.7.2
112
+ */
113
+ static inline CGPoint
114
+ ccpMidpoint(const CGPoint v1, const CGPoint v2)
115
+ {
116
+ return ccpMult(ccpAdd(v1, v2), 0.5f);
117
+ }
118
+
119
+ /** Calculates dot product of two points.
120
+ @return CGFloat
121
+ @since v0.7.2
122
+ */
123
+ static inline CGFloat
124
+ ccpDot(const CGPoint v1, const CGPoint v2)
125
+ {
126
+ return v1.x*v2.x + v1.y*v2.y;
127
+ }
128
+
129
+ /** Calculates cross product of two points.
130
+ @return CGFloat
131
+ @since v0.7.2
132
+ */
133
+ static inline CGFloat
134
+ ccpCross(const CGPoint v1, const CGPoint v2)
135
+ {
136
+ return v1.x*v2.y - v1.y*v2.x;
137
+ }
138
+
139
+ /** Calculates perpendicular of v, rotated 90 degrees counter-clockwise -- cross(v, perp(v)) >= 0
140
+ @return CGPoint
141
+ @since v0.7.2
142
+ */
143
+ static inline CGPoint
144
+ ccpPerp(const CGPoint v)
145
+ {
146
+ return ccp(-v.y, v.x);
147
+ }
148
+
149
+ /** Calculates perpendicular of v, rotated 90 degrees clockwise -- cross(v, rperp(v)) <= 0
150
+ @return CGPoint
151
+ @since v0.7.2
152
+ */
153
+ static inline CGPoint
154
+ ccpRPerp(const CGPoint v)
155
+ {
156
+ return ccp(v.y, -v.x);
157
+ }
158
+
159
+ /** Calculates the projection of v1 over v2.
160
+ @return CGPoint
161
+ @since v0.7.2
162
+ */
163
+ static inline CGPoint
164
+ ccpProject(const CGPoint v1, const CGPoint v2)
165
+ {
166
+ return ccpMult(v2, ccpDot(v1, v2)/ccpDot(v2, v2));
167
+ }
168
+
169
+ /** Rotates two points.
170
+ @return CGPoint
171
+ @since v0.7.2
172
+ */
173
+ static inline CGPoint
174
+ ccpRotate(const CGPoint v1, const CGPoint v2)
175
+ {
176
+ return ccp(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x);
177
+ }
178
+
179
+ /** Unrotates two points.
180
+ @return CGPoint
181
+ @since v0.7.2
182
+ */
183
+ static inline CGPoint
184
+ ccpUnrotate(const CGPoint v1, const CGPoint v2)
185
+ {
186
+ return ccp(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y);
187
+ }
188
+
189
+ /** Calculates the square length of a CGPoint (not calling sqrt() )
190
+ @return CGFloat
191
+ @since v0.7.2
192
+ */
193
+ static inline CGFloat
194
+ ccpLengthSQ(const CGPoint v)
195
+ {
196
+ return ccpDot(v, v);
197
+ }
198
+
199
+ /** Calculates the square distance between two points (not calling sqrt() )
200
+ @return CGFloat
201
+ @since v1.1
202
+ */
203
+ static inline CGFloat
204
+ ccpDistanceSQ(const CGPoint p1, const CGPoint p2)
205
+ {
206
+ return ccpLengthSQ(ccpSub(p1, p2));
207
+ }
208
+
209
+ /** Calculates distance between point an origin
210
+ @return CGFloat
211
+ @since v0.7.2
212
+ */
213
+ CGFloat ccpLength(const CGPoint v);
214
+
215
+ /** Calculates the distance between two points
216
+ @return CGFloat
217
+ @since v0.7.2
218
+ */
219
+ CGFloat ccpDistance(const CGPoint v1, const CGPoint v2);
220
+
221
+ /** Returns point multiplied to a length of 1.
222
+ @return CGPoint
223
+ @since v0.7.2
224
+ */
225
+ CGPoint ccpNormalize(const CGPoint v);
226
+
227
+ /** Converts radians to a normalized vector.
228
+ @return CGPoint
229
+ @since v0.7.2
230
+ */
231
+ CGPoint ccpForAngle(const CGFloat a);
232
+
233
+ /** Converts a vector to radians.
234
+ @return CGFloat
235
+ @since v0.7.2
236
+ */
237
+ CGFloat ccpToAngle(const CGPoint v);
238
+
239
+
240
+ /** Clamp a value between from and to.
241
+ @since v0.99.1
242
+ */
243
+ float clampf(float value, float min_inclusive, float max_inclusive);
244
+
245
+ /** Clamp a point between from and to.
246
+ @since v0.99.1
247
+ */
248
+ CGPoint ccpClamp(CGPoint p, CGPoint from, CGPoint to);
249
+
250
+ /** Quickly convert CGSize to a CGPoint
251
+ @since v0.99.1
252
+ */
253
+ CGPoint ccpFromSize(CGSize s);
254
+
255
+ /** Run a math operation function on each point component
256
+ * absf, fllorf, ceilf, roundf
257
+ * any function that has the signature: float func(float);
258
+ * For example: let's try to take the floor of x,y
259
+ * ccpCompOp(p,floorf);
260
+ @since v0.99.1
261
+ */
262
+ CGPoint ccpCompOp(CGPoint p, float (*opFunc)(float));
263
+
264
+ /** Linear Interpolation between two points a and b
265
+ @returns
266
+ alpha == 0 ? a
267
+ alpha == 1 ? b
268
+ otherwise a value between a..b
269
+ @since v0.99.1
270
+ */
271
+ CGPoint ccpLerp(CGPoint a, CGPoint b, float alpha);
272
+
273
+
274
+ /** @returns if points have fuzzy equality which means equal with some degree of variance.
275
+ @since v0.99.1
276
+ */
277
+ BOOL ccpFuzzyEqual(CGPoint a, CGPoint b, float variance);
278
+
279
+
280
+ /** Multiplies a nd b components, a.x*b.x, a.y*b.y
281
+ @returns a component-wise multiplication
282
+ @since v0.99.1
283
+ */
284
+ CGPoint ccpCompMult(CGPoint a, CGPoint b);
285
+
286
+ /** @returns the signed angle in radians between two vector directions
287
+ @since v0.99.1
288
+ */
289
+ float ccpAngleSigned(CGPoint a, CGPoint b);
290
+
291
+ /** @returns the angle in radians between two vector directions
292
+ @since v0.99.1
293
+ */
294
+ float ccpAngle(CGPoint a, CGPoint b);
295
+
296
+ /** Rotates a point counter clockwise by the angle around a pivot
297
+ @param v is the point to rotate
298
+ @param pivot is the pivot, naturally
299
+ @param angle is the angle of rotation cw in radians
300
+ @returns the rotated point
301
+ @since v0.99.1
302
+ */
303
+ CGPoint ccpRotateByAngle(CGPoint v, CGPoint pivot, float angle);
304
+
305
+ /** A general line-line intersection test
306
+ @param p1
307
+ is the startpoint for the first line P1 = (p1 - p2)
308
+ @param p2
309
+ is the endpoint for the first line P1 = (p1 - p2)
310
+ @param p3
311
+ is the startpoint for the second line P2 = (p3 - p4)
312
+ @param p4
313
+ is the endpoint for the second line P2 = (p3 - p4)
314
+ @param s
315
+ is the range for a hitpoint in P1 (pa = p1 + s*(p2 - p1))
316
+ @param t
317
+ is the range for a hitpoint in P3 (pa = p2 + t*(p4 - p3))
318
+ @return bool
319
+ indicating successful intersection of a line
320
+ note that to truly test intersection for segments we have to make
321
+ sure that s & t lie within [0..1] and for rays, make sure s & t > 0
322
+ the hit point is p3 + t * (p4 - p3);
323
+ the hit point also is p1 + s * (p2 - p1);
324
+ @since v0.99.1
325
+ */
326
+ BOOL ccpLineIntersect(CGPoint p1, CGPoint p2,
327
+ CGPoint p3, CGPoint p4,
328
+ float *s, float *t);
329
+
330
+ /*
331
+ ccpSegmentIntersect returns YES if Segment A-B intersects with segment C-D
332
+ @since v1.0.0
333
+ */
334
+ BOOL ccpSegmentIntersect(CGPoint A, CGPoint B, CGPoint C, CGPoint D);
335
+
336
+ /*
337
+ ccpIntersectPoint returns the intersection point of line A-B, C-D
338
+ @since v1.0.0
339
+ */
340
+ CGPoint ccpIntersectPoint(CGPoint A, CGPoint B, CGPoint C, CGPoint D);
341
+
342
+ #ifdef __cplusplus
343
+ }
344
+ #endif