| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Apecs.Physics
Description
apecs-physics prelude
Synopsis
- data Physics
- newtype Gravity = Gravity Vec
- newtype Iterations = Iterations Int
- stepPhysics :: Has w IO Physics => Double -> System w ()
- 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 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 CollideBodies = CollideBodies Bool
- data Collision = Collision {
- collisionNormal :: Vec
- collisionA :: Entity
- collisionB :: Entity
- data CollisionHandler = CollisionHandler {}
- defaultHandler :: CollisionHandler
- data 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 {
- pqShape :: Entity
- pqPoint :: WVec
- pqDistance :: Double
- pqGradient :: Double
- pointQuery :: Has w IO Physics => WVec -> Double -> CollisionFilter -> System w (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
Constructors
| Gravity Vec |
newtype Iterations #
Number of iterations per step, global value
Constructors
| Iterations Int |
Instances
| Eq Iterations # | |
Defined in Apecs.Physics.Types | |
| Show Iterations # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> Iterations -> ShowS # show :: Iterations -> String # showList :: [Iterations] -> ShowS # | |
| Component Iterations # | |
Defined in Apecs.Physics.Space Associated Types type Storage Iterations :: Type # | |
| Has w IO Physics => Has w IO Iterations # | |
Defined in Apecs.Physics.Space | |
| type Storage Iterations # | |
Defined in Apecs.Physics.Space | |
earthGravity :: Gravity #
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.
Constructors
| DynamicBody | |
| KinematicBody | |
| StaticBody |
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 #
Constructors
| AngularVelocity Double |
Instances
| Component AngularVelocity # | |
Defined in Apecs.Physics.Body Associated Types type Storage AngularVelocity :: Type # | |
| Has w IO Physics => Has w IO AngularVelocity # | |
Defined in Apecs.Physics.Body | |
| type Storage AngularVelocity # | |
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.
Constructors
| 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 #
Where the Body's center of gravity is, in body-local coordinates.
Can be read and written to.
Constructors
| CenterOfGravity BVec |
Instances
| Component CenterOfGravity # | |
Defined in Apecs.Physics.Body Associated Types type Storage CenterOfGravity :: Type # | |
| Has w IO Physics => Has w IO CenterOfGravity # | |
Defined in Apecs.Physics.Body | |
| type Storage CenterOfGravity # | |
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 Shapes belonging to a body. Read-only.
newtype ConstraintList #
The Constraints belonging to a body. Read-only.
Constructors
| ConstraintList [Entity] |
Instances
| Component ConstraintList # | |
Defined in Apecs.Physics.Body Associated Types type Storage ConstraintList :: Type # | |
| Has w IO Physics => Has w IO ConstraintList # | |
Defined in Apecs.Physics.Body | |
| type Storage ConstraintList # | |
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 #
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.
Constructors
| Elasticity Double |
Instances
| Eq Elasticity # | |
Defined in Apecs.Physics.Types | |
| Show Elasticity # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> Elasticity -> ShowS # show :: Elasticity -> String # showList :: [Elasticity] -> ShowS # | |
| Component Elasticity # | |
Defined in Apecs.Physics.Shape Associated Types type Storage Elasticity :: Type # | |
| Has w IO Physics => Has w IO Elasticity # | |
Defined in Apecs.Physics.Shape | |
| type Storage Elasticity # | |
Defined in Apecs.Physics.Shape | |
newtype SurfaceVelocity #
Constructors
| SurfaceVelocity Vec |
Instances
| Eq SurfaceVelocity # | |
Defined in Apecs.Physics.Types Methods (==) :: SurfaceVelocity -> SurfaceVelocity -> Bool # (/=) :: SurfaceVelocity -> SurfaceVelocity -> Bool # | |
| Show SurfaceVelocity # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> SurfaceVelocity -> ShowS # show :: SurfaceVelocity -> String # showList :: [SurfaceVelocity] -> ShowS # | |
| Component SurfaceVelocity # | |
Defined in Apecs.Physics.Shape Associated Types type Storage SurfaceVelocity :: Type # | |
| Has w IO Physics => Has w IO SurfaceVelocity # | |
Defined in Apecs.Physics.Shape | |
| type Storage SurfaceVelocity # | |
Defined in Apecs.Physics.Shape | |
data CollisionFilter #
Constructors
| CollisionFilter | |
Fields
| |
Instances
| Eq CollisionFilter # | |
Defined in Apecs.Physics.Types Methods (==) :: CollisionFilter -> CollisionFilter -> Bool # (/=) :: CollisionFilter -> CollisionFilter -> Bool # | |
| Show CollisionFilter # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> CollisionFilter -> ShowS # show :: CollisionFilter -> String # showList :: [CollisionFilter] -> ShowS # | |
| Component CollisionFilter # | |
Defined in Apecs.Physics.Shape Associated Types type Storage CollisionFilter :: Type # | |
| Has w IO Physics => Has w IO CollisionFilter # | |
Defined in Apecs.Physics.Shape | |
| type Storage CollisionFilter # | |
Defined in Apecs.Physics.Shape | |
A bitmask used for collision handling
Instances
| Eq Bitmask # | |
| Show Bitmask # | |
| Bits Bitmask # | |
Defined in Apecs.Physics.Types Methods (.&.) :: 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 # | |
Constraint
data Constraint #
Constructors
| Constraint Entity Entity ConstraintType |
Instances
| Eq Constraint # | |
Defined in Apecs.Physics.Types | |
| Show Constraint # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> Constraint -> ShowS # show :: Constraint -> String # showList :: [Constraint] -> ShowS # | |
| Component Constraint # | |
Defined in Apecs.Physics.Constraint Associated Types type Storage Constraint :: Type # | |
| Has w IO Physics => Has w IO Constraint # | |
Defined in Apecs.Physics.Constraint | |
| type Storage Constraint # | |
Defined in Apecs.Physics.Constraint | |
data ConstraintType #
Constructors
| 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 # | |
Defined in Apecs.Physics.Types Methods (==) :: ConstraintType -> ConstraintType -> Bool # (/=) :: ConstraintType -> ConstraintType -> Bool # | |
| Show ConstraintType # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> ConstraintType -> ShowS # show :: ConstraintType -> String # showList :: [ConstraintType] -> ShowS # | |
newtype CollideBodies #
Constructors
| CollideBodies Bool |
Instances
| Eq CollideBodies # | |
Defined in Apecs.Physics.Types Methods (==) :: CollideBodies -> CollideBodies -> Bool # (/=) :: CollideBodies -> CollideBodies -> Bool # | |
| Show CollideBodies # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> CollideBodies -> ShowS # show :: CollideBodies -> String # showList :: [CollideBodies] -> ShowS # | |
| Component CollideBodies # | |
Defined in Apecs.Physics.Constraint Associated Types type Storage CollideBodies :: Type # | |
| Has w IO Physics => Has w IO CollideBodies # | |
Defined in Apecs.Physics.Constraint | |
| type Storage CollideBodies # | |
Defined in Apecs.Physics.Constraint | |
Collision
Constructors
| Collision | |
Fields
| |
data CollisionHandler #
Constructors
| CollisionHandler | |
Fields
| |
Instances
| Component CollisionHandler # | |
Defined in Apecs.Physics.Collision Associated Types type Storage CollisionHandler :: Type # | |
| Has w IO Physics => Has w IO CollisionHandler # | |
Defined in Apecs.Physics.Collision | |
| type Storage CollisionHandler # | |
Defined in Apecs.Physics.Collision | |
data CollisionSource #
data SeparateCB #
data PreSolveCB #
data PostSolveCB #
mkSeparateCB :: (Collision -> System w ()) -> System w SeparateCB #
mkPreSolveCB :: (Collision -> System w Bool) -> System w PreSolveCB #
mkPostSolveCB :: (Collision -> System w ()) -> System w PostSolveCB #
Query
data PointQueryResult #
Constructors
| PointQueryResult | |
Fields
| |
Instances
| Eq PointQueryResult # | |
Defined in Apecs.Physics.Types Methods (==) :: PointQueryResult -> PointQueryResult -> Bool # (/=) :: PointQueryResult -> PointQueryResult -> Bool # | |
| Show PointQueryResult # | |
Defined in Apecs.Physics.Types Methods showsPrec :: Int -> PointQueryResult -> ShowS # show :: PointQueryResult -> String # showList :: [PointQueryResult] -> ShowS # | |
| Storable PointQueryResult # | |
Defined in Apecs.Physics.Query Methods 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 :: Has w IO Physics => WVec -> Double -> CollisionFilter -> System w (Maybe PointQueryResult) #
Geometry
shift :: BVec -> Convex -> Convex #
Translates all vertices. The name shift is to prevent collisions with gloss
cRectangle :: BVec -> Convex #
Centered rectangle with a given size
oRectangle :: BVec -> BVec -> Convex #
Rectangle with a given origin and size
zRectangle :: BVec -> Convex #
Rectangle with origin 0 and given size
toEdges :: Convex -> [Convex] #
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] #
A set of lines forming a grid. Returns (r + c + 2) segments.
module Apecs
module Linear.V2