ublubu / shapes Goto Github PK
View Code? Open in Web Editor NEWphysics engine and other tools for 2D shapes
physics engine and other tools for 2D shapes
shapes/shapes/src/Physics/Linear.hs
Lines 267 to 269 in fa5d959
shapes/shapes/src/Physics/Linear.hs
Lines 301 to 302 in fa5d959
The inverse effective mass of a pair of objects along the constraint axis
shapes/shapes/src/Physics/Constraint.hs
Lines 171 to 173 in fa5d959
NOTE: Can't make type family of kind #. (confirm?)
shapes/shapes-math/src/Shapes/Linear/Class.hs
Lines 3 to 4 in fa5d959
Lagrangian multiplier - the (signed) magnitude of the impulse
required to solve a constraint equation.
shapes/shapes/src/Physics/Constraint/Types.hs
Lines 16 to 19 in fa5d959
Hey there @ublubu! Are you still working on this project? Any idea how long before a hackage release (0.1 even).
See shapes/src/Physics/Engine/Main.hs line 54
shapes/shapes-demo/src/Physics/Draw/Transform.hs
Lines 71 to 72 in fa5d959
I'm guessing you already knew this as you mention in first in your reddit link but just doing a quick stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto"
shows that Physics.Broadphase.Opt.Aabb.culledPairs.f
is the biggest CPU cost center. It has two IntMap lookups which at first I thought may be the culprit but IM.lookup doesn't even show up in the prof file, and I've enabled library profiling. I'm not sure - I'd like to take a look at the generated core and see if I can make any sense of it. It could be that using a list is the culprit.
mu = 0
)shapes/shapes/src/Utils/Utils.hs
Lines 106 to 108 in fa5d959
shapes/shapes/src/Utils/Utils.hs
Lines 243 to 244 in fa5d959
I've been following this project for a few months and I'm excited that there's a physics library that's not stuck in the IO, but there's a pretty severe lack of haddock documentation right now which is making it difficult to learn the library.
see lap, Geometry.overlap
shapes/shapes-demo/src/Physics/Draw/Transform.hs
Lines 44 to 47 in fa5d959
see lap, Geometry.overlap
shapes/shapes/src/Physics/Transform.hs
Lines 92 to 94 in fa5d959
this one's for you, @schell
comment with your questions, so i know what to write about
shapes/shapes/src/Physics/Contact/Types.hs
Lines 19 to 20 in fa5d959
set up one of those fancy buttons in the readme that says whether this project is broken
set some version bounds for the dependencies. i plan to just use the major versions of whatever i'm building with using stack.
Get a 6D velocity vector for a pair of objects.
Same as '_constrainedVel6'
shapes/shapes/src/Physics/Constraint.hs
Lines 149 to 153 in fa5d959
pre-descZipVector, profiled 10 frames at 130ms
post-descZipVector, profiled 10 frames at 190ms
post-descZipVector-inline, profiled 10 frames at 130ms
why does pre-descZipVector run 100fps in the demo?
shapes/shapes/src/Utils/Utils.hs
Line 315 in 09da303
shapes/shapes/src/Utils/Utils.hs
Line 329 in 09da303
shapes/shapes/src/Utils/Utils.hs
Line 344 in 09da303
There are lots of 2d physics engines out there and a couple already have Haskell bindings (box2d, chipmunk). These are both battle tested and proven technologies. I don’t think shapes can compete with them in a standard “technology pull” project environment (one where the tech is picked based on the needs of the project). Asking a game developer to write their game in Haskell is a hard sell. So what can Haskell do that other languages cannot?
Haskell can guarantee reproducible results through referential transparency. Shapes already does this to a certain extent - it’s pure, so one set of inputs should always give you the same output, but the implementation of some underlying floating point operations (1) are platform dependent! Simulations on different machines or different build targets may produce different results.
Would it be worth it to use the techniques outlined by Joachim Breitner (@nomeata) in section 5.1 of this paper to ensure deterministic simulation under all circumstances?
Fun to think about, none the less.
(1) - transcendental functions like exp, sin, cos, log, etc.
shapes/shapes/src/Physics/Broadphase/Aabb.hs
Lines 39 to 40 in fa5d959
let things be bouncy
shapes/shapes/src/Physics/Constraints/Contact/NonPenetration.hs
Lines 33 to 34 in fa5d959
shapes/shapes/src/Physics/Scenes/Scene.hs
Lines 5 to 6 in fa5d959
i can probably be more judicious with the inline pragmas
shapes/shapes/bench/Physics/Broadphase/Benchmark.hs
Lines 19 to 20 in fa5d959
This would make using this library more discover-able.
In Physics.Engine.Class
, makePhysicalObj
takes a mass of (x, y). Why is the mass a vector? What does it represent?
https://github.com/ublubu/shapes/blob/master/shapes/src/Physics/Engine/Class.hs#L23
add INLINE pragmas, particularly in shapes-math and Utils.Utils
Using stackage nightly to build with ghc8 I found that shapes-math is erring with:
/Users/schell/Code/shapes/shapes-math/src/Shapes/Linear/Template.hs:43:20: error:
• Data constructor not in scope: NotStrict
• Perhaps you meant variable ‘notStrict’ (imported from Language.Haskell.TH)
/Users/schell/Code/shapes/shapes-math/src/Shapes/Linear/Template.hs:54:34: error:
• Couldn't match expected type ‘Maybe Kind’
with actual type ‘[Con]’
• In the fourth argument of ‘DataD’, namely
‘[NormalC vectorN (replicate dim constrArg)]’
In the first argument of ‘(:)’, namely
‘DataD
[] vectorN [] [NormalC vectorN (replicate dim constrArg)] []’
In the expression:
DataD [] vectorN [] [NormalC vectorN (replicate dim constrArg)] []
: impls
/Users/schell/Code/shapes/shapes-math/src/Shapes/Linear/Template.hs:54:83: error:
• Couldn't match type ‘Dec’ with ‘Cxt -> Dec’
Expected type: [Cxt -> Dec]
Actual type: [Dec]
• In the second argument of ‘(:)’, namely ‘impls’
In the expression:
DataD [] vectorN [] [NormalC vectorN (replicate dim constrArg)] []
: impls
In an equation for ‘decs’:
decs
= DataD
[] vectorN [] [NormalC vectorN (replicate dim constrArg)] []
: impls
/Users/schell/Code/shapes/shapes-math/src/Shapes/Linear/Template.hs:55:3: error:
• Couldn't match type ‘Cxt -> Dec’ with ‘Dec’
Expected type: Q [Dec]
Actual type: Q [Cxt -> Dec]
• In a stmt of a 'do' block: return decs
In the expression:
do { let vectorN = makeVectorN dim
constrArg = ...
....;
impls <- concat <$> mapM (\ f -> f vectorN vi dim) definers;
let decs = DataD ... vectorN ... ... ... : impls;
return decs }
In an equation for ‘makeVectorType’:
makeVectorType vi@(ValueInfo {..}) dim
= do { let vectorN = ...
....;
impls <- concat <$> mapM (\ f -> f vectorN vi dim) definers;
let decs = ...;
.... }
It seems template-haskell
2.11 has some breaking changes. What is the TH mostly used for in shapes-math? Maybe there's a non-TH way to accomplish this?
shapes/shapes/src/Physics/Contact/CircleVsHull.hs
Lines 24 to 25 in fa5d959
I know shapes is 2d and that 3d isn't on the roadmap, but how much more work is adding a separate 3d module? Maybe only using boxes or spheres?
Flatten a 'Contact' into 'Contact''s.
split contactsolution cache into impulse cache (copied between frames) and constraint cache (single frame)
shapes/shapes/src/Physics/Solvers/Contact.hs
Lines 72 to 73 in fa5d959
instance (Epsilon a, Floating a, Ord a) => WorldTransformable (ConvexHull a) a where
transform t = flip transformHull (transform t)
untransform t = flip transformHull (untransform t)
shapes/shapes/src/Physics/Contact/ConvexHull.hs
Lines 130 to 134 in fa5d959
shapes/shapes-math/src/Shapes/Linear/Template.hs
Lines 13 to 14 in fa5d959
dynamics may be updated many times during the constraint-solving steps of a frame.
shape information is only updated after all the constraint-solving is done.
it may be more efficient to keep separate data structures for each kind of state (and user data also).
now that there's only one implementation of the physics engine, there isn't really a need for these classes.
arguments in favor of keeping the typeclasses:
culledKeys are in order
change keyedContacts so they are also in order (make keyed contacts flippable and sort by feature?)
zip keyedContacts with old cache vector to create new cache vector
^ new cache vector is dense; first contacts get an extra solver iteration - less jittery/bouncy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.