2014-03-14 06:36:05 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< title > Phaser Source: physics/ninja/Circle.js< / title >
<!-- [if lt IE 9]>
< script src = "//html5shiv.googlecode.com/svn/trunk/html5.js" > < / script >
<![endif]-->
< link type = "text/css" rel = "stylesheet" href = "styles/sunlight.default.css" >
< link type = "text/css" rel = "stylesheet" href = "styles/site.cerulean.css" >
< / head >
< body >
< div class = "container-fluid" >
< div class = "navbar navbar-fixed-top navbar-inverse" >
< div class = "navbar-inner" >
< a class = "brand" href = "index.html" > Phaser< / a >
< ul class = "nav" >
< li class = "dropdown" >
< a href = "namespaces.list.html" class = "dropdown-toggle" data-toggle = "dropdown" > Namespaces< b
class="caret">< / b > < / a >
< ul class = "dropdown-menu " >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-0" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.html" > Phaser< / a >
< / li >
< / ul >
< / li >
< li class = "dropdown" >
< a href = "classes.list.html" class = "dropdown-toggle" data-toggle = "dropdown" > Classes< b
class="caret">< / b > < / a >
< ul class = "dropdown-menu " >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Animation.html" > Animation< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.AnimationManager.html" > AnimationManager< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.AnimationParser.html" > AnimationParser< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.BitmapData.html" > BitmapData< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.BitmapText.html" > BitmapText< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Button.html" > Button< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Cache.html" > Cache< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Camera.html" > Camera< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Canvas.html" > Canvas< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Circle.html" > Circle< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Color.html" > Color< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Device.html" > Device< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.html" > Easing< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Back.html" > Back< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Bounce.html" > Bounce< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Circular.html" > Circular< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Cubic.html" > Cubic< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Elastic.html" > Elastic< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Exponential.html" > Exponential< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Linear.html" > Linear< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Quadratic.html" > Quadratic< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Quartic.html" > Quartic< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Quintic.html" > Quintic< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Easing.Sinusoidal.html" > Sinusoidal< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Ellipse.html" > Ellipse< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Events.html" > Events< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Filter.html" > Filter< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Frame.html" > Frame< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.FrameData.html" > FrameData< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Game.html" > Game< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.GameObjectCreator.html" > GameObjectCreator< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.GameObjectFactory.html" > GameObjectFactory< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Gamepad.html" > Gamepad< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.GamepadButton.html" > GamepadButton< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Graphics.html" > Graphics< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Group.html" > Group< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Image.html" > Image< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Input.html" > Input< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.InputHandler.html" > InputHandler< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Key.html" > Key< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Keyboard.html" > Keyboard< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Line.html" > Line< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.LinkedList.html" > LinkedList< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Loader.html" > Loader< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.LoaderParser.html" > LoaderParser< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Math.html" > Math< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Mouse.html" > Mouse< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.MSPointer.html" > MSPointer< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Net.html" > Net< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
< a href = "Phaser.Particle.html" > Particle< / a >
< / li >
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Particles.html" > Particles< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Particles.Arcade.Emitter.html" > Emitter< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.html" > Physics< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Arcade.html" > Arcade< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Arcade.Body.html" > Body< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Ninja.html" > Ninja< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Ninja.AABB.html" > AABB< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Ninja.Body.html" > Body< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Ninja.Circle.html" > Circle< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.Ninja.Tile.html" > Tile< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.html" > P2< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.Body.html" > Body< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.BodyDebug.html" > BodyDebug< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.CollisionGroup.html" > CollisionGroup< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.ContactMaterial.html" > ContactMaterial< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.DistanceConstraint.html" > DistanceConstraint< / a >
< / li >
2014-04-11 12:09:28 +00:00
< li class = "class-depth-3" >
< a href = "Phaser.Physics.P2.FixtureList.html" > FixtureList< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.GearConstraint.html" > GearConstraint< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.InversePointProxy.html" > InversePointProxy< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.LockConstraint.html" > LockConstraint< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.Material.html" > Material< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.PointProxy.html" > PointProxy< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.PrismaticConstraint.html" > PrismaticConstraint< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.RevoluteConstraint.html" > RevoluteConstraint< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-3" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Physics.P2.Spring.html" > Spring< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Plugin.html" > Plugin< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.PluginManager.html" > PluginManager< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Point.html" > Point< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Pointer.html" > Pointer< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Polygon.html" > Polygon< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.QuadTree.html" > QuadTree< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.RandomDataGenerator.html" > RandomDataGenerator< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Rectangle.html" > Rectangle< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.RenderTexture.html" > RenderTexture< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.RequestAnimationFrame.html" > RequestAnimationFrame< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.RetroFont.html" > RetroFont< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.ScaleManager.html" > ScaleManager< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Signal.html" > Signal< / a >
< / li >
2014-04-11 12:09:28 +00:00
< li class = "class-depth-1" >
< a href = "Phaser.SignalBinding.html" > SignalBinding< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.SinglePad.html" > SinglePad< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Sound.html" > Sound< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.SoundManager.html" > SoundManager< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Sprite.html" > Sprite< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.SpriteBatch.html" > SpriteBatch< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Stage.html" > Stage< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.State.html" > State< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.StateManager.html" > StateManager< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Text.html" > Text< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Tile.html" > Tile< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Tilemap.html" > Tilemap< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.TilemapLayer.html" > TilemapLayer< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.TilemapParser.html" > TilemapParser< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Tileset.html" > Tileset< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.TileSprite.html" > TileSprite< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Time.html" > Time< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Timer.html" > Timer< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.TimerEvent.html" > TimerEvent< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Touch.html" > Touch< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Tween.html" > Tween< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.TweenManager.html" > TweenManager< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Utils.html" > Utils< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-2" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.Utils.Debug.html" > Debug< / a >
< / li >
2014-04-10 22:13:43 +00:00
< li class = "class-depth-1" >
2014-03-14 06:36:05 +00:00
< a href = "Phaser.World.html" > World< / a >
< / li >
< / ul >
< / li >
< / ul >
< / div >
< / div >
< div class = "row-fluid" >
< div class = "span12" >
< div id = "main" >
< h1 class = "page-title" > Source: physics/ninja/Circle.js< / h1 >
< section >
< article >
2014-03-28 01:42:49 +00:00
< pre class = "sunlight-highlight-javascript linenums" > /* jshint camelcase: false */
/**
2014-03-14 06:36:05 +00:00
* @author Richard Davey < rich@photonstorm.com>
* @copyright 2014 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Ninja Physics Circle constructor.
* Note: This class could be massively optimised and reduced in size. I leave that challenge up to you.
*
* @class Phaser.Physics.Ninja.Circle
* @classdesc Arcade Physics Constructor
* @constructor
* @param {Phaser.Physics.Ninja.Body} body - The body that owns this shape.
* @param {number} x - The x coordinate to create this shape at.
* @param {number} y - The y coordinate to create this shape at.
* @param {number} radius - The radius of this Circle.
*/
Phaser.Physics.Ninja.Circle = function (body, x, y, radius) {
/**
* @property {Phaser.Physics.Ninja.Body} system - A reference to the body that owns this shape.
*/
this.body = body;
/**
* @property {Phaser.Physics.Ninja} system - A reference to the physics system.
*/
this.system = body.system;
/**
* @property {Phaser.Point} pos - The position of this object.
*/
this.pos = new Phaser.Point(x, y);
/**
* @property {Phaser.Point} oldpos - The position of this object in the previous update.
*/
this.oldpos = new Phaser.Point(x, y);
/**
* @property {number} radius - The radius of this circle shape.
*/
this.radius = radius;
/**
* @property {number} xw - Half the width.
* @readonly
*/
this.xw = radius;
/**
* @property {number} xw - Half the height.
* @readonly
*/
this.yw = radius;
/**
* @property {number} width - The width.
* @readonly
*/
this.width = radius * 2;
/**
* @property {number} height - The height.
* @readonly
*/
this.height = radius * 2;
/**
* @property {number} oH - Internal var.
* @private
*/
this.oH = 0;
/**
* @property {number} oV - Internal var.
* @private
*/
this.oV = 0;
/**
* @property {Phaser.Point} velocity - The velocity of this object.
*/
this.velocity = new Phaser.Point();
/**
* @property {object} circleTileProjections - All of the collision response handlers.
*/
this.circleTileProjections = {};
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_FULL] = this.projCircle_Full;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_45DEG] = this.projCircle_45Deg;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_CONCAVE] = this.projCircle_Concave;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_CONVEX] = this.projCircle_Convex;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_22DEGs] = this.projCircle_22DegS;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_22DEGb] = this.projCircle_22DegB;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_67DEGs] = this.projCircle_67DegS;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_67DEGb] = this.projCircle_67DegB;
this.circleTileProjections[Phaser.Physics.Ninja.Tile.TYPE_HALF] = this.projCircle_Half;
2014-03-28 01:42:49 +00:00
};
2014-03-14 06:36:05 +00:00
Phaser.Physics.Ninja.Circle.prototype.constructor = Phaser.Physics.Ninja.Circle;
Phaser.Physics.Ninja.Circle.COL_NONE = 0;
Phaser.Physics.Ninja.Circle.COL_AXIS = 1;
Phaser.Physics.Ninja.Circle.COL_OTHER = 2;
Phaser.Physics.Ninja.Circle.prototype = {
/**
* Updates this Circles position.
*
* @method Phaser.Physics.Ninja.Circle#integrate
*/
integrate: function () {
var px = this.pos.x;
var py = this.pos.y;
// integrate
this.pos.x += (this.body.drag * this.pos.x) - (this.body.drag * this.oldpos.x);
this.pos.y += (this.body.drag * this.pos.y) - (this.body.drag * this.oldpos.y) + (this.system.gravity * this.body.gravityScale);
// store
this.velocity.set(this.pos.x - px, this.pos.y - py);
this.oldpos.set(px, py);
},
/**
* Process a world collision and apply the resulting forces.
*
* @method Phaser.Physics.Ninja.Circle#reportCollisionVsWorld
* @param {number} px - The tangent velocity
* @param {number} py - The tangent velocity
* @param {number} dx - Collision normal
* @param {number} dy - Collision normal
* @param {number} obj - Object this Circle collided with
*/
2014-03-28 01:42:49 +00:00
reportCollisionVsWorld: function (px, py, dx, dy) {
2014-03-14 06:36:05 +00:00
var p = this.pos;
var o = this.oldpos;
// Calc velocity
var vx = p.x - o.x;
var vy = p.y - o.y;
// Find component of velocity parallel to collision normal
var dp = (vx * dx + vy * dy);
var nx = dp * dx; //project velocity onto collision normal
var ny = dp * dy; //nx,ny is normal velocity
var tx = vx - nx; //px,py is tangent velocity
var ty = vy - ny;
// We only want to apply collision response forces if the object is travelling into, and not out of, the collision
var b, bx, by, fx, fy;
if (dp < 0)
{
fx = tx * this.body.friction;
fy = ty * this.body.friction;
b = 1 + this.body.bounce;
bx = (nx * b);
by = (ny * b);
if (dx === 1)
{
this.body.touching.left = true;
}
else if (dx === -1)
{
this.body.touching.right = true;
}
if (dy === 1)
{
this.body.touching.up = true;
}
else if (dy === -1)
{
this.body.touching.down = true;
}
}
else
{
// Moving out of collision, do not apply forces
bx = by = fx = fy = 0;
}
// Project object out of collision
p.x += px;
p.y += py;
// Apply bounce+friction impulses which alter velocity
o.x += px + bx + fx;
o.y += py + by + fy;
},
/**
* Collides this Circle against the world bounds.
*
* @method Phaser.Physics.Ninja.Circle#collideWorldBounds
*/
collideWorldBounds: function () {
var dx = this.system.bounds.x - (this.pos.x - this.radius);
if (0 < dx)
{
this.reportCollisionVsWorld(dx, 0, 1, 0, null);
}
else
{
2014-03-24 12:41:45 +00:00
dx = (this.pos.x + this.radius) - this.system.bounds.right;
2014-03-14 06:36:05 +00:00
if (0 < dx)
{
this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
}
}
var dy = this.system.bounds.y - (this.pos.y - this.radius);
if (0 < dy)
{
this.reportCollisionVsWorld(0, dy, 0, 1, null);
}
else
{
2014-03-24 12:41:45 +00:00
dy = (this.pos.y + this.radius) - this.system.bounds.bottom;
2014-03-14 06:36:05 +00:00
if (0 < dy)
{
this.reportCollisionVsWorld(0, -dy, 0, -1, null);
}
}
},
/**
* Collides this Circle with a Tile.
*
* @method Phaser.Physics.Ninja.Circle#collideCircleVsTile
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {boolean} True if they collide, otherwise false.
*/
collideCircleVsTile: function (tile) {
var pos = this.pos;
var r = this.radius;
var c = tile;
var tx = c.pos.x;
var ty = c.pos.y;
var txw = c.xw;
var tyw = c.yw;
var dx = pos.x - tx; // tile->obj delta
var px = (txw + r) - Math.abs(dx); // penetration depth in x
if (0 < px)
{
var dy = pos.y - ty; // tile->obj delta
var py = (tyw + r) - Math.abs(dy); // pen depth in y
if (0 < py)
{
// object may be colliding with tile
// determine grid/voronoi region of circle center
this.oH = 0;
this.oV = 0;
if (dx < -txw)
{
// circle is on left side of tile
this.oH = -1;
}
else if (txw < dx)
{
// circle is on right side of tile
this.oH = 1;
}
if (dy < -tyw)
{
// circle is on top side of tile
this.oV = -1;
}
else if (tyw < dy)
{
// circle is on bottom side of tile
this.oV = 1;
}
return this.resolveCircleTile(px, py, this.oH, this.oV, this, c);
}
}
},
/**
* Resolves tile collision.
*
* @method Phaser.Physics.Ninja.Circle#resolveCircleTile
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
resolveCircleTile: function (x, y, oH, oV, obj, t) {
if (0 < t.id)
{
return this.circleTileProjections[t.type](x, y, oH, oV, obj, t);
}
else
{
// console.log("ResolveCircleTile() was called with an empty (or unknown) tile!: ID=" + t.id + ")");
return false;
}
},
/**
* Resolves Full tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_Full
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_Full: function (x, y, oH, oV, obj, t) {
//if we're colliding vs. the current cell, we need to project along the
//smallest penetration vector.
//if we're colliding vs. horiz. or vert. neighb, we simply project horiz/vert
//if we're colliding diagonally, we need to collide vs. tile corner
2014-03-28 01:42:49 +00:00
if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//collision with current cell
if (x < y)
{
//penetration in x is smaller; project in x
var dx = obj.pos.x - t.pos.x;//get sign for projection along x-axis
2014-03-28 01:42:49 +00:00
//NOTE: should we handle the delta === 0 case?! and how? (project towards oldpos?)
2014-03-14 06:36:05 +00:00
if (dx < 0)
{
obj.reportCollisionVsWorld(-x, 0, -1, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
obj.reportCollisionVsWorld(x, 0, 1, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
}
else
{
2014-03-28 01:42:49 +00:00
//penetration in y is smaller; project in y
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - t.pos.y;//get sign for projection along y-axis
2014-03-28 01:42:49 +00:00
//NOTE: should we handle the delta === 0 case?! and how? (project towards oldpos?)
2014-03-14 06:36:05 +00:00
if (dy < 0)
{
obj.reportCollisionVsWorld(0, -y, 0, -1, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
obj.reportCollisionVsWorld(0, y, 0, 1, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
}
}
else
{
//collision with vertical neighbor
obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//collision with horizontal neighbor
obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//diagonal collision
//get diag vertex position
var vx = t.pos.x + (oH * t.xw);
var vy = t.pos.y + (oV * t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx * dx + dy * dy);
var pen = obj.radius - len;
if (0 < pen)
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves 45 Degree tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_45Deg
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_45Deg: function (x, y, oH, oV, obj, t) {
//if we're colliding diagonally:
// -if obj is in the diagonal pointed to by the slope normal: we can't collide, do nothing
// -else, collide vs. the appropriate vertex
//if obj is in this tile: perform collision as for aabb-ve-45deg
//if obj is horiz OR very neighb in direction of slope: collide only vs. slope
//if obj is horiz or vert neigh against direction of slope: collide vs. face
var signx = t.signx;
var signy = t.signy;
var lenP;
2014-03-28 01:42:49 +00:00
if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current tile
var sx = t.sx;
var sy = t.sy;
var ox = (obj.pos.x - (sx * obj.radius)) - t.pos.x;//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = (obj.pos.y - (sy * obj.radius)) - t.pos.y;//point on the circle, relative to the tile center
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the innermost point is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox * sx) + (oy * sy);
if (dp < 0)
{
//collision; project delta onto slope and use this as the slope penetration vector
sx *= -dp;//(sx,sy) is now the penetration vector
sy *= -dp;
//find the smallest axial projection vector
if (x < y)
{
//penetration in x is smaller
lenP = x;
y = 0;
2014-03-28 01:42:49 +00:00
//get sign for projection along x-axis
2014-03-14 06:36:05 +00:00
if ((obj.pos.x - t.pos.x) < 0)
{
x *= -1;
}
}
else
{
//penetration in y is smaller
lenP = y;
x = 0;
2014-03-28 01:42:49 +00:00
//get sign for projection along y-axis
2014-03-14 06:36:05 +00:00
if ((obj.pos.y - t.pos.y) < 0)
{
y *= -1;
}
}
var lenN = Math.sqrt(sx * sx + sy * sy);
if (lenP < lenN)
{
obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
else
{
//colliding vertically
if ((signy * oV) < 0)
{
//colliding with face/edge
obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
var sx = t.sx;
var sy = t.sy;
var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y + (oV * t.yw));//point on the circle, relative to the closest tile vert
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the vertex, otherwise by the normal.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronoi region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox * -sy) + (oy * sx);
if (0 < (perp * signx * signy))
{
//collide vs. vertex
var len = Math.sqrt(ox * ox + oy * oy);
var pen = obj.radius - len;
if (0 < pen)
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
else
{
//collide vs. slope
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox * sx) + (oy * sy);
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
if (0 < pen)
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
if ((signx * oH) < 0)
{
//colliding with face/edge
obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
var sx = t.sx;
var sy = t.sy;
var ox = obj.pos.x - (t.pos.x + (oH * t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//point on the circle, relative to the closest tile vert
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the normal, otherwise by the vertex.
//(NOTE: this is the opposite logic of the vertical case;
// for vertical, if the perp prod and the slope's slope agree, it's outside.
// for horizontal, if the perp prod and the slope's slope agree, circle is inside.
// ..but this is only a property of flahs' coord system (i.e the rules might swap
// in righthanded systems))
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox * -sy) + (oy * sx);
if ((perp * signx * signy) < 0)
{
//collide vs. vertex
var len = Math.sqrt(ox * ox + oy * oy);
var pen = obj.radius - len;
if (0 < pen)
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
else
{
//collide vs. slope
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox * sx) + (oy * sy);
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
if (0 < pen)
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
else
{
//colliding diagonally
if (0 < ((signx * oH) + (signy * oV)))
{
//the dotprod of slope normal and cell offset is strictly positive,
//therefore obj is in the diagonal neighb pointed at by the normal, and
//it cannot possibly reach/touch/penetrate the slope
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
else
{
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x + (oH * t.xw);
var vy = t.pos.y + (oV * t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx * dx + dy * dy);
var pen = obj.radius - len;
if (0 < pen)
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves Concave tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_Concave
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_Concave: function (x, y, oH, oV, obj, t) {
//if we're colliding diagonally:
// -if obj is in the diagonal pointed to by the slope normal: we can't collide, do nothing
// -else, collide vs. the appropriate vertex
//if obj is in this tile: perform collision as for aabb
//if obj is horiz OR very neighb in direction of slope: collide vs vert
//if obj is horiz or vert neigh against direction of slope: collide vs. face
var signx = t.signx;
var signy = t.signy;
var lenP;
2014-03-28 01:42:49 +00:00
if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current tile
2014-03-28 01:42:49 +00:00
var ox = (t.pos.x + (signx * t.xw)) - obj.pos.x;//(ox,oy) is the vector from the circle to
2014-03-14 06:36:05 +00:00
var oy = (t.pos.y + (signy * t.yw)) - obj.pos.y;//tile-circle's center
var twid = t.xw * 2;
var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
//note that this should be precomputed at compile-time since it's constant
var len = Math.sqrt(ox * ox + oy * oy);
var pen = (len + obj.radius) - trad;
if (0 < pen)
{
//find the smallest axial projection vector
if (x < y)
{
//penetration in x is smaller
lenP = x;
y = 0;
2014-03-28 01:42:49 +00:00
//get sign for projection along x-axis
2014-03-14 06:36:05 +00:00
if ((obj.pos.x - t.pos.x) < 0)
{
x *= -1;
}
}
else
{
//penetration in y is smaller
lenP = y;
x = 0;
2014-03-28 01:42:49 +00:00
//get sign for projection along y-axis
2014-03-14 06:36:05 +00:00
if ((obj.pos.y - t.pos.y) < 0)
{
y *= -1;
}
}
if (lenP < pen)
{
obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we can assume that len >0, because if we're here then
//(len + obj.radius) > trad, and since obj.radius < = trad
//len MUST be > 0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
else
{
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
}
else
{
//colliding vertically
if ((signy * oV) < 0)
{
//colliding with face/edge
obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we could only be colliding vs the vertical tip
//get diag vertex position
var vx = t.pos.x - (signx * t.xw);
var vy = t.pos.y + (oV * t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx * dx + dy * dy);
var pen = obj.radius - len;
if (0 < pen)
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out vertically
dx = 0;
dy = oV;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
if ((signx * oH) < 0)
{
//colliding with face/edge
obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we could only be colliding vs the horizontal tip
//get diag vertex position
var vx = t.pos.x + (oH * t.xw);
var vy = t.pos.y - (signy * t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx * dx + dy * dy);
var pen = obj.radius - len;
if (0 < pen)
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out horizontally
dx = oH;
dy = 0;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
else
{
//colliding diagonally
if (0 < ((signx * oH) + (signy * oV)))
{
//the dotprod of slope normal and cell offset is strictly positive,
//therefore obj is in the diagonal neighb pointed at by the normal, and
//it cannot possibly reach/touch/penetrate the slope
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
else
{
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x + (oH * t.xw);
var vy = t.pos.y + (oV * t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx * dx + dy * dy);
var pen = obj.radius - len;
if (0 < pen)
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves Convex tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_Convex
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_Convex: function (x, y, oH, oV, obj, t) {
//if the object is horiz AND/OR vertical neighbor in the normal (signx,signy)
//direction, collide vs. tile-circle only.
//if we're colliding diagonally:
// -else, collide vs. the appropriate vertex
//if obj is in this tile: perform collision as for aabb
//if obj is horiz or vert neigh against direction of slope: collide vs. face
var signx = t.signx;
var signy = t.signy;
var lenP;
2014-03-28 01:42:49 +00:00
if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current tile
2014-03-28 01:42:49 +00:00
var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
2014-03-14 06:36:05 +00:00
var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
var twid = t.xw * 2;
var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
//note that this should be precomputed at compile-time since it's constant
var len = Math.sqrt(ox * ox + oy * oy);
var pen = (trad + obj.radius) - len;
if (0 < pen)
{
//find the smallest axial projection vector
if (x < y)
{
//penetration in x is smaller
lenP = x;
y = 0;
2014-03-28 01:42:49 +00:00
//get sign for projection along x-axis
2014-03-14 06:36:05 +00:00
if ((obj.pos.x - t.pos.x) < 0)
{
x *= -1;
}
}
else
{
//penetration in y is smaller
lenP = y;
x = 0;
2014-03-28 01:42:49 +00:00
//get sign for projection along y-axis
2014-03-14 06:36:05 +00:00
if ((obj.pos.y - t.pos.y) < 0)
{
y *= -1;
}
}
if (lenP < pen)
{
obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
2014-03-28 01:42:49 +00:00
//note: len should NEVER be === 0, because if it is,
2014-03-14 06:36:05 +00:00
//projeciton by an axis shoudl always be shorter, and we should
//never arrive here
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
else
{
//colliding vertically
if ((signy * oV) < 0)
{
//colliding with face/edge
obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//obj in neighboring cell pointed at by tile normal;
//we could only be colliding vs the tile-circle surface
2014-03-28 01:42:49 +00:00
var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
2014-03-14 06:36:05 +00:00
var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
var twid = t.xw * 2;
var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
//note that this should be precomputed at compile-time since it's constant
var len = Math.sqrt(ox * ox + oy * oy);
var pen = (trad + obj.radius) - len;
if (0 < pen)
{
2014-03-28 01:42:49 +00:00
//note: len should NEVER be === 0, because if it is,
2014-03-14 06:36:05 +00:00
//obj is not in a neighboring cell!
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
if ((signx * oH) < 0)
{
//colliding with face/edge
obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//obj in neighboring cell pointed at by tile normal;
//we could only be colliding vs the tile-circle surface
2014-03-28 01:42:49 +00:00
var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
2014-03-14 06:36:05 +00:00
var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
var twid = t.xw * 2;
var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
//note that this should be precomputed at compile-time since it's constant
var len = Math.sqrt(ox * ox + oy * oy);
var pen = (trad + obj.radius) - len;
if (0 < pen)
{
2014-03-28 01:42:49 +00:00
//note: len should NEVER be === 0, because if it is,
2014-03-14 06:36:05 +00:00
//obj is not in a neighboring cell!
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
else
{
//colliding diagonally
if (0 < ((signx * oH) + (signy * oV)))
{
//obj in diag neighb cell pointed at by tile normal;
//we could only be colliding vs the tile-circle surface
2014-03-28 01:42:49 +00:00
var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
2014-03-14 06:36:05 +00:00
var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
var twid = t.xw * 2;
var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
//note that this should be precomputed at compile-time since it's constant
var len = Math.sqrt(ox * ox + oy * oy);
var pen = (trad + obj.radius) - len;
if (0 < pen)
{
2014-03-28 01:42:49 +00:00
//note: len should NEVER be === 0, because if it is,
2014-03-14 06:36:05 +00:00
//obj is not in a neighboring cell!
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
else
{
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x + (oH * t.xw);
var vy = t.pos.y + (oV * t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx * dx + dy * dy);
var pen = obj.radius - len;
if (0 < pen)
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves Half tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_Half
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_Half: function (x,y,oH,oV,obj,t) {
//if obj is in a neighbor pointed at by the halfedge normal,
//we'll never collide (i.e if the normal is (0,1) and the obj is in the DL.D, or R neighbors)
//
//if obj is in a neigbor perpendicular to the halfedge normal, it might
//collide with the halfedge-vertex, or with the halfedge side.
//
//if obj is in a neigb pointing opposite the halfedge normal, obj collides with edge
//
//if obj is in a diagonal (pointing away from the normal), obj collides vs vertex
//
//if obj is in the halfedge cell, it collides as with aabb
var signx = t.signx;
var signy = t.signy;
var celldp = (oH*signx + oV*signy);//this tells us about the configuration of cell-offset relative to tile normal
2014-03-28 01:42:49 +00:00
if (0 < celldp)
2014-03-14 06:36:05 +00:00
{
//obj is in "far" (pointed-at-by-normal) neighbor of halffull tile, and will never hit
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
2014-03-28 01:42:49 +00:00
else if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current tile
var r = obj.radius;
var ox = (obj.pos.x - (signx*r)) - t.pos.x;//this gives is the coordinates of the innermost
var oy = (obj.pos.y - (signy*r)) - t.pos.y;//point on the circle, relative to the tile center
2014-03-28 01:42:49 +00:00
//we perform operations analogous to the 45deg tile, except we're using
2014-03-14 06:36:05 +00:00
//an axis-aligned slope instead of an angled one..
var sx = signx;
var sy = signy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
//collision; project delta onto slope and use this to displace the object
sx *= -dp;//(sx,sy) is now the projection vector
2014-03-28 01:42:49 +00:00
sy *= -dp;
2014-03-14 06:36:05 +00:00
var lenN = Math.sqrt(sx*sx + sy*sy);
var lenP = Math.sqrt(x*x + y*y);
2014-03-28 01:42:49 +00:00
if (lenP < lenN)
2014-03-14 06:36:05 +00:00
{
obj.reportCollisionVsWorld(x,y,x/lenP, y/lenP,t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(sx,sy,t.signx,t.signy);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
return true;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vertically
2014-03-28 01:42:49 +00:00
if (celldp === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var dx = obj.pos.x - t.pos.x;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//we're in a cell perpendicular to the normal, and can collide vs. halfedge vertex
//or halfedge side
2014-03-28 01:42:49 +00:00
if ((dx*signx) < 0)
2014-03-14 06:36:05 +00:00
{
//collision with halfedge side
obj.reportCollisionVsWorld(0,y*oV,0,oV,t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
{
//collision with halfedge vertex
var dy = obj.pos.y - (t.pos.y + oV*t.yw);//(dx,dy) is now the vector from the appropriate halfedge vertex to the circle
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = signx / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
}
else
{
//due to the first conditional (celldp >0), we know we're in the cell "opposite" the normal, and so
//we can only collide with the cell edge
//collision with vertical neighbor
obj.reportCollisionVsWorld(0,y*oV,0,oV,t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
2014-03-28 01:42:49 +00:00
if (celldp === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - t.pos.y;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//we're in a cell perpendicular to the normal, and can collide vs. halfedge vertex
//or halfedge side
2014-03-28 01:42:49 +00:00
if ((dy*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//collision with halfedge side
obj.reportCollisionVsWorld(x*oH,0,oH,0,t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
{
//collision with halfedge vertex
var dx = obj.pos.x - (t.pos.x + oH*t.xw);//(dx,dy) is now the vector from the appropriate halfedge vertex to the circle
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = signx / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//due to the first conditional (celldp >0), we know w're in the cell "opposite" the normal, and so
//we can only collide with the cell edge
obj.reportCollisionVsWorld(x*oH, 0, oH, 0, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//colliding diagonally; we know, due to the initial (celldp >0) test which has failed
//if we've reached this point, that we're in a diagonal neighbor on the non-normal side, so
//we could only be colliding with the cell vertex, if at all.
//get diag vertex position
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y + (oV*t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_NONE;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
},
/**
* Resolves 22 Degree tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_22DegS
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_22DegS: function (x,y,oH,oV,obj,t) {
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the object is in a cell pointed at by signy, no collision will ever occur
//otherwise,
//
//if we're colliding diagonally:
// -collide vs. the appropriate vertex
//if obj is in this tile: collide vs slope or vertex
//if obj is horiz neighb in direction of slope: collide vs. slope or vertex
//if obj is horiz neighb against the slope:
2014-03-28 01:42:49 +00:00
// if (distance in y from circle to 90deg corner of tile < 1/2 tileheight, collide vs. face)
2014-03-14 06:36:05 +00:00
// else(collide vs. corner of slope) (vert collision with a non-grid-aligned vert)
//if obj is vert neighb against direction of slope: collide vs. face
2014-03-28 01:42:49 +00:00
var lenP;
2014-03-14 06:36:05 +00:00
var signx = t.signx;
var signy = t.signy;
2014-03-28 01:42:49 +00:00
if (0 < (signy*oV))
2014-03-14 06:36:05 +00:00
{
//object will never collide vs tile, it can't reach that far
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
2014-03-28 01:42:49 +00:00
else if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current tile
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var r = obj.radius;
var ox = obj.pos.x - (t.pos.x - (signx*t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - t.pos.y;//point on the circle, relative to the tile corner
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the vertex, otherwise by the normal or axially.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
2014-03-14 06:36:05 +00:00
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if (0 < (perp*signx*signy))
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = r - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope or vs axis
2014-03-28 01:42:49 +00:00
ox -= r*sx;//this gives us the vector from
2014-03-14 06:36:05 +00:00
oy -= r*sy;//a point on the slope to the innermost point on the circle
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
//collision; project delta onto slope and use this to displace the object
sx *= -dp;//(sx,sy) is now the projection vector
2014-03-28 01:42:49 +00:00
sy *= -dp;
2014-03-14 06:36:05 +00:00
var lenN = Math.sqrt(sx*sx + sy*sy);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//find the smallest axial projection vector
2014-03-28 01:42:49 +00:00
if (x < y)
{
2014-03-14 06:36:05 +00:00
//penetration in x is smaller
lenP = x;
2014-03-28 01:42:49 +00:00
y = 0;
//get sign for projection along x-axis
if ((obj.pos.x - t.pos.x) < 0)
2014-03-14 06:36:05 +00:00
{
x *= -1;
}
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//penetration in y is smaller
lenP = y;
2014-03-28 01:42:49 +00:00
x = 0;
//get sign for projection along y-axis
if ((obj.pos.y - t.pos.y)< 0)
2014-03-14 06:36:05 +00:00
{
y *= -1;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
if (lenP < lenN)
2014-03-14 06:36:05 +00:00
{
obj.reportCollisionVsWorld(x,y,x/lenP, y/lenP, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(sx,sy,t.sx,t.sy,t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
}
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vertically; we can assume that (signy*oV) < 0
//due to the first conditional far above
obj.reportCollisionVsWorld(0,y*oV, 0, oV, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
2014-03-28 01:42:49 +00:00
if ((signx*oH) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding with face/edge OR with corner of wedge, depending on our position vertically
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x - (signx*t.xw);
var vy = t.pos.y;
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
if ((dy*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding vs face
obj.reportCollisionVsWorld(x*oH, 0, oH, 0, t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vs. vertex
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
else
{
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var ox = obj.pos.x - (t.pos.x + (oH*t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y - (signy*t.yw));//point on the circle, relative to the closest tile vert
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the normal, otherwise by the vertex.
//(NOTE: this is the opposite logic of the vertical case;
// for vertical, if the perp prod and the slope's slope agree, it's outside.
// for horizontal, if the perp prod and the slope's slope agree, circle is inside.
// ..but this is only a property of flahs' coord system (i.e the rules might swap
// in righthanded systems))
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if ((perp*signx*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
2014-03-14 06:36:05 +00:00
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx*pen, sy*pen, sx, sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
else
{
//colliding diagonally; due to the first conditional above,
//obj is vertically offset against slope, and offset in either direction horizontally
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y + (oV*t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves 22 Degree tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_22DegB
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_22DegB: function (x,y,oH, oV, obj,t) {
//if we're colliding diagonally:
// -if we're in the cell pointed at by the normal, collide vs slope, else
// collide vs. the appropriate corner/vertex
//
//if obj is in this tile: collide as with aabb
//
//if obj is horiz or vertical neighbor AGAINST the slope: collide with edge
//
//if obj is horiz neighb in direction of slope: collide vs. slope or vertex or edge
//
//if obj is vert neighb in direction of slope: collide vs. slope or vertex
2014-03-28 01:42:49 +00:00
var lenP;
2014-03-14 06:36:05 +00:00
var signx = t.signx;
var signy = t.signy;
2014-03-28 01:42:49 +00:00
if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current cell
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var r = obj.radius;
var ox = (obj.pos.x - (sx*r)) - (t.pos.x - (signx*t.xw));//this gives is the coordinates of the innermost
var oy = (obj.pos.y - (sy*r)) - (t.pos.y + (signy*t.yw));//point on the AABB, relative to a point on the slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
//collision; project delta onto slope and use this to displace the object
sx *= -dp;//(sx,sy) is now the projection vector
2014-03-28 01:42:49 +00:00
sy *= -dp;
2014-03-14 06:36:05 +00:00
var lenN = Math.sqrt(sx*sx + sy*sy);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//find the smallest axial projection vector
2014-03-28 01:42:49 +00:00
if (x < y)
{
2014-03-14 06:36:05 +00:00
//penetration in x is smaller
lenP = x;
2014-03-28 01:42:49 +00:00
y = 0;
//get sign for projection along x-axis
if ((obj.pos.x - t.pos.x) < 0)
2014-03-14 06:36:05 +00:00
{
x *= -1;
}
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//penetration in y is smaller
lenP = y;
2014-03-28 01:42:49 +00:00
x = 0;
//get sign for projection along y-axis
if ((obj.pos.y - t.pos.y)< 0)
2014-03-14 06:36:05 +00:00
{
y *= -1;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
if (lenP < lenN)
2014-03-14 06:36:05 +00:00
{
obj.reportCollisionVsWorld(x, y, x/lenP, y/lenP, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
}
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vertically
2014-03-28 01:42:49 +00:00
if ((signy*oV) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding with face/edge
obj.reportCollisionVsWorld(0, y*oV, 0, oV, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var ox = obj.pos.x - (t.pos.x - (signx*t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y + (signy*t.yw));//point on the circle, relative to the closest tile vert
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the vertex, otherwise by the normal.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if (0 < (perp*signx*signy))
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox*sx) + (oy*sy);
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx*pen, sy*pen,sx, sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
2014-03-28 01:42:49 +00:00
if ((signx*oH) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding with face/edge
obj.reportCollisionVsWorld(x*oH, 0, oH, 0, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//colliding with edge, slope, or vertex
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var ox = obj.pos.x - (t.pos.x + (signx*t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - t.pos.y;//point on the circle, relative to the closest tile vert
if ((oy*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//we're colliding with the halfface
obj.reportCollisionVsWorld(x*oH, 0, oH, 0, t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
{
//colliding with the vertex or slope
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the slope, otherwise by the vertex.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if ((perp*signx*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox*sx) + (oy*sy);
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx*pen, sy*pen, t.sx, t.sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
}
}
else
{
//colliding diagonally
2014-03-28 01:42:49 +00:00
if ( 0 < ((signx*oH) + (signy*oV)) )
2014-03-14 06:36:05 +00:00
{
//the dotprod of slope normal and cell offset is strictly positive,
//therefore obj is in the diagonal neighb pointed at by the normal.
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//collide vs slope
//we should really precalc this at compile time, but for now, fuck it
var slen = Math.sqrt(2*2 + 1*1);//the raw slope is (-2,-1)
var sx = (signx*1) / slen;//get slope _unit_ normal;
var sy = (signy*2) / slen;//raw RH normal is (1,-2)
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var r = obj.radius;
var ox = (obj.pos.x - (sx*r)) - (t.pos.x - (signx*t.xw));//this gives is the coordinates of the innermost
var oy = (obj.pos.y - (sy*r)) - (t.pos.y + (signy*t.yw));//point on the circle, relative to a point on the slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
//collision; project delta onto slope and use this to displace the object
2014-03-14 06:36:05 +00:00
//(sx,sy)*-dp is the projection vector
obj.reportCollisionVsWorld(-sx*dp, -sy*dp, t.sx, t.sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
else
{
//collide vs the appropriate vertex
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y + (oV*t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves 67 Degree tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_67DegS
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_67DegS: function (x,y,oH,oV,obj,t) {
//if the object is in a cell pointed at by signx, no collision will ever occur
//otherwise,
//
//if we're colliding diagonally:
// -collide vs. the appropriate vertex
//if obj is in this tile: collide vs slope or vertex or axis
//if obj is vert neighb in direction of slope: collide vs. slope or vertex
//if obj is vert neighb against the slope:
2014-03-28 01:42:49 +00:00
// if (distance in y from circle to 90deg corner of tile < 1/2 tileheight, collide vs. face)
2014-03-14 06:36:05 +00:00
// else(collide vs. corner of slope) (vert collision with a non-grid-aligned vert)
//if obj is horiz neighb against direction of slope: collide vs. face
var signx = t.signx;
var signy = t.signy;
2014-03-28 01:42:49 +00:00
if (0 < (signx*oH))
2014-03-14 06:36:05 +00:00
{
//object will never collide vs tile, it can't reach that far
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
2014-03-28 01:42:49 +00:00
else if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current tile
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
2014-03-28 01:42:49 +00:00
var lenP;
2014-03-14 06:36:05 +00:00
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var r = obj.radius;
var ox = obj.pos.x - t.pos.x;//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y - (signy*t.yw));//point on the circle, relative to the tile corner
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the normal or axis, otherwise by the corner/vertex
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
2014-03-14 06:36:05 +00:00
//if the circle is in side the slope/face's voronoi region, or that of the vertex.
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if ((perp*signx*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = r - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope or vs axis
2014-03-28 01:42:49 +00:00
ox -= r*sx;//this gives us the vector from
2014-03-14 06:36:05 +00:00
oy -= r*sy;//a point on the slope to the innermost point on the circle
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
//collision; project delta onto slope and use this to displace the object
sx *= -dp;//(sx,sy) is now the projection vector
2014-03-28 01:42:49 +00:00
sy *= -dp;
2014-03-14 06:36:05 +00:00
var lenN = Math.sqrt(sx*sx + sy*sy);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//find the smallest axial projection vector
2014-03-28 01:42:49 +00:00
if (x < y)
{
2014-03-14 06:36:05 +00:00
//penetration in x is smaller
lenP = x;
2014-03-28 01:42:49 +00:00
y = 0;
//get sign for projection along x-axis
if ((obj.pos.x - t.pos.x) < 0)
2014-03-14 06:36:05 +00:00
{
x *= -1;
}
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//penetration in y is smaller
lenP = y;
2014-03-28 01:42:49 +00:00
x = 0;
//get sign for projection along y-axis
if ((obj.pos.y - t.pos.y)< 0)
2014-03-14 06:36:05 +00:00
{
y *= -1;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
if (lenP < lenN)
2014-03-14 06:36:05 +00:00
{
obj.reportCollisionVsWorld(x,y,x/lenP, y/lenP, t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(sx,sy,t.sx,t.sy,t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vertically
2014-03-28 01:42:49 +00:00
if ((signy*oV) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding with face/edge OR with corner of wedge, depending on our position vertically
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x;
var vy = t.pos.y - (signy*t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
if ((dx*signx) < 0)
{
2014-03-14 06:36:05 +00:00
//colliding vs face
obj.reportCollisionVsWorld(0, y*oV, 0, oV, t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vs. vertex
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
else
{
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var ox = obj.pos.x - (t.pos.x - (signx*t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y + (oV*t.yw));//point on the circle, relative to the closest tile vert
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the vertex, otherwise by the normal.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if (0 < (perp*signx*signy))
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
2014-03-14 06:36:05 +00:00
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx*pen, sy*pen, t.sx, t.sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally; we can assume that (signy*oV) < 0
//due to the first conditional far above
2014-03-28 01:42:49 +00:00
obj.reportCollisionVsWorld(x*oH, 0, oH, 0, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//colliding diagonally; due to the first conditional above,
//obj is vertically offset against slope, and offset in either direction horizontally
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y + (oV*t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
},
/**
* Resolves 67 Degree tile collision.
*
* @method Phaser.Physics.Ninja.Circle#projCircle_67DegB
* @param {number} x - Penetration depth on the x axis.
* @param {number} y - Penetration depth on the y axis.
* @param {number} oH - Grid / voronoi region.
* @param {number} oV - Grid / voronoi region.
* @param {Phaser.Physics.Ninja.Circle} obj - The Circle involved in the collision.
* @param {Phaser.Physics.Ninja.Tile} t - The Tile involved in the collision.
* @return {number} The result of the collision.
*/
projCircle_67DegB: function (x,y,oH, oV, obj,t) {
//if we're colliding diagonally:
// -if we're in the cell pointed at by the normal, collide vs slope, else
// collide vs. the appropriate corner/vertex
//
//if obj is in this tile: collide as with aabb
//
//if obj is horiz or vertical neighbor AGAINST the slope: collide with edge
//
//if obj is vert neighb in direction of slope: collide vs. slope or vertex or halfedge
//
//if obj is horiz neighb in direction of slope: collide vs. slope or vertex
var signx = t.signx;
var signy = t.signy;
2014-03-28 01:42:49 +00:00
if (oH === 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding with current cell
2014-03-28 01:42:49 +00:00
var lenP;
2014-03-14 06:36:05 +00:00
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var r = obj.radius;
var ox = (obj.pos.x - (sx*r)) - (t.pos.x + (signx*t.xw));//this gives is the coordinates of the innermost
var oy = (obj.pos.y - (sy*r)) - (t.pos.y - (signy*t.yw));//point on the AABB, relative to a point on the slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
//collision; project delta onto slope and use this to displace the object
sx *= -dp;//(sx,sy) is now the projection vector
2014-03-28 01:42:49 +00:00
sy *= -dp;
2014-03-14 06:36:05 +00:00
var lenN = Math.sqrt(sx*sx + sy*sy);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//find the smallest axial projection vector
2014-03-28 01:42:49 +00:00
if (x < y)
{
2014-03-14 06:36:05 +00:00
//penetration in x is smaller
lenP = x;
2014-03-28 01:42:49 +00:00
y = 0;
//get sign for projection along x-axis
if ((obj.pos.x - t.pos.x) < 0)
2014-03-14 06:36:05 +00:00
{
x *= -1;
}
}
else
2014-03-28 01:42:49 +00:00
{
2014-03-14 06:36:05 +00:00
//penetration in y is smaller
lenP = y;
2014-03-28 01:42:49 +00:00
x = 0;
//get sign for projection along y-axis
if ((obj.pos.y - t.pos.y)< 0)
2014-03-14 06:36:05 +00:00
{
y *= -1;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
if (lenP < lenN)
2014-03-14 06:36:05 +00:00
{
obj.reportCollisionVsWorld(x,y,x/lenP, y/lenP, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//colliding vertically
2014-03-28 01:42:49 +00:00
if ((signy*oV) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding with face/edge
obj.reportCollisionVsWorld(0, y*oV, 0, oV, t);
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//colliding with edge, slope, or vertex
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var ox = obj.pos.x - t.pos.x;//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y + (signy*t.yw));//point on the circle, relative to the closest tile vert
if ((ox*signx) < 0)
2014-03-14 06:36:05 +00:00
{
//we're colliding with the halfface
obj.reportCollisionVsWorld(0, y*oV, 0, oV, t);
2014-03-28 01:42:49 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
2014-03-14 06:36:05 +00:00
}
else
{
//colliding with the vertex or slope
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the vertex, otherwise by the slope.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if (0 < (perp*signx*signy))
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox*sx) + (oy*sy);
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx*pen, sy*pen, sx, sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
}
}
}
2014-03-28 01:42:49 +00:00
else if (oV === 0)
2014-03-14 06:36:05 +00:00
{
//colliding horizontally
2014-03-28 01:42:49 +00:00
if ((signx*oH) < 0)
2014-03-14 06:36:05 +00:00
{
//colliding with face/edge
obj.reportCollisionVsWorld(x*oH, 0, oH, 0, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_AXIS;
}
else
{
//we could only be colliding vs the slope OR a vertex
//look at the vector form the closest vert to the circle to decide
var slen = Math.sqrt(2*2 + 1*1);//the raw slope is (-2,-1)
var sx = (signx*2) / slen;//get slope _unit_ normal;
var sy = (signy*1) / slen;//raw RH normal is (1,-2)
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var ox = obj.pos.x - (t.pos.x + (signx*t.xw));//this gives is the coordinates of the innermost
2014-03-28 01:42:49 +00:00
var oy = obj.pos.y - (t.pos.y - (signy*t.yw));//point on the circle, relative to the closest tile vert
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal's righthand normal
//has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
//then we project by the slope, otherwise by the vertex.
2014-03-28 01:42:49 +00:00
//note that this is simply a VERY tricky/weird method of determining
//if the circle is in side the slope/face's voronio region, or that of the vertex.
2014-03-14 06:36:05 +00:00
var perp = (ox*-sy) + (oy*sx);
2014-03-28 01:42:49 +00:00
if ((perp*signx*signy) < 0)
2014-03-14 06:36:05 +00:00
{
//collide vs. vertex
var len = Math.sqrt(ox*ox + oy*oy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
ox /= len;
oy /= len;
obj.reportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
else
{
//collide vs. slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
//penetrating the slope. note that this method of penetration calculation doesn't hold
//in general (i.e it won't work if the circle is in the slope), but works in this case
//because we know the circle is in a neighboring cell
var dp = (ox*sx) + (oy*sy);
var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//collision; circle out along normal by penetration amount
obj.reportCollisionVsWorld(sx*pen, sy*pen, t.sx, t.sy, t);
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
}
}
}
else
{
//colliding diagonally
2014-03-28 01:42:49 +00:00
if ( 0 < ((signx*oH) + (signy*oV)) )
2014-03-14 06:36:05 +00:00
{
//the dotprod of slope normal and cell offset is strictly positive,
//therefore obj is in the diagonal neighb pointed at by the normal.
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//collide vs slope
var sx = t.sx;
var sy = t.sy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var r = obj.radius;
var ox = (obj.pos.x - (sx*r)) - (t.pos.x + (signx*t.xw));//this gives is the coordinates of the innermost
var oy = (obj.pos.y - (sy*r)) - (t.pos.y - (signy*t.yw));//point on the circle, relative to a point on the slope
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
var dp = (ox*sx) + (oy*sy);
2014-03-28 01:42:49 +00:00
if (dp < 0)
2014-03-14 06:36:05 +00:00
{
2014-03-28 01:42:49 +00:00
//collision; project delta onto slope and use this to displace the object
2014-03-14 06:36:05 +00:00
//(sx,sy)*-dp is the projection vector
obj.reportCollisionVsWorld(-sx*dp, -sy*dp, t.sx, t.sy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
return Phaser.Physics.Ninja.Circle.COL_NONE;
}
else
{
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
//collide vs the appropriate vertex
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y + (oV*t.yw);
2014-03-28 01:42:49 +00:00
var dx = obj.pos.x - vx;//calc vert->circle vector
2014-03-14 06:36:05 +00:00
var dy = obj.pos.y - vy;
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.radius - len;
2014-03-28 01:42:49 +00:00
if (0 < pen)
2014-03-14 06:36:05 +00:00
{
//vertex is in the circle; project outward
2014-03-28 01:42:49 +00:00
if (len === 0)
2014-03-14 06:36:05 +00:00
{
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else
{
dx /= len;
dy /= len;
}
obj.reportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
return Phaser.Physics.Ninja.Circle.COL_OTHER;
}
2014-03-28 01:42:49 +00:00
}
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
2014-03-14 06:36:05 +00:00
return Phaser.Physics.Ninja.Circle.COL_NONE;
2014-03-24 12:41:45 +00:00
},
/**
* Destroys this Circle's reference to Body and System
*
* @method Phaser.Physics.Ninja.Circle#destroy
*/
destroy: function() {
this.body = null;
this.system = null;
2014-03-14 06:36:05 +00:00
}
2014-03-28 01:42:49 +00:00
};
2014-03-14 06:36:05 +00:00
< / pre >
< / article >
< / section >
< / div >
< div class = "clearfix" > < / div >
< footer >
< span class = "copyright" >
Phaser Copyright © 2012-2014 Photon Storm Ltd.
< / span >
< br / >
< span class = "jsdoc-message" >
2014-04-11 12:09:28 +00:00
Documentation generated by < a href = "https://github.com/jsdoc3/jsdoc" > JSDoc 3.3.0-dev< / a >
2014-04-11 12:28:17 +00:00
on Fri Apr 11 2014 13:25:03 GMT+0100 (BST) using the < a href = "https://github.com/terryweiss/docstrap" > DocStrap template< / a > .
2014-03-14 06:36:05 +00:00
< / span >
< / footer >
< / div >
< br clear = "both" >
< / div >
< / div >
< script src = "scripts/sunlight.js" > < / script >
< script src = "scripts/sunlight.javascript.js" > < / script >
< script src = "scripts/sunlight-plugin.doclinks.js" > < / script >
< script src = "scripts/sunlight-plugin.linenumbers.js" > < / script >
< script src = "scripts/sunlight-plugin.menu.js" > < / script >
< script src = "scripts/jquery.min.js" > < / script >
< script src = "scripts/jquery.scrollTo.js" > < / script >
< script src = "scripts/jquery.localScroll.js" > < / script >
< script src = "scripts/bootstrap-dropdown.js" > < / script >
< script src = "scripts/toc.js" > < / script >
< script > Sunlight . highlightAll ( { lineNumbers : true , showMenu : true , enableDoclinks : true } ) ; < / script >
< script >
$( function () {
$( "#toc" ).toc( {
2014-04-10 22:13:43 +00:00
anchorName : function(i, heading, prefix) {
2014-03-14 06:36:05 +00:00
return $(heading).attr("id") || ( prefix + i );
},
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
< / script >
< / body >
< / html >