packages feed

apecs-physics 0.3.1 → 0.3.2

raw patch · 5 files changed

+107/−12 lines, 5 filesdep ~apecsdep ~basedep ~containersPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: apecs, base, containers, inline-c, linear, template-haskell, vector

API changes (from Hackage documentation)

Files

+ CHANGELOG.md view
@@ -0,0 +1,19 @@+## [0.3.2]+### Changed+- Fixed links and added changelog to cabal file+- Added version bounds for dependencies+- Expanded haddocks++## [0.3.1]+### Changed+- added `apecs` version bound++## [0.3.0]+### Added+- `ShapeList` and `ConstraintList` components for bodies, that contain a list of entity indices of their shapes and constraints (read-only).+### Changed+- `Shape`s, `Constraint`s, and `CollisionHandler`s now track their original Haskell representations, and can be meaningfully read.+- `Shape` and `Constraint` now only have a single constructor, that explicitly takes an entity argument indicating what entity it belongs to. Previously, the interface suggested that shapes and constraints were properties of bodies, which was wrong.+- Bodies now track their shapes and constraints in /mutable/ stores+### Removed+- The `ShapeBody` component has been removed. You can find out a shapes body by reading the `Shape` component's `ShapeExtend` constructor directly.
apecs-physics.cabal view
@@ -1,8 +1,8 @@ name:                apecs-physics-version:             0.3.1+version:             0.3.2 synopsis:            2D physics for apecs description:         2D physics for apecs. Uses Chipmunk physics library under the hood.-homepage:            https://github.com/jonascarpay/apecs-physics#readme+homepage:            https://github.com/jonascarpay/apecs#readme license:             BSD3 license-file:        LICENSE author:              Jonas Carpay@@ -13,6 +13,7 @@ cabal-version:       >=1.10 extra-source-files:   README.md,+  CHANGELOG.md,   Chipmunk2D/include/chipmunk/prime.h,   Chipmunk2D/include/chipmunk/chipmunk_private.h,   Chipmunk2D/include/chipmunk/chipmunk_types.h,@@ -51,7 +52,7 @@  custom-setup   setup-depends:-    base  >= 4.5 && < 4.13,+    base  >= 4.9 && < 5,     Cabal >= 1.14  flag release@@ -76,16 +77,16 @@     Apecs.Physics.Types     Apecs.Physics.Query   build-depends:-    base >= 4.7 && < 4.13,-    apecs >= 0.7,-    containers,-    inline-c,-    linear,-    template-haskell,-    vector+    apecs            >= 0.7  && < 0.8,+    base             >= 4.9  && < 5,+    containers       >= 0.5  && < 0.8,+    inline-c         >= 0.6  && < 1,+    linear           >= 1.20 && < 2,+    template-haskell >= 2.12 && < 3,+    vector           >= 0.10 && < 0.13   ghc-options:     -Wall-    -- -O2+    -O2     -Wno-orphans     -Wno-unused-do-bind     -Wno-name-shadowing
src/Apecs/Physics.hs view
@@ -11,6 +11,7 @@   earthGravity,    -- * Body+  -- $BODY   Body (..), Position (..), Velocity (..), Angle (..), AngularVelocity (..), Force (..),   BodyMass (..), Moment (..), CenterOfGravity (..), Torque (..), ShapeList (..), ConstraintList (..), @@ -50,3 +51,12 @@ import           Apecs.Physics.Shape import           Apecs.Physics.Space import           Apecs.Physics.Types+++-- $BODY+-- When you give an entity a @'Body'@ 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).
src/Apecs/Physics/Shape.hs view
@@ -42,6 +42,7 @@ defaultFilter :: CollisionFilter defaultFilter = CollisionFilter 0 maskAll maskAll +-- | A box with the given height, width, and center point boxShape :: Double -> Double -> Vec -> Convex boxShape w h offset = Convex ((+offset) <$> verts) 0   where
src/Apecs/Physics/Types.hs view
@@ -65,14 +65,29 @@ --   These components cannot be added or removed from an entity, but rather are present as long as the entity has a @Body@. data Body = DynamicBody | KinematicBody | StaticBody deriving (Eq, Ord, Enum) +-- | A subcomponent of @Body@ representing where it is in world coordinates. newtype Position        = Position WVec+-- | A subcomponent of @Body@ representing where it is going in world coordinates newtype Velocity        = Velocity WVec+-- | 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. newtype Force           = Force Vec+-- | 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. newtype Torque          = Torque Double+-- | A component representing the mass of the @Body@ overall. newtype BodyMass        = BodyMass Double deriving (Eq, Show)+-- | The moment of inertia of the @Body@.+-- This is basically the body's tendency to resist angular acceleration. newtype Moment          = Moment Double deriving (Eq, Show) newtype Angle           = Angle Double deriving (Eq, Show) newtype AngularVelocity = AngularVelocity Double+-- | Where the @Body@'s center of gravity is, in body-local coordinates.+-- Can be read and written to. newtype CenterOfGravity = CenterOfGravity BVec  -- | The @Shape@s belonging to a body. Read-only.@@ -88,10 +103,34 @@ --   Consists of a list of vertices, and a radius. data Convex = Convex [BVec] Double deriving (Eq, Show) +-- | 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.  newtype Sensor          = Sensor          Bool       deriving (Eq, Show)+-- | 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. newtype Elasticity      = Elasticity      Double     deriving (Eq, Show)+-- | 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. newtype Mass            = Mass            Double     deriving (Eq, Show)+-- | 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. newtype Density         = Density         Double     deriving (Eq, Show)+-- | 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 Friction        = Friction        Double     deriving (Eq, Show) newtype SurfaceVelocity = SurfaceVelocity Vec        deriving (Eq, Show) newtype CollisionType   = CollisionType   C.CUIntPtr deriving (Eq, Show)@@ -144,7 +183,10 @@ newtype Gravity = Gravity Vec deriving (Eq, Show) -- | Daming factor, global value newtype Damping = Damping Double deriving (Eq, Show)--- | Speed threshold to be considered idle, and a candidate for being put to sleep. Global value+-- | Speed threshold to be considered idle, and a candidate for being put to sleep. Global value.+-- Bodies with a speed less than this will not be simulated until a force acts upon them,+-- which can potentially lead to large gains in performance, especially if there's a lot of+-- inactive bodies in the simulation. newtype IdleSpeedThreshold = IdleSpeedThreshold Double deriving (Eq, Show) -- | Sleep idle time threshold, global value newtype SleepIdleTime = SleepIdleTime Double deriving (Eq, Show)@@ -198,9 +240,20 @@ data CollisionHandler = CollisionHandler   { source      :: CollisionSource   , beginCB     :: Maybe BeginCB+  -- ^ A callback called when two bodies start touching for the first time.+  -- If it returns 'True', the physics engine will process the collision normally.+  -- If it returns 'False', the physics engine will __ignore the collision entirely__.   , separateCB  :: Maybe SeparateCB+  -- ^ A callback called when two bodies have just stopped touching. This will+  -- __always__ be called if 'beginCB' is, regardless of the return value of 'beginCB'.   , preSolveCB  :: Maybe PreSolveCB+  -- ^ A callback called when two bodies are touching during a physics step. If this function+  -- returns 'True', the collision will be processed normally. If it returns 'False, then+    -- the physics engine will stop processing the collision for this step.   , postSolveCB :: Maybe PostSolveCB+  -- ^ A callback called when two bodies are touching __after__ 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.   }  data CollisionSource@@ -222,14 +275,25 @@  data SegmentQueryResult = SegmentQueryResult   { sqShape        :: Entity+  -- ^ What entity did this query connect with?   , sqImpactPoint  :: Vec+  -- ^ The point that the segment impacted with the shape   , sqImpactNormal :: Vec+  -- ^ The normal of the surface that the segment hit   , sqImpactAlpha  :: Double+  -- ^ The normalized distance along the query segment in the range `[0, 1]`.+  -- Multiply it by the length of the segment to get the distance away the shape is.   } deriving (Eq, Show)  data PointQueryResult = PointQueryResult   { pqShape    :: Entity+  -- ^ What entity did this query connect with?   , pqPoint    :: WVec+  -- ^ The closest point on the shape's surface (in world space)   , pqDistance :: Double+  -- ^ The distance to the queried point   , pqGradient :: Double+  -- ^ The gradient of the distance function.+  -- This is equal to 'pqPoint'/'pqDistance' but accurate for even+  -- very small distances.    } deriving (Eq, Show)