-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell bindings for Chipmunk2D physics engine -- -- Please see the README on GitHub at -- https://github.com/CthulhuDen/chiphunk#readme @package chiphunk @version 0.1.1.0 -- | Chiphunk is a low-level Haskell bindings for the Chipmunk2D -- physics engine. It includes most (almost all) of the functions -- mentioned in the main documentation for Chipmunk2D, except for some -- (relatively) exotic ones, which may be added later per request. module Chiphunk.Low -- | Clamp f to be between min and max fClamp :: Double -> Double -> Double -> Double -- | Linearly interpolate between f1 and f2 fLerp :: Double -> Double -> Double -> Double -- | Linearly interpolate from f1 towards f2 by no more -- than d. fLerpConst :: Double -> Double -> Double -> Double -- | 2D vector packed into a struct. data Vect Vect :: !Double -> !Double -> Vect [vX] :: Vect -> !Double [vY] :: Vect -> !Double -- | Constant for the zero vector. -- -- Alias for zeroV vZero :: Vect -- | Convenience constructor for creating new cpVect structs. Alias for -- Vect cpv :: Double -> Double -> Vect -- | Check if two vectors are equal. (Be careful when comparing floating -- point numbers!) -- -- Alias for ==. vEql :: Vect -> Vect -> Bool -- | Add two vectors. -- -- Alias for ^+^. vAdd :: Vect -> Vect -> Vect -- | Subtract two vectors. -- -- Alias for ^-^. vSub :: Vect -> Vect -> Vect -- | Negate a vector. -- -- Alias for negateV. vNeg :: Vect -> Vect -- | Scalar multiplication. -- -- Alias for ^*. vMult :: Vect -> Double -> Vect -- | Vector dot product. -- -- Alias for <.>. vDot :: Vect -> Vect -> Double -- | 2D vector cross product analog. The cross product of 2D vectors -- results in a 3D vector with only a z component. This function returns -- the value along the z-axis. vCross :: Vect -> Vect -> Double -- | Returns a perpendicular vector. (90 degree rotation) -- -- Alias for cross2. vPerp :: Vect -> Vect -- | Returns a perpendicular vector. (-90 degree rotation) vRPerp :: Vect -> Vect -- | Returns the vector projection of v1 onto v2. -- -- Alias for project. vProject :: Vect -> Vect -> Vect -- | Uses complex multiplication to rotate v1 by v2. -- Scaling will occur if v1 is not a unit vector. vRotate :: Vect -> Vect -> Vect -- | Inverse of vRotate. vUnRotate :: Vect -> Vect -> Vect -- | Returns the length of v. -- -- Alias for magnitude. vLength :: Vect -> Double -- | Returns the squared length of v. Faster than vLength -- when you only need to compare lengths. -- -- Alias for magnitudeSq. vLengthSq :: Vect -> Double -- | Linearly interpolate between v1 and v2. -- -- Alias for lerp. vLerp :: Vect -> Vect -> Double -> Vect -- | Linearly interpolate between v1 towards v2 by -- distance d. vLerpConst :: Vect -> Vect -> Double -> Vect -- | Spherical linearly interpolate between v1 and v2. vSLerp :: Vect -> Vect -> Double -> Vect -- | Spherical linearly interpolate between v1 towards v2 -- by no more than angle a in radians. vSLerpConst :: Vect -> Vect -> Double -> Vect -- | Returns a normalized copy of v. As a special case, it returns -- vZero when called on vZero. -- -- Alias for normalized. vNormalize :: Vect -> Vect -- | Clamp v to length len. vClamp :: Vect -> Double -> Vect -- | Returns the distance between v1 and v2. vDist :: Vect -> Vect -> Double -- | Returns the squared distance between v1 and v2. -- Faster than vDist when you only need to compare distances. vDistSq :: Vect -> Vect -> Double -- | Returns true if the distance between v1 and v2 is -- less than dist. vNear :: Vect -> Vect -> Double -> Bool -- | Returns the unit length vector for the given angle (in radians). vForAngle :: Double -> Vect -- | Returns the angular direction v is pointing in (in radians). vToAngle :: Vect -> Double -- | Simple bounding box struct. Stored as left, bottom, right, top values. data BB BB :: !Double -> !Double -> !Double -> !Double -> BB [bbL] :: BB -> !Double [bbB] :: BB -> !Double [bbR] :: BB -> !Double [bbT] :: BB -> !Double -- | Convenience constructor for BB structs. bbNew :: Double -> Double -> Double -> Double -> BB -- | Convenience constructor for making a BB fitting with a center -- point and half width and height. bbNewForExtents :: Vect -> Double -> Double -> BB -- | Convenience constructor for making a BB fitting a circle at -- position p with radius r. bbNewForCircle :: Vect -> Double -> BB -- | Returns true if the bounding boxes intersect. bbIntersects :: BB -> BB -> Bool -- | Returns true if bb completely contains other. bbContainsBB :: BB -> BB -> Bool -- | Returns true if bb contains v. bbContainsVect :: BB -> Vect -> Bool -- | Return the minimal bounding box that contains both a and -- b. bbMerge :: BB -> BB -> BB -- | Return the minimal bounding box that contains both bb and -- v. bbExpand :: BB -> Vect -> BB -- | Return the center of bb. bbCenter :: BB -> Vect -- | Return the area of bb. bbArea :: BB -> Double -- | Merges a and b then returns the area of the merged -- bounding box. bbMergedArea :: BB -> BB -> Double -- | Returns the fraction along the segment query the BB is hit. -- Returns INFINITY if it doesn’t hit. bbSegmentQuery :: BB -> Vect -> Vect -> Double -- | Returns true if the segment defined by endpoints a and -- b intersect bb. bbIntersectsSegment :: BB -> Vect -> Vect -> Bool -- | Returns a copy of v clamped to the bounding box bb. bbClampVect :: BB -> Vect -> Vect -- | Returns a copy of v wrapped to the bounding box bb. bbWrapVect :: BB -> Vect -> Vect -- | Rigid body somewhere in C code. data Body -- | Chipmunk supports three different types of bodies with unique -- behavioral and performance characteristics. data BodyType -- | Dynamic bodies are the default body type. They react to collisions, -- are affected by forces and gravity, and have a finite amount of mass. -- These are the type of bodies that you want the physics engine to -- simulate for you. Dynamic bodies interact with all types of bodies and -- can generate collision callbacks. BodyTypeDynamic :: BodyType -- | Kinematic bodies are bodies that are controlled from your code instead -- of inside the physics engine. They arent affected by gravity and they -- have an infinite amount of mass so they don’t react to collisions or -- forces with other bodies. Kinematic bodies are controlled by setting -- their velocity, which will cause them to move. Good examples of -- kinematic bodies might include things like moving platforms. Objects -- that are touching or jointed to a kinematic body are never allowed to -- fall asleep. BodyTypeKimenatic :: BodyType -- | Static bodies are bodies that never (or rarely) move. Using static -- bodies for things like terrain offers a big performance boost over -- other body types — because Chipmunk doesn’t need to check for -- collisions between static objects and it never needs to update their -- collision information. Additionally, because static bodies don’t move, -- Chipmunk knows it’s safe to let objects that are touching or jointed -- to them fall asleep. Generally all of your level geometry will be -- attached to a static body except for things like moving platforms or -- doors. Every space provide a built-in static body for your -- convenience. Static bodies can be moved, but there is a performance -- penalty as the collision information is recalculated. There is no -- penalty for having multiple static bodies, and it can be useful for -- simplifying your code by allowing different parts of your static -- geometry to be initialized or moved separately. BodyTypeStatic :: BodyType -- | Creates body of type BodyTypeDynamic. bodyNew :: Double -> Double -> IO Body -- | Create body of type BodyTypeKimenatic. bodyNewKinematic :: IO Body -- | Create body of type BodyTypeStatic. bodyNewStatic :: IO Body -- | Be careful not to free a body before any shapes or constraints -- attached to it have been removed from a space. bodyFree :: Body -> IO () -- | Type of a body (dynamic, kinematic, static). When changing an body to -- a dynamic body, the mass and moment of inertia are recalculated from -- the shapes added to the body. Custom calculated moments of inertia are -- not preseved when changing types. This function cannot be called -- directly in a collision callback. bodyType :: Body -> StateVar BodyType -- | Mass of the body. bodyMass :: Body -> StateVar Double -- | Moment of inertia (MoI or sometimes just moment) of the body. The -- moment is like the rotational mass of a body. See below for function -- to help calculate the moment. bodyMoment :: Body -> StateVar Double -- | Position of the body. When changing the position you may also want to -- call spaceReindexShapesForBody to update the collision -- detection information for the attached shapes if plan to make any -- queries against the space. bodyPosition :: Body -> StateVar Vect -- | Location of the center of gravity in body local coordinates. The -- default value is (0, 0), meaning the center of gravity is the same as -- the position of the body. bodyCenterOfGravity :: Body -> StateVar Vect -- | Linear velocity of the center of gravity of the body. bodyVelocity :: Body -> StateVar Vect -- | Force applied to the center of gravity of the body. This value is -- reset for every time step. bodyForce :: Body -> StateVar Vect -- | Set rotation of the body in radians. When changing the rotation you -- may also want to call spaceReindexShapesForBody to update the -- collision detection information for the attached shapes if you plan to -- make any queries against the space. A body rotates around its center -- of gravity, not its position. bodyAngle :: Body -> StateVar Double -- | Angular velocity of the body in radians per second. bodyAngularVelocity :: Body -> StateVar Double -- | Torque applied to the body. This value is reset for every time step. bodyTorque :: Body -> StateVar Double -- | The rotation vector for the body. Can be used with vRotate or -- vUnRotate to perform fast rotations. bodyRotation :: Body -> GettableStateVar Vect -- | The Space that body has been added to. bodySpace :: Body -> GettableStateVar Space -- | User data pointer. Use this pointer to get a reference to the game -- object that owns this body from callbacks. bodyUserData :: Body -> StateVar DataPtr -- | Calculate the moment of inertia for a hollow circle, r1 and -- r2 are the inner and outer diameters in no particular order. -- (A solid circle has an inner diameter of 0) momentForCircle :: Double -> Double -> Double -> Vect -> Double -- | Calculate the moment of inertia for a line segment. The endpoints -- a and b are relative to the body. momentForSegment :: Double -> Vect -> Vect -> Double -> Double -- | Calculate the moment of inertia for a solid polygon shape assuming its -- center of gravity is at its centroid. The offset is added to each -- vertex. momentForPoly :: Double -> [Vect] -> Vect -> Double -> Double -- | Calculate the moment of inertia for a solid box centered on the body. momentForBox :: Double -> Double -> Double -> Double -- | Area of a hollow circle. areaForCircle :: Double -> Double -> Double -- | Area of a beveled segment. (Will always be zero if radius is zero) areaForSegment :: Vect -> Vect -> Double -> Double -- | Signed area of a polygon shape. Returns a negative number for polygons -- with a clockwise winding. areaForPoly :: [Vect] -> Double -> Double -- | Convert from body local coordinates to world space coordinates. bodyLocalToWorld :: Body -> Vect -> IO Vect -- | Convert from world space coordinates to body local coordinates. bodyWorldToLocal :: Body -> Vect -> IO Vect -- | Absolute velocity of the rigid body at the given world point. bodyVelocityAtWorldPoint :: Body -> Vect -> GettableStateVar Vect -- | Add the force to body as if applied from the world -- point. bodyApplyForceAtWorldPoint :: Body -> Vect -> Vect -> IO () -- | Add the local force to body as if applied from the -- body local point. bodyApplyForceAtLocalPoint :: Body -> Vect -> Vect -> IO () -- | Add the impulse to body as if applied from the world -- point. bodyApplyImpulseAtWorldPoint :: Body -> Vect -> Vect -> IO () -- | Add the local impulse to body as if applied from the -- body local point. bodyApplyImpulseAtLocalPoint :: Body -> Vect -> Vect -> IO () -- | Returns true if body is sleeping. bodyIsSleeping :: Body -> IO Bool -- | Reset the idle timer on a body. If it was sleeping, wake it and any -- other bodies it was touching. bodyActivate :: Body -> IO () -- | Forces a body to fall asleep immediately even if it’s in midair. -- Cannot be called from a callback. bodySleep :: Body -> IO () -- | Activates all bodies touching body. If filter is not -- nullPtr, then only bodies touching through filter will -- be awoken. bodyActivateStatic :: Body -> Shape -> IO () -- | When objects in Chipmunk sleep, they sleep as a group of all objects -- that are touching or jointed together. When an object is woken up, all -- of the objects in its group are woken up. bodySleepWithGroup -- allows you group sleeping objects together. It acts identically to -- bodySleep if you pass nullPtr as group by -- starting a new group. If you pass a sleeping body for group, -- body will be awoken when group is awoken. You can use this to -- initialize levels and start stacks of objects in a pre-sleeping state. bodySleepWithGroup :: Body -> Body -> IO () -- | Type of callback which can be used to iterate all Shapes in a -- Body. type BodyShapeIteratorFunc = Body -> Shape -> Ptr () -> IO () -- | Call func once for each shape that is attached to -- body and added to a space. data is passed along as a -- context value. It is safe to remove shapes using these callbacks. bodyEachShape :: Body -> BodyShapeIteratorFunc -> Ptr () -> IO () -- | Type of callback which can be used to iterate all Constraints -- in a Body. type BodyConstraintIteratorFunc = Body -> Constraint -> Ptr () -> IO () -- | Call func once for each constraint that is attached to -- body and added to a space. data is passed along as a -- context value. It is safe to remove constraints using thes callbacks. bodyEachConstraint :: Body -> BodyConstraintIteratorFunc -> Ptr () -> IO () -- | Type of callback which can be used to iterate all Arbiters in a -- Body. type BodyArbiterIteratorFunc = Body -> Arbiter -> Ptr () -> IO () -- | This one is more interesting. Calls func once for each -- collision pair that body is involved in. Calling -- 'arbiterGetBodies'/'arbiterGetShapes' will return the body or shape -- for body as the first argument. You can use this to check all sorts of -- collision information for a body like if it’s touching the ground, -- another particular object, how much collision force is being applied -- to an object, etc. -- -- Sensor shapes and arbiters that have been rejected by a collision -- handler callback or arbiterIgnore are not tracked by the -- contact graph. bodyEachArbiter :: Body -> BodyArbiterIteratorFunc -> Ptr () -> IO () -- | There are currently 3 collision shape types: -- -- -- -- You can add as many shapes to a body as you wish. That is why the two -- types are separate. -- -- Combining multiple shapes gives you the flexibility to make any object -- you want as well as providing different areas of the same object with -- different friction, elasticity or callback values. data Shape -- | The rigid body the shape is attached to. Can only be set when the -- shape is not added to a space. shapeBody :: Shape -> StateVar Body -- | The bounding box of the shape. Only guaranteed to be valid after -- shapeCacheBB or spaceStep is called. Moving a body -- that a shape is connected to does not update its bounding box. For -- shapes used for queries that aren’t attached to bodies, you can also -- use shapeUpdate. shapeBB :: Shape -> GettableStateVar BB -- | A boolean value if this shape is a sensor or not. Sensors only call -- collision callbacks, and never generate real collisions. shapeSensor :: Shape -> StateVar Bool -- | Elasticity of the shape. A value of 0.0 gives no bounce, while a value -- of 1.0 will give a “perfect” bounce. However due to inaccuracies in -- the simulation using 1.0 or greater is not recommended however. -- -- The elasticity for a collision is found by multiplying the elasticity -- of the individual shapes together. shapeElasticity :: Shape -> StateVar Double -- | Friction coefficient. Chipmunk uses the Coulomb friction model, a -- value of 0.0 is frictionless. -- -- The friction for a collision is found by multiplying the friction of -- the individual shapes together. Table of friction coefficients. shapeFriction :: Shape -> StateVar Double -- | The surface velocity of the object. Useful for creating conveyor belts -- or players that move around. This value is only used when calculating -- friction, not resolving the collision. shapeSurfaceVelocity :: Shape -> StateVar Vect -- | Collision type of this shape. | You can assign types to Chipmunk -- collision shapes that trigger callbacks when objects of certain types -- touch. See the callbacks section for more information. shapeCollisionType :: Shape -> StateVar CollisionType -- | Fast collision filtering type that is used to determine if two objects -- collide before calling collision or query callbacks. data ShapeFilter ShapeFilter :: !WordPtr -> !Word32 -> !Word32 -> ShapeFilter [sfGroup] :: ShapeFilter -> !WordPtr [sfCategories] :: ShapeFilter -> !Word32 [sfMask] :: ShapeFilter -> !Word32 -- | The collision filter for this shape. See Filtering Collisions for more -- information. shapeFilter :: Shape -> StateVar ShapeFilter -- | The Space that shape has been added to. shapeSpace :: Shape -> GettableStateVar Space -- | A user definable data pointer. If you set this to point at the game -- object the shapes is for, then you can access your game object from -- Chipmunk callbacks. shapeUserData :: Shape -> StateVar DataPtr -- | Deallocates shape. shapeFree :: Shape -> IO () -- | Synchronizes shape with the body its attached to. shapeCacheBB :: Shape -> IO BB -- | Sets the position and rotation of the shape shapeUpdate :: Shape -> Transform -> IO BB -- | Create new circle-like shape. circleShapeNew :: Body -> Double -> Vect -> IO Shape -- | Create new segment-shaped shape. segmentShapeNew :: Body -> Vect -> Vect -> Double -> IO Shape -- | When you have a number of segment shapes that are all joined together, -- things can still collide with the “cracks” between the segments. By -- setting the neighbor segment endpoints you can tell Chipmunk to avoid -- colliding with the inner parts of the crack. segmentShapeNeighbors :: Shape -> SettableStateVar (Vect, Vect) -- | A convex hull will be calculated from the vertexes automatically. The -- polygon shape will be created with a radius, increasing the size of -- the shape. polyShapeNew :: Body -> [Vect] -> Transform -> Double -> IO Shape -- | Alternate constructors for poly shapes. This version does not apply a -- transform nor does it create a convex hull. Verticies must be provided -- with a counter-clockwise winding. polyShapeNewRaw :: Body -> [Vect] -> Double -> IO Shape -- | Createa box shape from dimensions. boxShapeNew :: Body -> Double -> Double -> Double -> IO Shape -- | Alternative to boxShapeNew using BB to set size. boxShapeNew2 :: Body -> BB -> Double -> IO Shape -- | Calculate the centroid for a polygon. centroidForPoly :: [Vect] -> Vect -- | Calculate the convex hull of a given set of points. convexHull :: [Vect] -> Double -> ([Vect], Int) -- | Spaces in Chipmunk are the basic unit of simulation. You add rigid -- bodies, shapes, and constraints to the space and then step them all -- forward through time together. data Space -- | Iterations allow you to control the accuracy of the solver. Defaults -- to 10. See above for more information. spaceIterations :: Space -> StateVar Int -- | Global gravity applied to the space. Defaults to vZero. Can be -- overridden on a per body basis by writing custom integration -- functions. Changing the gravity will activate all sleeping bodies in -- the space. spaceGravity :: Space -> StateVar Vect -- | Amount of simple damping to apply to the space. A value of 0.9 means -- that each body will lose 10% of its velocity per second. Defaults to -- 1. Like gravity, it can be overridden on a per body basis. spaceDamping :: Space -> StateVar Double -- | Speed threshold for a body to be considered idle. The default value of -- 0 means the space estimates a good threshold based on gravity. spaceIdleSpeedThreshold :: Space -> StateVar Double -- | Time a group of bodies must remain idle in order to fall asleep. The -- default value of INFINITY disables the sleeping feature. spaceSleepTimeThreshold :: Space -> StateVar Double -- | Amount of overlap between shapes that is allowed. To improve -- stability, set this as high as you can without noticable overlapping. -- It defaults to 0.1. spaceCollisionSlop :: Space -> StateVar Double -- | Chipmunk allows fast moving objects to overlap, then fixes the overlap -- over time. Overlapping objects are unavoidable even if swept -- collisions are supported, and this is an efficient and stable way to -- deal with overlapping objects. The bias value controls what percentage -- of overlap remains unfixed after a second and defaults to ~0.2%. -- -- Valid values are in the range from 0 to 1, but using 0 is not -- recommended for stability reasons. -- -- The default value is calculated as (1.0 - 0.1) ^ 60 meaning -- that Chipmunk attempts to correct 10% of error ever 1/60th of a -- second. -- -- Note: Very very few games will need to change this value. spaceCollisionBias :: Space -> StateVar Double -- | The number of frames the space keeps collision solutions around for. -- Helps prevent jittering contacts from getting worse. This defaults to -- 3 and very very very few games will need to change this value. spaceCollisionPersistence :: Space -> StateVar Word32 -- | The current (if you are in a callback from spaceStep) or most -- recent (outside of a spaceStep call) timestep. spaceCurrentTimeStep :: Space -> GettableStateVar Double -- | Returns true when you cannot add/remove objects from the space. In -- particular, spaces are locked when in a collision callback. Instead, -- run your code in a post-step callback instead. spaceIsLocked :: Space -> IO Bool -- | A user definable data pointer. It is often useful to point this at the -- gamestate object or scene management object that owns the space. spaceUserData :: Space -> StateVar DataPtr -- | A dedicated static body for the space. You don’t have to use it, but -- because its memory is managed automatically with the space its very -- convenient. You can set its user data pointer to something helpful if -- you want for callbacks. spaceStaticBody :: Space -> GettableStateVar Body -- | Standard Chipmunk allocation function. spaceNew :: IO Space -- | Standard Chipmunk deallocation function. spaceFree :: Space -> IO () -- | Add shape to the space. spaceAddShape :: Space -> Shape -> IO () -- | Add body to the space. spaceAddBody :: Space -> Body -> IO () -- | Add constraint to the space. spaceAddConstraint :: Space -> Constraint -> IO () -- | Remove shape from the space. spaceRemoveShape :: Space -> Shape -> IO () -- | Remove body from the space. spaceRemoveBody :: Space -> Body -> IO () -- | Remove constraint from the space. spaceRemoveConstraint :: Space -> Constraint -> IO () -- | Check if shape is attached to the space. spaceContainsShape :: Space -> Shape -> IO Bool -- | Check if body is attached to the space. spaceContainsBody :: Space -> Body -> IO Bool -- | Check if constraint is attached to the space. spaceContainsConstraint :: Space -> Constraint -> IO Bool -- | Reindex a specific shape. spaceReindexShape :: Space -> Shape -> IO () -- | Reindex all the shapes for a certain body. spaceReindexShapesForBody :: Space -> Body -> IO () -- | Reindex all static shapes. Generally updating only the shapes that -- changed is faster. spaceReindexStatic :: Space -> IO () -- | Type of callback which can be used to iterate all Bodys in a -- Space. type SpaceBodyIteratorFunc = Body -> Ptr () -> IO () -- | Call func for each body in the space also passing -- along your data pointer. Sleeping bodies are included, but -- static and kinematic bodies are not as they aren’t added to the space. spaceEachBody :: Space -> SpaceBodyIteratorFunc -> Ptr () -> IO () -- | Type of callback which can be used to iterate all Shapes in a -- Space. type SpaceShapeIteratorFunc = Shape -> Ptr () -> IO () -- | Call func for each shape in the space also passing -- along your data pointer. Sleeping and static shapes are -- included. spaceEachShape :: Space -> SpaceShapeIteratorFunc -> Ptr () -> IO () -- | Type of callback which can be used to iterate all Constraints -- in a Space. type SpaceConstraintIteratorFunc = Constraint -> Ptr () -> IO () -- | Call func for each constraint in the space also passing along your -- data pointer. spaceEachConstraint :: Space -> SpaceConstraintIteratorFunc -> Ptr () -> IO () -- | Update the space for the given time step. Using a fixed time step is -- highly recommended. Doing so can greatly increase the quality of the -- simulation. The easiest way to do constant timesteps is to simple step -- forward by 1/60th of a second (or whatever your target framerate is) -- for each frame regardless of how long it took to render. This works -- fine for many games, but a better way to do it is to separate your -- physics timestep and rendering. spaceStep :: Space -> Double -> IO () -- | A constraint is something that describes how two bodies interact with -- each other. (how they constrain each other) Constraints can be simple -- joints that allow bodies to pivot around each other like the bones in -- your body, or they can be more abstract like the gear joint or motors. data Constraint -- | The first body constraint is attached to constraintBodyA :: Constraint -> GettableStateVar Body -- | The second body constraint is attached to constraintBodyB :: Constraint -> GettableStateVar Body -- | The maximum force that the constraint can use to act on the two -- bodies. Defaults to INFINITY. constraintMaxForce :: Constraint -> StateVar Double -- | The percentage of joint error that remains unfixed after a second. -- This works exactly the same as the collision bias property of a space, -- but applies to fixing error (stretching) of joints instead of -- overlapping collisions. constraintErrorBias :: Constraint -> StateVar Double -- | Get the maximum speed at which the constraint can apply error -- correction. Defaults to INFINITY. constraintMaxBias :: Constraint -> StateVar Double -- | The Space that constraint has been added to. constraintSpace :: Constraint -> GettableStateVar Space -- | Constraints can be used for filtering collisions too. When two bodies -- collide, Chipmunk ignores the collisions if this property is set to -- False on any constraint that connects the two bodies. -- Defaults to True. -- -- This can be used to create a chain that self collides, but adjacent -- links in the chain do not collide. constraintCollideBodies :: Constraint -> StateVar Bool -- | A user definable data pointer. Use this pointer to get a reference to -- the game object that owns this constraint from callbacks. constraintUserData :: Constraint -> StateVar DataPtr -- | The most recent impulse that constraint applied. To convert this to a -- force, divide by the timestep passed to spaceStep. You can -- use this to implement breakable joints to check if the force they -- attempted to apply exceeded a certain threshold. constraintImpulse :: Constraint -> GettableStateVar Double -- | Free function is shared by all joint types. Allocation functions are -- specific to each joint type. constraintFree :: Constraint -> IO () -- | Connect two bodies via anchor points on those bodies. The distance -- between the two anchor points is measured when the joint is created. -- If you want to set a specific distance, use the setter function to -- override it. pinJointNew :: Body -> Body -> Vect -> Vect -> IO Constraint -- | Anchor on first body. pinJointAnchorA :: Constraint -> StateVar Vect -- | Anchor on second body. pinJointAnchorB :: Constraint -> StateVar Vect -- | Desired distance the joint will try to enforce. pinJointDist :: Constraint -> StateVar Double -- | Connect two bodies via anchor points forcing distance to remain in -- range. slideJointNew :: Body -> Body -> Vect -> Vect -> Double -> Double -> IO Constraint -- | Anchor on first body. slideJointAnchorA :: Constraint -> StateVar Vect -- | Anchor on second body. slideJointAnchorB :: Constraint -> StateVar Vect -- | The minimum distance the joint will try to enforce. slideJointMin :: Constraint -> StateVar Double -- | The maximum distance the joint will try to enforce. slideJointMax :: Constraint -> StateVar Double -- | Because the pivot location is given in world coordinates, you must -- have the bodies moved into the correct positions already. pivotJointNew :: Body -> Body -> Vect -> IO Constraint -- | Alternatively you can specify the joint based on a pair of anchor -- points, but make sure you have the bodies in the right place as the -- joint will fix itself as soon as you start simulating the space. pivotJointNew2 :: Body -> Body -> Vect -> Vect -> IO Constraint -- | Anchor on first body. pivotJointAnchorA :: Constraint -> StateVar Vect -- | Anchor on second body. pivotJointAnchorB :: Constraint -> StateVar Vect -- | Pivot is attached to groove on first body and to anchor on the second. -- All coordinates are body local. grooveJointNew :: Body -> Body -> Vect -> Vect -> Vect -> IO Constraint -- | First endpoint of groove (on first body). grooveJointGrooveA :: Constraint -> StateVar Vect -- | Second endpoint of groove (on first body). grooveJointGrooveB :: Constraint -> StateVar Vect -- | Anchor on second body. grooveJointAnchorB :: Constraint -> StateVar Vect -- | Defined much like a slide joint. dampedSpringNew :: Body -> Body -> Vect -> Vect -> Double -> Double -> Double -> IO Constraint -- | Anchor on first body. dampedSpringAnchorA :: Constraint -> StateVar Vect -- | Anchor on second body. dampedSpringAnchorB :: Constraint -> StateVar Vect -- | Desired distance the spring will try to enforce. dampedSpringRestLength :: Constraint -> StateVar Double -- | Spring stiffness dampedSpringStiffness :: Constraint -> StateVar Double -- | Spring damping dampedSpringDamping :: Constraint -> StateVar Double -- | Create new damped rotary spring constraint dampedRotarySpringNew :: Body -> Body -> Double -> Double -> Double -> IO Constraint -- | Set desired angle in radians the spring will try to enforce. dampedRotarySpringRestAngle :: Constraint -> StateVar Double -- | Spring stiffness. dampedRotarySpringStiffness :: Constraint -> StateVar Double -- | Spring damping. dampedRotarySpringDamping :: Constraint -> StateVar Double -- | Create new rotation limiting joint rotaryLimitJointNew :: Body -> Body -> Double -> Double -> IO Constraint -- | Minimum angle in radians the joint will try to enforce. rotaryLimitJointMin :: Constraint -> StateVar Double -- | Maximum angle in radians the joint will try to enforce. rotaryLimitJointMax :: Constraint -> StateVar Double -- | Allocate and initialize a ratchet joint. ratchetJointNew :: Body -> Body -> Double -> Double -> IO Constraint -- | The angle of the current ratchet tooth. ratchetJointAngle :: Constraint -> StateVar Double -- | The phase offset of the ratchet. ratchetJointPhase :: Constraint -> StateVar Double -- | The angular distance of each ratchet. ratchetJointRatchet :: Constraint -> StateVar Double -- | Allocate and initialize a gear joint. gearJointNew :: Body -> Body -> Double -> Double -> IO Constraint -- | Phase offset of the ratchet. gearJointPhase :: Constraint -> StateVar Double -- | Ratio of the ratchet gearJointRatio :: Constraint -> StateVar Double -- | Allocate and initialize a simple motor. simpleMotorNew :: Body -> Body -> Double -> IO Constraint -- | Ratio of angular velocities. simpleMotorRate :: Constraint -> StateVar Double -- | Collision callback type CollisionCallback ret = Arbiter -> Space -> DataPtr -> IO ret -- | Collision type type CollisionType = WordPtr -- | This collision handler processes collisions between objects of type -- typeA and typeB. Fill the desired collision callback -- functions- they are documented above. A user definable context pointer -- userData is included for your convenience. This pointer is -- provided as an argument in each callback function. -- -- A collision handler is a set of 4 function callbacks for the different -- collision events that Chipmunk recognizes. data CollisionHandler CollisionHandler :: !CollisionType -> !CollisionType -> !FunPtr (CollisionCallback CPBool) -> !FunPtr (CollisionCallback CPBool) -> !FunPtr (CollisionCallback ()) -> !FunPtr (CollisionCallback ()) -> !DataPtr -> CollisionHandler -- | typeA [chTypeA] :: CollisionHandler -> !CollisionType -- | typeB [chTypeB] :: CollisionHandler -> !CollisionType -- | Two shapes just started touching for the first time this step. Return -- true from the callback to process the collision normally or false to -- cause Chipmunk to ignore the collision entirely. If you return false, -- the preSolve and postSolve callbacks will never be run, but you will -- still recieve a separate event when the shapes stop overlapping. [chBeginFunc] :: CollisionHandler -> !FunPtr (CollisionCallback CPBool) -- | Two shapes are touching during this step. Return false from the -- callback to make Chipmunk ignore the collision this step or true to -- process it normally. Additionally, you may override collision values -- using arbiterFriction, arbiterRestitution or -- arbiterSurfaceVelocity to provide custom friction, elasticity, -- or surface velocity values. See Arbiter for more info. [chPreSolveFunc] :: CollisionHandler -> !FunPtr (CollisionCallback CPBool) -- | Two shapes are touching and their collision response has been -- processed. You can retrieve the collision impulse or kinetic energy at -- this time if you want to use it to calculate sound volumes or damage -- amounts. See Arbiter for more info. [chPostSolveFunc] :: CollisionHandler -> !FunPtr (CollisionCallback ()) -- | Two shapes have just stopped touching for the first time this step. To -- ensure that begin/separate are always called in balanced pairs, it -- will also be called when removing a shape while its in contact with -- something or when deallocating the space. [chSeparateFunc] :: CollisionHandler -> !FunPtr (CollisionCallback ()) -- | userData [cpUserData] :: CollisionHandler -> !DataPtr -- | Pointer to collision handler type CollisionHandlerPtr = Ptr (CollisionHandler) -- | Add a CollisionHandler for specific collision type pair or -- return the existing handler for the type pair. Whenever shapes with -- collision types (cpShape.collision_type) a and b collide, this handler -- will be used to process the collision events. When a new collision -- handler is created, the callbacks will all be set to builtin callbacks -- that perform the default behavior (call the wildcard handlers, and -- accept all collisions). spaceAddCollisionHandler :: Space -> CollisionType -> CollisionType -> IO CollisionHandlerPtr -- | Add a wildcard collision handler for given collision type. This -- handler will be used any time an object with this type collides with -- another object, regardless of its type. A good example is a projectile -- that should be destroyed the first time it hits anything. There may be -- a specific collision handler and two wildcard handlers. It’s up to the -- specific handler to decide if and when to call the wildcard handlers -- and what to do with their return values. (See arbiterCallWildcard* -- below) When a new wildcard handler is created, the callbacks will all -- be set to builtin callbacks that perform the default behavior. (accept -- all collisions in begin and preSolve, or do nothing for postSolve and -- separate. spaceAddWildcardHandler :: Space -> CollisionType -> IO CollisionHandlerPtr -- | Return a reference to the default collision handler or that is used to -- process all collisions that don’t have a more specific handler. The -- default behavior for each of the callbacks is to call the wildcard -- handlers, ANDing their return values together if applicable. spaceAddDefaultCollisionHandler :: Space -> IO CollisionHandlerPtr -- | Use this helper function to modify collision handler. -- --
--   spaceAddCollisionHandler s t1 t2 >>= flip modifyColliionHandler (ch -> pure ch {chSeparateFunc = separateCollback})
--   
modifyCollisionHandler :: CollisionHandlerPtr -> (CollisionHandler -> IO CollisionHandler) -> IO () -- | Make callback. Need to free afterwards. mkCallback :: CollisionCallback () -> IO (FunPtr (CollisionCallback ())) -- | Make callback. Need to free afterwards. mkCallbackB :: CollisionCallback Bool -> IO (FunPtr (CollisionCallback CPBool)) -- | Function type used for postStep callbacks. space is the space -- the callback was registered on, obj is the pointer value you -- supplied as the key, and data is a user definable pointer you -- can use to pass in as a context value. type PostStepFunc = Space " space" -> Ptr () " obj" -> Ptr () " data" -> IO () -- | Add func to be called before spaceStep returns. -- key and data will be passed to your function. Only -- the first callback registered for any unique value of key -- will be recorded. -- -- It returns True if the callback is scheduled and False -- when the key has already been used. -- -- The behavior of adding a postStep callback from outside of a -- collision handler or query callback is undefined. spaceAddPostStepCallback :: Space -> PostStepFunc -> Ptr () -> Ptr () -> IO Bool -- | Chipmunk’s Arbiter struct encapsulates a pair of colliding -- shapes and all of the data about their collision. Arbiter is -- created when a collision starts, and persist until those shapes are no -- longer colliding. -- -- Why are they called arbiters? The short answer is that I kept using -- the word “arbitrates” to describe the way that collisions were -- resolved and then I saw that Box2D actually called them arbiters way -- back in 2006 when I was looking at its solver. An arbiter is like a -- judge, a person that has authority to settle disputes between two -- people. It was a fun, fitting name and was shorter to type than -- CollisionPair which I had been using. It was originally meant to be a -- private internal structure only, but evolved to be useful from -- callbacks. data Arbiter -- | The calculated elasticity for this collision pair. Setting the value -- in a preSolve() callback will override the value calculated by the -- space. The default calculation multiplies the elasticity of the two -- shapes together. arbiterRestitution :: Arbiter -> StateVar Double -- | The calculated friction for this collision pair. Setting the value in -- a preSolve() callback will override the value calculated by the space. -- The default calculation multiplies the friction of the two shapes -- together. arbiterFriction :: Arbiter -> StateVar Double -- | The calculated surface velocity for this collision pair. Setting the -- value in a preSolve() callback will override the value calculated by -- the space. The default calculation subtracts the surface velocity of -- the second shape from the first and then projects that onto the -- tangent of the collision. This is so that only friction is affected by -- default calculation. -- -- Using a custom calculation, you can make something that responds like -- a pinball bumper, or where the surface velocity is dependent on the -- location of the contact point. arbiterSurfaceVelocity :: Arbiter -> StateVar Vect -- | A user definable context pointer. The value will persist until just -- after the separate callback is called for the pair. -- -- Note: If you need to clean up this pointer, you should -- implement the separate callback to do it. Also be careful when -- destroying the space as there may be active collisions still. In order -- to trigger the separate callbacks and clean up your data, you’ll need -- to remove all the shapes from the space before disposing of it. This -- is something I’d suggest doing anyway. See -- ChipmunkDemo.c:ChipmunkDemoFreeSpaceChildren() for an example of how -- to do it easily. arbiterUserData :: Arbiter -> StateVar DataPtr -- | The number of contacts tracked by this arbiter. For the forseeable -- future, the maximum number of contacts will be two. arbiterCount :: Arbiter -> GettableStateVar Int -- | Collision normal in a specific point tracked by this collision. arbiterNormal :: Arbiter -> GettableStateVar Vect -- | Collision point of a specific point on first body. arbiterPointA :: Arbiter -> Int -> GettableStateVar Vect -- | Collision point of a specific point on second body. arbiterPointB :: Arbiter -> Int -> GettableStateVar Vect -- | Penetration depth of a collision point. arbiterDepth :: Arbiter -> Int -> GettableStateVar Double -- | Returns true if this is the first step the two shapes started -- touching. This can be useful for sound effects for instance. If its -- the first frame for a certain collision, check the energy of the -- collision in a postStep callbock and use that to determine the volume -- of a sound effect to play. arbiterIsFirstContact :: Arbiter -> IO Bool -- | Returns True during a separate callback if the callback was -- invoked due to an object removal. arbiterIsRemoval :: Arbiter -> IO Bool -- | The colliding shapes in the order that they were defined in the -- collision handler associated with this arbiter. If you defined the -- handler as cpSpaceAddCollisionHandler(space, 1, 2, ...), you you will -- find that a->collision_type == 1 and b->collision_type == 2. arbiterShapes :: Arbiter -> GettableStateVar (Shape, Shape) -- | The colliding bodies in the order that they were defined in the -- collision handler associated with this arbiter. If you defined the -- handler as cpSpaceAddCollisionHandler(space, 1, 2, ...), you you will -- find that a->collision_type == 1 and b->collision_type == 2. arbiterBodies :: Arbiter -> GettableStateVar (Body, Body) -- | Run begin wildcard callback for first body. arbiterCallWildcardBeginA :: Arbiter -> Space -> IO Bool -- | Run begin wildcard callback for second body. arbiterCallWildcardBeginB :: Arbiter -> Space -> IO Bool -- | Run preSolve wildcard callback for first body. arbiterCallWildcardPreSolveA :: Arbiter -> Space -> IO Bool -- | Run preSolve wildcard callback for second body. arbiterCallWildcardPreSolveB :: Arbiter -> Space -> IO Bool -- | Run postSolve wildcard callback for first body. arbiterCallWildcardPostSolveA :: Arbiter -> Space -> IO () -- | Run postSolve wildcard callback for second body. arbiterCallWildcardPostSolveB :: Arbiter -> Space -> IO () -- | Run separate wildcard callback for first body. arbiterCallWildcardSeparateA :: Arbiter -> Space -> IO () -- | Run separate wildcard callback for second body. arbiterCallWildcardSeparateB :: Arbiter -> Space -> IO () -- | Pointer to user data. type DataPtr = Ptr (()) -- | Type used for 2×3 affine transforms in Chipmunk. data Transform Transform :: !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> Transform [tA] :: Transform -> !Double [tB] :: Transform -> !Double [tC] :: Transform -> !Double [tD] :: Transform -> !Double [tTx] :: Transform -> !Double [tTy] :: Transform -> !Double -- | The constant nullPtr contains a distinguished value of -- Ptr that is not associated with a valid memory location. nullPtr :: () => Ptr a -- | This is the class of all readable state variables. class HasGetter t a | t -> a get :: (HasGetter t a, MonadIO m) => t -> m a -- | This is the class of all writable state variables. class HasSetter t a | t -> a -- | Write a new value into a state variable. ($=) :: (HasSetter t a, MonadIO m) => t -> a -> m () infixr 2 $=