shapes
shapes copied to clipboard
write a guide/tutorial
this one's for you, @schell
comment with your questions, so i know what to write about
My goal is to get an mvp working within my game. It's a pretty traditional setup - one main loop with a time tick, physics tick (currently empty), scripting tick and render tick. I'd like to be able to associate game entities with physical bodies and update them in between physics ticks (applying an impulse here or changing the mass there, etc).
From my browsing I think I'm mostly interested in the concrete types and functions, basically the contents of
Physics.Engine Physics.Engine.Main Physics.World etc
I'm using an entity-component setup where entities are Int
keys which I can use to associate to different components. In the case of the physics system I'm guessing the component may be a WorldObj
. Every physics tick would then consist of gathering the entity's keys and associated WorldObj
s, constructing the World WorldObj
, constructing the Scene Engine
and then running runWorld
or some such function, decomposing the result back into updates to the entity's components. From that you can probably guess what I'm trying to do and what I don't understand about the system so far ;) The current problem in my brain is how to feed the time delta to runWorld
, as it takes integer steps. My guess is it's somewhere in Physics.Engine.Main
- I'm looking at it now ... looks like it's fixed? Anything that would help me get on the right track would be greatly appreciated 👍
One quick question though - it seems there are a lot of big typeclasses and functions that require Proxy - I'm trying to steer clear of them for now as I'm guessing they're only needed internally. Did you make a conscious decision to use typeclasses over good old records? I've found that my code becomes drastically easier to refactor and "see" when using the method described in this article. You can see an example between my project renderable 0.1 and renderable 0.2.
Okay! Bed time for me! Thanks again 💯
BTW - I only mentioned the typeclass/record thing because it looks like a lot of the typeclass functions require you to pass a Proxy anyway - so you might as well be passing the record and get rid of the constraints. I've asked around a bit on IRC how that would affect performance and everyone seems to think it would either improve only very slightly or have no effect - since apparently that's what GHC does under the hood anyway, using a dictionary.
Hey, that's a good tip. I thought about doing it that way, and maybe I should. I still think I need the type families, but I should be able to put the functions in a record.
WRT Physics.Engine.Main
, I'd recommend replacing whichever pieces you want to customize. It's not very parameterized since I've only been using it for testing/benchmarking so far. In the long run, there will probably be multiple implementations for some pieces, so library users will mix and match to fit the kind of scenes they're simulating. Just use Physics.Engine.Main
as a guide (an example of client code) for now.
What is mu
in
makeWorldObj :: PhysicalObj -> Double -> ConvexHull -> WorldObj
makeWorldObj phys mu shape = woUpdateShape $ WorldObj phys mu shape
from Physics.World.Object
?
What is the unit of time for the delta in
updateWorld :: Double -> EngineT s World'
updateWorld delta = ...
from Physics.Engine.Main
?
mu
is the coefficient of friction. It's usually represented by the Greek letter.
The time delta is in seconds.
I've got a working demo going!
Hey, that's great! I definitely want to get a "restitution" knob for you, so the boxes don't have to look like they're full of sand when they collide.
How do I create static objects? Should I give them infinite or a really big mass?
Ah - sorry - I figured it out - you set the mass to 0.
How do I overlay static objects? Currently 'crossing' two static objects makes the sim explode (or something similar).
Oh, crap. I shouldn't check for collisions between static objects. I've been a bit sick the past few days, so I haven't spent any time on shapes
. I'll have a look at this and the PR stuff this weekend.
ok, i fixed the static objects exploding everything. @611b2ee8ecd048f5c222918689c9a831601507aa
And I'm glad you're feeling better :)
thanks. me, too. i'll look into exposing dt
tomorrow - unless there's a higher priority for you. maybe i'll also look into a task tracker, so i don't have to make up a sort order every time i look at the issues list.
I'm actually off in graphics land for a bit, so there's no rush for anything on my behalf.