-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | 2D physics for apecs
--   
--   2D physics for apecs. Uses Chipmunk physics library under the hood.
@package apecs-physics
@version 0.3.2


-- | apecs-physics prelude
module Apecs.Physics

-- | Uninhabited, should be added to the world as a component to add a
--   physics space.
data Physics

-- | Gravity force vector, global value
newtype Gravity
Gravity :: Vec -> Gravity

-- | Number of iterations per step, global value
newtype Iterations
Iterations :: Int -> Iterations
stepPhysics :: Has w IO Physics => Double -> System w ()
earthGravity :: Gravity

-- | Added to a component to add it to the physics space. Deleting it will
--   also delete all associated shapes and constraints. A body has a number
--   of subcomponents: <tt>Position</tt>, <tt>Velocity</tt>,
--   <tt>Force</tt>, <tt>Torque</tt>, <tt>BodyMass</tt>, <tt>Moment</tt>,
--   <tt>Angle</tt>, <tt>AngularVelocity</tt>, and
--   <tt>CenterOfGravity</tt>. These components cannot be added or removed
--   from an entity, but rather are present as long as the entity has a
--   <tt>Body</tt>.
data Body
DynamicBody :: Body
KinematicBody :: Body
StaticBody :: Body

-- | A subcomponent of <tt>Body</tt> representing where it is in world
--   coordinates.
newtype Position
Position :: WVec -> Position

-- | A subcomponent of <tt>Body</tt> representing where it is going in
--   world coordinates
newtype Velocity
Velocity :: WVec -> Velocity
newtype Angle
Angle :: Double -> Angle
newtype AngularVelocity
AngularVelocity :: Double -> AngularVelocity

-- | A component used to apply a force to a <tt>Body</tt>. The force is
--   applied to the body's center of gravity. This component is reset to
--   <tt> Vec 0 0 </tt> after every stimulation step, so it is mainly used
--   to apply a force as opposed to being read.
newtype Force
Force :: Vec -> Force

-- | A component representing the mass of the <tt>Body</tt> overall.
newtype BodyMass
BodyMass :: Double -> BodyMass

-- | The moment of inertia of the <tt>Body</tt>. This is basically the
--   body's tendency to resist angular acceleration.
newtype Moment
Moment :: Double -> Moment

-- | Where the <tt>Body</tt>'s center of gravity is, in body-local
--   coordinates. Can be read and written to.
newtype CenterOfGravity
CenterOfGravity :: BVec -> CenterOfGravity

-- | A component used to apply a torque to a <tt>Body</tt>. The torque is
--   applied to the entire body at once. This component is reset to <tt> 0
--   </tt> after every simulation step, so it is mainly used to apply a
--   torque as opposed to being read.
newtype Torque
Torque :: Double -> Torque

-- | The <tt>Shape</tt>s belonging to a body. Read-only.
newtype ShapeList
ShapeList :: [Entity] -> ShapeList

-- | The <tt>Constraint</tt>s belonging to a body. Read-only.
newtype ConstraintList
ConstraintList :: [Entity] -> ConstraintList

-- | A convex polygon. Consists of a list of vertices, and a radius.
data Convex
Convex :: [BVec] -> Double -> Convex

-- | Shape component. Adding a shape to an entity that has no <tt>Body</tt>
--   is a noop.
data Shape
Shape :: Entity -> Convex -> Shape

-- | The mass of a shape is technically a measure of how much resistance it
--   has to being accelerated, but it's generally easier to understand it
--   as being how "heavy" something is.
--   
--   The physics engine lets you set this, and it will calculate the
--   <a>Density</a> and other components for you.
--   
--   See <a>https://en.wikipedia.org/wiki/Mass</a> for more information.
newtype Mass
Mass :: Double -> Mass

-- | The density of a shape is a measure of how much mass an object has in
--   a given volume.
--   
--   The physics engine lets you set this, and it will calculate the
--   <a>Mass</a> and other components for you.
--   
--   See <a>https://en.wikipedia.org/wiki/Density</a> for more information.
newtype Density
Density :: Double -> Density

-- | If a body is a <a>Sensor</a>, it exists only to trigger collision
--   responses. It won't phyiscally interact with other bodies in any way,
--   but it <b>will</b> cause collision handlers to run.
newtype Sensor
Sensor :: Bool -> Sensor

-- | The friction of an object is a measure of how much it resists
--   movement. Shapes with high friction will naturally slow down more
--   quickly over time than objects with low friction.
--   
--   See <a>https://en.wikipedia.org/wiki/Friction</a> for more
--   information.
newtype Friction
Friction :: Double -> Friction

-- | The elasticity of a shape. Higher elasticities will create more
--   elastic collisions, IE, will be bouncier.
--   
--   See <a>https://en.wikipedia.org/wiki/Elasticity_(physics)</a> for more
--   information.
newtype Elasticity
Elasticity :: Double -> Elasticity
newtype SurfaceVelocity
SurfaceVelocity :: Vec -> SurfaceVelocity
data CollisionFilter
CollisionFilter :: CollisionGroup -> Bitmask -> Bitmask -> CollisionFilter
[filterGroup] :: CollisionFilter -> CollisionGroup
[filterCategories] :: CollisionFilter -> Bitmask
[filterMask] :: CollisionFilter -> Bitmask

-- | A bitmask used for collision handling
newtype Bitmask
Bitmask :: CUInt -> Bitmask
maskAll :: Bitmask
maskNone :: Bitmask

-- | Makes a bitmask from a list of indices
maskList :: [Int] -> Bitmask
defaultFilter :: CollisionFilter

-- | A box with the given height, width, and center point
boxShape :: Double -> Double -> Vec -> Convex
data Constraint
Constraint :: Entity -> Entity -> ConstraintType -> Constraint
data ConstraintType

