From 95bb556b0ea9c91d9d6cf0aacf8af84f71e35741 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Thu, 30 Aug 2012 15:59:06 +0200 Subject: Model now computes 3D AABBs --- Spear.lkshs | 12 ++++++------ Spear.lkshw | 2 +- Spear/Assets/Model.hsc | 34 +++++++++++++++++++--------------- Spear/Assets/Model/Model.c | 8 ++++++-- Spear/Render/AnimatedModel.hs | 6 ++---- Spear/Render/StaticModel.hs | 6 ++---- 6 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Spear.lkshs b/Spear.lkshs index 29bc011..41fc6c7 100644 --- a/Spear.lkshs +++ b/Spear.lkshs @@ -1,18 +1,18 @@ Version of session file format: 1 Time of storage: - "Wed Aug 29 20:11:59 CEST 2012" -Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 4, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 298) 192)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 678) 954 -Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs" 605)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3309)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 831)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs" 0)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs" 1173)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Just (ModuleName ["Spear","Math","Matrix4"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,4],[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs" 636)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs" 437)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP])] + "Thu Aug 30 15:57:16 CEST 2012" +Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 287) 184)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 654) 954 +Population: [(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 359)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,1],[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs" 636)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 5372)),[SplitP LeftP])] Window size: (1820,939) Completion size: (750,399) Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" -Active pane: Just "MatrixUtils.hs" +Active pane: Just "Workspace" Toolbar visible: True -FindbarState: (False,FindState {entryStr = "asdad", entryHist = ["asdad","translv","Vector3.","Vector.","copy_tr","asad","Octree","idxs","elemIndexa","elemtIn","splitAt","allocaBytes"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) +FindbarState: (False,FindState {entryStr = "\170", entryHist = ["\170","\\","^","scale","Vector4.","asdad","translv","Vector3.","Vector.","copy_tr","asad","Octree"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) Recently opened files: - ["/home/jeanne/programming/haskell/Spear/Spear/GLSL/Uniform.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix3.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Loader.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.c","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.h"] + ["/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/OBJ/OBJ_load.c","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/MD2/MD2_load.c","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs","/home/jeanne/programming/haskell/Spear/Spear/App/Application.hs","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model.hsc","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.c","/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/StaticModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Camera.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs"] Recently opened workspaces: ["/home/jeanne/programming/haskell/hagen/hagen.lkshw","/home/jeanne/programming/haskell/foo/foo.lkshw","/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/programming/haskell/nexus/nexus.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file diff --git a/Spear.lkshw b/Spear.lkshw index 24a6e94..3021a3b 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,7 +1,7 @@ Version of workspace file format: 1 Time of storage: - "Thu Aug 30 12:51:30 CEST 2012" + "Thu Aug 30 15:57:13 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: diff --git a/Spear/Assets/Model.hsc b/Spear/Assets/Model.hsc index 525d377..f1adfd7 100644 --- a/Spear/Assets/Model.hsc +++ b/Spear/Assets/Model.hsc @@ -157,26 +157,30 @@ instance Storable CTriangle where #{poke triangle, textureIndices[2]} ptr t2 --- | A 2D axis-aligned bounding box. -data Box = Box {-# UNPACK #-} !Vec2 {-# UNPACK #-} !Vec2 +-- | A 3D axis-aligned bounding box. +data Box = Box {-# UNPACK #-} !Vec3 {-# UNPACK #-} !Vec3 instance Storable Box where - sizeOf _ = 4 * sizeFloat + sizeOf _ = 6 * sizeFloat alignment _ = alignment (undefined :: CFloat) peek ptr = do - f0 <- peekByteOff ptr 0 - f1 <- peekByteOff ptr sizeFloat - f2 <- peekByteOff ptr $ 2*sizeFloat - f3 <- peekByteOff ptr $ 3*sizeFloat - return $ Box (Vec2 f0 f1) (Vec2 f2 f3) + xmin <- peekByteOff ptr 0 + ymin <- peekByteOff ptr sizeFloat + zmin <- peekByteOff ptr $ 2*sizeFloat + xmax <- peekByteOff ptr $ 3*sizeFloat + ymax <- peekByteOff ptr $ 4*sizeFloat + zmax <- peekByteOff ptr $ 5*sizeFloat + return $ Box (Vec3 xmin ymin zmin) (Vec3 xmax ymax zmax) - poke ptr (Box (Vec2 f0 f1) (Vec2 f2 f3)) = do - pokeByteOff ptr 0 f0 - pokeByteOff ptr sizeFloat f1 - pokeByteOff ptr (2*sizeFloat) f2 - pokeByteOff ptr (3*sizeFloat) f3 + poke ptr (Box (Vec3 xmin ymin zmin) (Vec3 xmax ymax zmax)) = do + pokeByteOff ptr 0 xmin + pokeByteOff ptr sizeFloat ymin + pokeByteOff ptr (2*sizeFloat) zmin + pokeByteOff ptr (3*sizeFloat) xmax + pokeByteOff ptr (4*sizeFloat) ymax + pokeByteOff ptr (5*sizeFloat) zmax -- | A model skin. @@ -448,11 +452,11 @@ foreign import ccall "Model.h model_to_ground" model_to_ground :: Ptr Model -> IO () --- | Get the model's 2D bounding boxes. +-- | Get the model's 3D bounding boxes. modelBoxes :: Model -> IO (V.Vector Box) modelBoxes model = with model $ \modelPtr -> - allocaArray (numVerts model * numFrames model * 4) $ \pointsPtr -> do + allocaArray (numVerts model * numFrames model * 6) $ \pointsPtr -> do model_compute_boxes modelPtr pointsPtr let n = numFrames model getBoxes = peekBoxes pointsPtr n 0 0 $ return [] diff --git a/Spear/Assets/Model/Model.c b/Spear/Assets/Model/Model.c index d315da1..ff5e758 100644 --- a/Spear/Assets/Model/Model.c +++ b/Spear/Assets/Model/Model.c @@ -92,17 +92,21 @@ void model_compute_boxes (Model* model, float* points) float xmax = v->x; float ymin = v->y; float ymax = v->y; + float zmin = v->z; + float zmax = v->z; unsigned i; for (i = 0; i < model->numVertices; ++i, ++v) { xmin = fmin (xmin, v->x); ymin = fmin (ymin, v->y); + zmin = fmin (zmin, v->z); xmax = fmax (xmax, v->x); ymax = fmax (ymax, v->y); + zmax = fmax (zmax, v->z); } - *points++ = xmin; *points++ = ymin; - *points++ = xmax; *points++ = ymax; + *points++ = xmin; *points++ = ymin; *points++ = zmin; + *points++ = xmax; *points++ = ymax; *points++ = zmax; } } diff --git a/Spear/Render/AnimatedModel.hs b/Spear/Render/AnimatedModel.hs index 552fada..091f97d 100644 --- a/Spear/Render/AnimatedModel.hs +++ b/Spear/Render/AnimatedModel.hs @@ -204,7 +204,5 @@ render uniforms (AnimatedModelRenderer model _ _ _ curFrame fp _) = -- | Get the model's ith bounding box. -box :: Int -> AnimatedModelResource -> AABB -box i model = - let (Box (Vec2 xmin ymin) (Vec2 xmax ymax)) = boxes model V.! i - in AABB (vec2 xmin ymin) (vec2 xmax ymax) +box :: Int -> AnimatedModelResource -> Box +box i model = boxes model V.! i diff --git a/Spear/Render/StaticModel.hs b/Spear/Render/StaticModel.hs index ddf574d..ea0606f 100644 --- a/Spear/Render/StaticModel.hs +++ b/Spear/Render/StaticModel.hs @@ -130,7 +130,5 @@ render uniforms (StaticModelRenderer model) = -- | Get the model's ith bounding box. -box :: Int -> StaticModelResource -> AABB -box i model = - let (Box (Vec2 xmin ymin) (Vec2 xmax ymax)) = boxes model V.! i - in AABB (vec2 xmin ymin) (vec2 xmax ymax) +box :: Int -> StaticModelResource -> Box +box i model = boxes model V.! i -- cgit v1.2.3