Safe Haskell | None |
---|---|
Language | Haskell2010 |
apecs-physics prelude
Synopsis
- data Physics
- newtype Gravity = Gravity Vec
- newtype Iterations = Iterations Int
- stepPhysics :: MonadIO m => Has w m Physics => Double -> SystemT w m ()
- earthGravity :: Gravity
- data Body
- newtype Position = Position WVec
- newtype Velocity = Velocity WVec
- newtype Angle = Angle Double
- newtype AngularVelocity = AngularVelocity Double
- newtype Force = Force Vec
- newtype BodyMass = BodyMass Double
- newtype Moment = Moment Double
- newtype CenterOfGravity = CenterOfGravity BVec
- newtype Torque = Torque Double
- newtype ShapeList = ShapeList [Entity]
- newtype ConstraintList = ConstraintList [Entity]
- data Convex = Convex [BVec] Double
- data Shape = Shape Entity Convex
- newtype Mass = Mass Double
- newtype Density = Density Double
- newtype Sensor = Sensor Bool
- newtype Friction = Friction Double
- newtype Elasticity = Elasticity Double
- newtype SurfaceVelocity = SurfaceVelocity Vec
- data CollisionFilter = CollisionFilter {
- filterGroup :: CollisionGroup
- filterCategories :: Bitmask
- filterMask :: Bitmask
- newtype CollisionType = CollisionType CUIntPtr
- newtype Bitmask = Bitmask CUInt
- maskAll :: Bitmask
- maskNone :: Bitmask
- maskList :: [Int] -> Bitmask
- defaultFilter :: CollisionFilter
- boxShape :: Double -> Double -> Vec -> Convex
- data Constraint = Constraint Entity Entity ConstraintType
- data ConstraintType
- = PinJoint BVec BVec
- | SlideJoint BVec BVec Double Double
- | PivotJoint WVec
- | PivotJoint2 BVec BVec
- | GrooveJoint BVec BVec BVec
- | DampedSpring BVec BVec Double Double Double
- | DampedRotarySpring Double Double Double
- | RotaryLimitJoint Double Double
- | RatchetJoint Double Double
- | GearJoint Double Double
- | SimpleMotor Double
- newtype MaxForce = MaxForce Double
- newtype MaxBias = MaxBias Double
- newtype ErrorBias = ErrorBias Double
- newtype Impulse = Impulse Double
- newtype CollideBodies = CollideBodies Bool
- data Collision = Collision {}
- data CollisionHandler = CollisionHandler {}
- defaultHandler :: CollisionHandler
- data CollisionSource
- data BeginCB
- data SeparateCB
- data PreSolveCB
- data PostSolveCB
- mkBeginCB :: MonadIO m => (Collision -> SystemT w IO Bool) -> SystemT w m BeginCB
- mkSeparateCB :: MonadIO m => (Collision -> SystemT w IO ()) -> SystemT w m SeparateCB
- mkPreSolveCB :: MonadIO m => (Collision -> SystemT w IO Bool) -> SystemT w m PreSolveCB
- mkPostSolveCB :: MonadIO m => (Collision -> SystemT w IO ()) -> SystemT w m PostSolveCB
- addPostStepCallback :: (Has w m Physics, MonadIO m) => Int -> SystemT w IO () -> SystemT w m ()
- data PointQueryResult = PointQueryResult {
- pqShape :: Entity
- pqPoint :: WVec
- pqDistance :: Double
- pqGradient :: Vec
- pointQuery :: (MonadIO m, Has w m Physics) => WVec -> Double -> CollisionFilter -> SystemT w m (Maybe PointQueryResult)
- vertices :: Convex -> [BVec]
- mapVertices :: (BVec -> BVec) -> Convex -> Convex
- 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
- cRectangle :: BVec -> Convex
- oRectangle :: BVec -> BVec -> Convex
- zRectangle :: BVec -> Convex
- toEdges :: Convex -> [Convex]
- gridLines :: Vec -> Int -> Int -> [Convex]
- type BVec = Vec
- type WVec = Vec
- module Apecs
- module Linear.V2
General
Uninhabited, should be added to the world as a component to add a physics space.
Space
Gravity force vector, global value
Gravity Vec |
newtype Iterations Source #
Number of iterations per step, global value
Instances
Eq Iterations Source # | |
Defined in Apecs.Physics.Types (==) :: Iterations -> Iterations -> Bool # (/=) :: Iterations -> Iterations -> Bool # | |
Show Iterations Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> Iterations -> ShowS # show :: Iterations -> String # showList :: [Iterations] -> ShowS # | |
Component Iterations Source # | |
Defined in Apecs.Physics.Space type Storage Iterations :: Type # | |
(MonadIO m, Has w m Physics) => Has w m Iterations Source # | |
Defined in Apecs.Physics.Space getStore :: SystemT w m (Storage Iterations) # | |
type Storage Iterations Source # | |
Defined in Apecs.Physics.Space |
Body
When you give an entity a
component in 'apecs-physics', the physics engine will
also give this entity a number of sub-components.
These sub-components may be read and written separately from the actualy Body
itself,
which makes the library both more expressive (as you can only write about the parts of a
physics body you actually want to view or change) and more performant
(as only the changed parts of a body actually need to be updated when you write to them).Body
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: Position
, Velocity
, Force
, Torque
, BodyMass
, Moment
, Angle
, AngularVelocity
, and CenterOfGravity
.
These components cannot be added or removed from an entity, but rather are present as long as the entity has a Body
.
A subcomponent of Body
representing where it is in world coordinates.
A subcomponent of Body
representing where it is going in world coordinates
newtype AngularVelocity Source #
Instances
Component AngularVelocity Source # | |
Defined in Apecs.Physics.Body type Storage AngularVelocity :: Type # | |
(MonadIO m, Has w m Physics) => Has w m AngularVelocity Source # | |
Defined in Apecs.Physics.Body getStore :: SystemT w m (Storage AngularVelocity) # | |
type Storage AngularVelocity Source # | |
Defined in Apecs.Physics.Body |
A component used to apply a force to a Body
.
The force is applied to the body's center of gravity.
This component is reset to Vec 0 0
after every stimulation step,
so it is mainly used to apply a force as opposed to being read.
Force Vec |
A component representing the mass of the Body
overall.
The moment of inertia of the Body
.
This is basically the body's tendency to resist angular acceleration.
newtype CenterOfGravity Source #
Where the Body
's center of gravity is, in body-local coordinates.
Can be read and written to.
Instances
Component CenterOfGravity Source # | |
Defined in Apecs.Physics.Body type Storage CenterOfGravity :: Type # | |
(MonadIO m, Has w m Physics) => Has w m CenterOfGravity Source # | |
Defined in Apecs.Physics.Body getStore :: SystemT w m (Storage CenterOfGravity) # | |
type Storage CenterOfGravity Source # | |
Defined in Apecs.Physics.Body |
A component used to apply a torque to a Body
.
The torque is applied to the entire body at once.
This component is reset to 0
after every simulation step, so it
is mainly used to apply a torque as opposed to being read.
The Shape
s belonging to a body. Read-only.
newtype ConstraintList Source #
The Constraint
s belonging to a body. Read-only.
Instances
Component ConstraintList Source # | |
Defined in Apecs.Physics.Body type Storage ConstraintList :: Type # | |
(MonadIO m, Has w m Physics) => Has w m ConstraintList Source # | |
Defined in Apecs.Physics.Body getStore :: SystemT w m (Storage ConstraintList) # | |
type Storage ConstraintList Source # | |
Defined in Apecs.Physics.Body |
Shape
A convex polygon. Consists of a list of vertices, and a radius.
Shape component.
Adding a shape to an entity that has no Body
is a noop.
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 Density
and other components
for you.
See https://en.wikipedia.org/wiki/Mass for more information.
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 Mass
and other components for you.
See https://en.wikipedia.org/wiki/Density for more information.
If a body is a Sensor
, it exists only to trigger collision responses.
It won't phyiscally interact with other bodies in any way, but it will
cause collision handlers to run.
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 https://en.wikipedia.org/wiki/Friction for more information.
newtype Elasticity Source #
The elasticity of a shape. Higher elasticities will create more elastic collisions, IE, will be bouncier.
See https://en.wikipedia.org/wiki/Elasticity_(physics) for more information.
Instances
Eq Elasticity Source # | |
Defined in Apecs.Physics.Types (==) :: Elasticity -> Elasticity -> Bool # (/=) :: Elasticity -> Elasticity -> Bool # | |
Show Elasticity Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> Elasticity -> ShowS # show :: Elasticity -> String # showList :: [Elasticity] -> ShowS # | |
Component Elasticity Source # | |
Defined in Apecs.Physics.Shape type Storage Elasticity :: Type # | |
(MonadIO m, Has w m Physics) => Has w m Elasticity Source # | |
Defined in Apecs.Physics.Shape getStore :: SystemT w m (Storage Elasticity) # | |
type Storage Elasticity Source # | |
Defined in Apecs.Physics.Shape |
newtype SurfaceVelocity Source #
SurfaceVelocity Vec |
Instances
Eq SurfaceVelocity Source # | |
Defined in Apecs.Physics.Types (==) :: SurfaceVelocity -> SurfaceVelocity -> Bool # (/=) :: SurfaceVelocity -> SurfaceVelocity -> Bool # | |
Show SurfaceVelocity Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> SurfaceVelocity -> ShowS # show :: SurfaceVelocity -> String # showList :: [SurfaceVelocity] -> ShowS # | |
Component SurfaceVelocity Source # | |
Defined in Apecs.Physics.Shape type Storage SurfaceVelocity :: Type # | |
(MonadIO m, Has w m Physics) => Has w m SurfaceVelocity Source # | |
Defined in Apecs.Physics.Shape getStore :: SystemT w m (Storage SurfaceVelocity) # | |
type Storage SurfaceVelocity Source # | |
Defined in Apecs.Physics.Shape |
data CollisionFilter Source #
Collision Filters determine what shapes this shape collides with.
Shapes in the same filterGroup
will never collide with one another.
This is used to ignore collisions between parts on a complex object.
filterCategories
is a bitmask that determines what categories a shape belongs to.
filterMask
is a bitmask that determines what categories it collides with.
See https://chipmunk-physics.net/release/ChipmunkLatest-Docs/#cpShape-Filtering for more information.
CollisionFilter | |
|
Instances
Eq CollisionFilter Source # | |
Defined in Apecs.Physics.Types (==) :: CollisionFilter -> CollisionFilter -> Bool # (/=) :: CollisionFilter -> CollisionFilter -> Bool # | |
Show CollisionFilter Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> CollisionFilter -> ShowS # show :: CollisionFilter -> String # showList :: [CollisionFilter] -> ShowS # | |
Component CollisionFilter Source # | |
Defined in Apecs.Physics.Shape type Storage CollisionFilter :: Type # | |
(MonadIO m, Has w m Physics) => Has w m CollisionFilter Source # | |
Defined in Apecs.Physics.Shape getStore :: SystemT w m (Storage CollisionFilter) # | |
type Storage CollisionFilter Source # | |
Defined in Apecs.Physics.Shape |
newtype CollisionType Source #
A Shape
can have a CollisionType
.
CollisionType
s are used by callbacks for filtering, also see CollisionSource
.
The difference between CollisionType
and CollisionFilter
is that a CollisionFilter
determines whether
two shapes in the physics engine collide, or pass through one another, whereas a CollisionType
determines
what callback is called.
In general, if you don't want any special checks to happen, use CollisionFilter
.
Instances
A bitmask used for collision handling
Instances
Eq Bitmask Source # | |
Show Bitmask Source # | |
Bits Bitmask Source # | |
Defined in Apecs.Physics.Types (.&.) :: Bitmask -> Bitmask -> Bitmask # (.|.) :: Bitmask -> Bitmask -> Bitmask # xor :: Bitmask -> Bitmask -> Bitmask # complement :: Bitmask -> Bitmask # shift :: Bitmask -> Int -> Bitmask # rotate :: Bitmask -> Int -> Bitmask # setBit :: Bitmask -> Int -> Bitmask # clearBit :: Bitmask -> Int -> Bitmask # complementBit :: Bitmask -> Int -> Bitmask # testBit :: Bitmask -> Int -> Bool # bitSizeMaybe :: Bitmask -> Maybe Int # shiftL :: Bitmask -> Int -> Bitmask # unsafeShiftL :: Bitmask -> Int -> Bitmask # shiftR :: Bitmask -> Int -> Bitmask # unsafeShiftR :: Bitmask -> Int -> Bitmask # rotateL :: Bitmask -> Int -> Bitmask # |
boxShape :: Double -> Double -> Vec -> Convex Source #
A box with the given height, width, and center point
Constraint
data Constraint Source #
Instances
Eq Constraint Source # | |
Defined in Apecs.Physics.Types (==) :: Constraint -> Constraint -> Bool # (/=) :: Constraint -> Constraint -> Bool # | |
Show Constraint Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> Constraint -> ShowS # show :: Constraint -> String # showList :: [Constraint] -> ShowS # | |
Component Constraint Source # | |
Defined in Apecs.Physics.Constraint type Storage Constraint :: Type # | |
(MonadIO m, Has w m Physics) => Has w m Constraint Source # | |
Defined in Apecs.Physics.Constraint getStore :: SystemT w m (Storage Constraint) # | |
type Storage Constraint Source # | |
Defined in Apecs.Physics.Constraint |
data ConstraintType Source #
PinJoint BVec BVec | Maintains a fixed distance between two anchor points |
SlideJoint BVec BVec Double Double | A |
PivotJoint WVec | Creates a pivot point at the given world coordinate |
PivotJoint2 BVec BVec | Creates a pivot point at the given body coordinates |
GrooveJoint BVec BVec BVec | 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. |
DampedSpring BVec BVec Double Double Double | Spring between two anchor points, with given rest length, stiffness, and damping. |
DampedRotarySpring Double Double Double | Rotary sping, with given rest angle, stiffness, and damping. |
RotaryLimitJoint Double Double | Joint with minimum and maximum angle |
RatchetJoint Double Double | Rathet joint with given phase and ratchet (distance between clicks). |
GearJoint Double Double | |
SimpleMotor Double | Keeps relative angular velocity constant |
Instances
Eq ConstraintType Source # | |
Defined in Apecs.Physics.Types (==) :: ConstraintType -> ConstraintType -> Bool # (/=) :: ConstraintType -> ConstraintType -> Bool # | |
Show ConstraintType Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> ConstraintType -> ShowS # show :: ConstraintType -> String # showList :: [ConstraintType] -> ShowS # |
newtype CollideBodies Source #
Instances
Eq CollideBodies Source # | |
Defined in Apecs.Physics.Types (==) :: CollideBodies -> CollideBodies -> Bool # (/=) :: CollideBodies -> CollideBodies -> Bool # | |
Show CollideBodies Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> CollideBodies -> ShowS # show :: CollideBodies -> String # showList :: [CollideBodies] -> ShowS # | |
Component CollideBodies Source # | |
Defined in Apecs.Physics.Constraint type Storage CollideBodies :: Type # | |
(MonadIO m, Has w m Physics) => Has w m CollideBodies Source # | |
Defined in Apecs.Physics.Constraint getStore :: SystemT w m (Storage CollideBodies) # | |
type Storage CollideBodies Source # | |
Defined in Apecs.Physics.Constraint |
Collision
Collision | |
|
data CollisionHandler Source #
CollisionHandler | |
|
Instances
Component CollisionHandler Source # | |
Defined in Apecs.Physics.Collision type Storage CollisionHandler :: Type # | |
(MonadIO m, Has w m Physics) => Has w m CollisionHandler Source # | |
Defined in Apecs.Physics.Collision getStore :: SystemT w m (Storage CollisionHandler) # | |
type Storage CollisionHandler Source # | |
Defined in Apecs.Physics.Collision |
data CollisionSource Source #
A CollisionSource
determines what types of collisions a callback handles.
Also see CollisionType
data SeparateCB Source #
data PreSolveCB Source #
data PostSolveCB Source #
mkSeparateCB :: MonadIO m => (Collision -> SystemT w IO ()) -> SystemT w m SeparateCB Source #
mkPreSolveCB :: MonadIO m => (Collision -> SystemT w IO Bool) -> SystemT w m PreSolveCB Source #
mkPostSolveCB :: MonadIO m => (Collision -> SystemT w IO ()) -> SystemT w m PostSolveCB Source #
addPostStepCallback :: (Has w m Physics, MonadIO m) => Int -> SystemT w IO () -> SystemT w m () Source #
Add an action that will be executed after the physics engine is done processing the current step. Since you generally cannot modify the physics space while the engine is handling collisions, addPostStepCallback
is the primary way of making changes to the physics space with a CollisionHandler
in a safe manner.
Please note that you should only use this function for callbacks in conjunction with a CollisionHandler
!
Query
data PointQueryResult Source #
PointQueryResult | |
|
Instances
Eq PointQueryResult Source # | |
Defined in Apecs.Physics.Types (==) :: PointQueryResult -> PointQueryResult -> Bool # (/=) :: PointQueryResult -> PointQueryResult -> Bool # | |
Show PointQueryResult Source # | |
Defined in Apecs.Physics.Types showsPrec :: Int -> PointQueryResult -> ShowS # show :: PointQueryResult -> String # showList :: [PointQueryResult] -> ShowS # | |
Storable PointQueryResult Source # | |
Defined in Apecs.Physics.Query sizeOf :: PointQueryResult -> Int # alignment :: PointQueryResult -> Int # peekElemOff :: Ptr PointQueryResult -> Int -> IO PointQueryResult # pokeElemOff :: Ptr PointQueryResult -> Int -> PointQueryResult -> IO () # peekByteOff :: Ptr b -> Int -> IO PointQueryResult # pokeByteOff :: Ptr b -> Int -> PointQueryResult -> IO () # peek :: Ptr PointQueryResult -> IO PointQueryResult # poke :: Ptr PointQueryResult -> PointQueryResult -> IO () # |
pointQuery :: (MonadIO m, Has w m Physics) => WVec -> Double -> CollisionFilter -> SystemT w m (Maybe PointQueryResult) Source #
Geometry
shift :: BVec -> Convex -> Convex Source #
Translates all vertices. The name shift is to prevent collisions with gloss
cRectangle :: BVec -> Convex Source #
Centered rectangle with a given size
zRectangle :: BVec -> Convex Source #
Rectangle with origin 0 and given size
toEdges :: Convex -> [Convex] Source #
Split a shape into its edges. Will return no edges for points, but returns 2 for a line (in opposite directions)
gridLines :: Vec -> Int -> Int -> [Convex] Source #
A set of lines forming a grid. Returns (r + c + 2) segments.
Type synonym indicating that a vector is expected to be in body-space coordinates
Type synonym indicating that a vector is expected to be in world-space coordinates
module Apecs
module Linear.V2