From 8bcacfa20da130a31abd6ecbba842586b0a20395 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Wed, 29 Aug 2012 12:44:52 +0200 Subject: Added box function --- Spear/Render/AnimatedModel.hs | 10 ++++++++++ Spear/Render/StaticModel.hs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/Spear/Render/AnimatedModel.hs b/Spear/Render/AnimatedModel.hs index 8db87c3..bdeb916 100644 --- a/Spear/Render/AnimatedModel.hs +++ b/Spear/Render/AnimatedModel.hs @@ -10,6 +10,7 @@ module Spear.Render.AnimatedModel , bind , render , update +, box ) where @@ -17,6 +18,8 @@ where import Spear.Assets.Model import Spear.Render.Model import Spear.GLSL +import Spear.Math.AABB +import Spear.Math.Vector2 (vec2) import Spear.Render.Material import Spear.Render.Program import Spear.Setup as Setup @@ -186,3 +189,10 @@ render uniforms (AnimatedModelRenderer model _ _ _ curFrame fp) = glUniform1f (shiLoc uniforms) $ unsafeCoerce shi glUniform1f (fpLoc uniforms) (unsafeCoerce fp) drawArrays gl_TRIANGLES (n*curFrame) n + + +-- | 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) diff --git a/Spear/Render/StaticModel.hs b/Spear/Render/StaticModel.hs index cefb7ed..ddf574d 100644 --- a/Spear/Render/StaticModel.hs +++ b/Spear/Render/StaticModel.hs @@ -7,6 +7,7 @@ module Spear.Render.StaticModel , Spear.Render.StaticModel.release , bind , render +, box ) where @@ -14,6 +15,8 @@ where import Spear.Assets.Model import Spear.Render.Model import Spear.GLSL +import Spear.Math.AABB +import Spear.Math.Vector2 (vec2) import Spear.Render.Material import Spear.Render.Program import Spear.Setup as Setup @@ -124,3 +127,10 @@ render uniforms (StaticModelRenderer model) = uniformVec4 (ksLoc uniforms) ks glUniform1f (shiLoc uniforms) $ unsafeCoerce shi drawArrays gl_TRIANGLES 0 $ nVertices 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) -- cgit v1.2.3