-- | Maintains a fixed distance between two anchor points
PinJoint :: BVec -> BVec -> ConstraintType

-- | A <tt>PinJoint</tt> with minimum and maximum distance
SlideJoint :: BVec -> BVec -> Double -> Double -> ConstraintType

-- | Creates a pivot point at the given world coordinate
PivotJoint :: WVec -> ConstraintType

-- | Creates a pivot point at the given body coordinates
PivotJoint2 :: BVec -> BVec -> ConstraintType

-- | The first two vectors are the start and end of the groove on body A,
--   the third argument is the anchor point on body B.
GrooveJoint :: BVec -> BVec -> BVec -> ConstraintType

-- | Spring between two anchor points, with given rest length, stiffness,
--   and damping.
DampedSpring :: BVec -> BVec -> Double -> Double -> Double -> ConstraintType

-- | Rotary sping, with given rest angle, stiffness, and damping.
DampedRotarySpring :: Double -> Double -> Double -> ConstraintType

-- | Joint with minimum and maximum angle
RotaryLimitJoint :: Double -> Double -> ConstraintType

-- | Rathet joint with given phase and ratchet (distance between clicks).
RatchetJoint :: Double -> Double -> ConstraintType
GearJoint :: Double -> Double -> ConstraintType

-- | Keeps relative angular velocity constant
SimpleMotor :: Double -> ConstraintType
newtype MaxForce
MaxForce :: Double -> MaxForce
newtype MaxBias
MaxBias :: Double -> MaxBias
newtype ErrorBias
ErrorBias :: Double -> ErrorBias
newtype CollideBodies
CollideBodies :: Bool -> CollideBodies
data Collision
Collision :: Vec -> Entity -> Entity -> Collision
[collisionNormal] :: Collision -> Vec
[collisionA] :: Collision -> Entity
[collisionB] :: Collision -> Entity
data CollisionHandler
CollisionHandler :: CollisionSource -> Maybe BeginCB -> Maybe SeparateCB -> Maybe PreSolveCB -> Maybe PostSolveCB -> CollisionHandler
[source] :: CollisionHandler -> CollisionSource

-- | A callback called when two bodies start touching for the first time.
--   If it returns <a>True</a>, the physics engine will process the
--   collision normally. If it returns <a>False</a>, the physics engine
--   will <b>ignore the collision entirely</b>.
[beginCB] :: CollisionHandler -> Maybe BeginCB

-- | A callback called when two bodies have just stopped touching. This
--   will <b>always</b> be called if <a>beginCB</a> is, regardless of the
--   return value of <a>beginCB</a>.
[separateCB] :: CollisionHandler -> Maybe SeparateCB

-- | A callback called when two bodies are touching during a physics step.
--   If this function returns <a>True</a>, the collision will be processed
--   normally. If it returns 'False, then the physics engine will stop
--   processing the collision for this step.
[preSolveCB] :: CollisionHandler -> Maybe PreSolveCB

-- | A callback called when two bodies are touching <b>after</b> the
--   response to the collision has been processed. This means that you can
--   determine the collision impulse or kinetic energy in this callback, if
--   you need that for processing.
[postSolveCB] :: CollisionHandler -> Maybe PostSolveCB
defaultHandler :: CollisionHandler
data CollisionSource
Wildcard :: CollisionGroup -> CollisionSource
Between :: CollisionGroup -> CollisionGroup -> CollisionSource
data BeginCB
data SeparateCB
data PreSolveCB
data PostSolveCB
mkBeginCB :: (Collision -> System w Bool) -> System w BeginCB
mkSeparateCB :: (Collision -> System w ()) -> System w SeparateCB
mkPreSolveCB :: (Collision -> System w Bool) -> System w PreSolveCB
mkPostSolveCB :: (Collision -> System w ()) -> System w PostSolveCB
data PointQueryResult
PointQueryResult :: Entity -> WVec -> Double -> Double -> PointQueryResult

-- | What entity did this query connect with?
[pqShape] :: PointQueryResult -> Entity

-- | The closest point on the shape's surface (in world space)
[pqPoint] :: PointQueryResult -> WVec

-- | The distance to the queried point
[pqDistance] :: PointQueryResult -> Double

-- | The gradient of the distance function. This is equal to
--   'pqPoint'/'pqDistance' but accurate for even very small distances.
[pqGradient] :: PointQueryResult -> Double
pointQuery :: Has w IO Physics => WVec -> Double -> CollisionFilter -> System w (Maybe PointQueryResult)
vertices :: Convex -> [BVec]

-- | Map a function over all vertices
mapVertices :: (BVec -> BVec) -> Convex -> Convex

-- | Translates all vertices. The name shift is to prevent collisions with
--   gloss
shift :: BVec -> Convex -> Convex
getRadius :: Convex -> Double
setRadius :: Double -> Convex -> Convex
cCircle :: Double -> Convex
zCircle :: Double -> Convex
oCircle :: BVec -> Double -> Convex
hLine :: Double -> Convex
vLine :: Double -> Convex

-- | Centered rectangle with a given size
cRectangle :: BVec -> Convex

-- | Rectangle with a given origin and size
oRectangle :: BVec -> BVec -> Convex

-- | Rectangle with origin 0 and given size
zRectangle :: BVec -> Convex

-- | Split a shape into its edges. Will return no edges for points, but
--   returns 2 for a line (in opposite directions)
toEdges :: Convex -> [Convex]

-- | A set of lines forming a grid. Returns (r + c + 2) segments.
gridLines :: Vec -> Int -> Int -> [Convex]

-- | Type synonym indicating that a vector is expected to be in body-space
--   coordinates
type BVec = Vec

-- | Type synonym indicating that a vector is expected to be in world-space
--   coordinates
type WVec = Vec
