Copyright | Plow Technologies LLC |
---|---|
License | MIT License |
Maintainer | Scott Murphy |
Safe Haskell | None |
Language | Haskell2010 |
Normal collision detection proceeds by checking one model against another, one at a time.
If you are dealing with a discretized grid you can simulataneously check collissions against all models simultaneously by projecting your models into a Binary grid. Then by looking for an empty intersection set, collissions are avoided and a new world is returned.
Algorithmic complexity is determined by the grid size only. A Grid can be stored in (GridSize/8) Bytes
the theory is to create a Shadow model, that is a rectangular projection into bits.
Then you position that projection onto a World, which is a 2d bit array.
you can do this all in 1 step with
>>>
either (fail) (putStrLn. showWorld) $ addModelToWorld 7 7 (shadowRect 3 3) (emptyWorld 10 10)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ X X X
>>>
let (Right world1) = addModelToWorld 7 7 (shadowRect 3 3) (emptyWorld 10 10)
>>>
let (Right world2) = addModelToWorld 1 1 (shadowRect 3 3) world1
>>>
putStrLn . showWorld $ world2
_ _ _ _ _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ X X X _ _ _ _ _ _ _ X X X
The interfaces presented here have smart constructors and try to keep you safe.. however, you can go to the internal package which is exposed if you want to violate the model assumptions, you bad person you
|
- makePatchable :: Int -> Int -> ShadowModel -> World -> Either String Patchable
- emptyWorld :: Int -> Int -> World
- addPatchToWorld :: Patchable -> World
- addModelToWorld :: Int -> Int -> ShadowModel -> World -> Either String World
- showWorld :: World -> String
- showShadowBoxModel :: ShadowModel -> String
- shadowRect :: Int -> Int -> ShadowModel
- newtype ShadowModel = ShadowModel {
- _unshadowModel :: BitArray (Int, Int)
- data World
Documentation
makePatchable :: Int -> Int -> ShadowModel -> World -> Either String Patchable Source
Make a patchable world, grouping world and model together This runs all the boundary tests so that patches can be applied quickly
emptyWorld :: Int -> Int -> World Source
Build a world with no shadows The width and height are in pixel length
addPatchToWorld :: Patchable -> World Source
place a shadow model at a given position, assumes the model is represented in a square matrix the matrix that is projected is actually just [0,1], it uses it as an intermediate while reading values out of sm. This allows us to control a true or false value without having to convert to a list
addModelToWorld :: Int -> Int -> ShadowModel -> World -> Either String World Source
Primary use Function addModelToWorld can be used with a model to create a world that can have more models consistently added to it
showShadowBoxModel :: ShadowModel -> String Source
Pretty Print a ShadowBox
shadowRect :: Int -> Int -> ShadowModel Source
Build a rectangle shadow of a given width and height Enter the width and height in bits
newtype ShadowModel Source
Shadow Models are the shapes that are inserted into a world at an origin
ShadowModel | |
|