packages feed

HODE-2008.10.27: src/Physics/ODE/Space.th

module Physics.ODE.Space
    ( createSimple
    , createHash
    , destroySpace
    , setLevels
    , getLevels
    , setCleanup
    , getCleanup
    , add
    , remove
    , query
    , getNumGeoms
    , getGeomUnsafe
    , tryGetGeom
    , getGeom
    )  where

import Foreign
import Data.Maybe

import Physics.ODE.Types

#ifdef HASTH
import Foreign.HacanonLight.DIS
import Foreign.HacanonLight.Generate
import Physics.ODE.DIS
#endif

$(bind "createSimple" "dSimpleSpaceCreate" [maybePtr space,space])
$(bind "createHash" "dHashSpaceCreate" [maybePtr space,space])

$(bind "destroySpace" "dSpaceDestroy" [space,unit])

$(bind "setLevels" "dHashSpaceSetLevels" [space,int,int,unit])
$(bind "getLevels" "dHashSpaceGetLevels" [space,mkOut int,mkOut int,unit])

$(bind "setCleanup" "dSpaceSetCleanup" [space,bool,unit])
$(bind "getCleanup" "dSpaceGetCleanup" [space,bool])

$(bind "add" "dSpaceAdd" [space,geom,unit])
$(bind "remove" "dSpaceRemove" [space,geom,unit])
$(bind "query" "dSpaceQuery" [space,geom,bool])

$(bind "getNumGeoms" "dSpaceGetNumGeoms" [space,int])
$(bind "getGeomUnsafe" "dSpaceGetGeom" [space,int,geom])

tryGetGeom :: Space -> Int -> IO (Maybe Geom)
tryGetGeom space nth
    = do num <- getNumGeoms space
         if nth > num-1
            then return Nothing
            else fmap Just (getGeomUnsafe space nth)

getGeom :: Space -> Int -> IO Geom
getGeom space nth
    = fmap (fromMaybe (error msg)) (tryGetGeom space nth)
    where msg = "Physics.ODE.Space.getGeom: Index ("++show nth++") out of range."