aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/Triangle.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/Triangle.hs')
-rw-r--r--Spear/Math/Triangle.hs29
1 files changed, 12 insertions, 17 deletions
diff --git a/Spear/Math/Triangle.hs b/Spear/Math/Triangle.hs
index 04c2639..c47879b 100644
--- a/Spear/Math/Triangle.hs
+++ b/Spear/Math/Triangle.hs
@@ -4,11 +4,12 @@ module Spear.Math.Triangle
4) 4)
5where 5where
6 6
7import Spear.Math.Algebra
8import Spear.Math.Vector
7 9
8import Spear.Math.Vector 10import Foreign.C.Types
9 11import Foreign.Storable
10import Foreign.C.Types 12import Prelude hiding ((*))
11import Foreign.Storable
12 13
13 14
14data Triangle = Triangle 15data Triangle = Triangle
@@ -18,23 +19,17 @@ data Triangle = Triangle
18 } 19 }
19 20
20 21
21sizeVector3 = 3 * sizeOf (undefined :: CFloat)
22
23
24instance Storable Triangle where 22instance Storable Triangle where
25 23 sizeOf _ = (3::Int) * sizeVector3
26 sizeOf _ = 3 * sizeVector3
27 alignment _ = alignment (undefined :: CFloat) 24 alignment _ = alignment (undefined :: CFloat)
28 25
29 peek ptr = do 26 peek ptr = do
30 p0 <- peekByteOff ptr 0 27 p0 <- peekByteOff ptr 0
31 p1 <- peekByteOff ptr $ 1 * sizeVector3 28 p1 <- peekByteOff ptr $ (1::Int) * sizeVector3
32 p2 <- peekByteOff ptr $ 2 * sizeVector3 29 p2 <- peekByteOff ptr $ (2::Int) * sizeVector3
33
34 return $ Triangle p0 p1 p2 30 return $ Triangle p0 p1 p2
35 31
36
37 poke ptr (Triangle p0 p1 p2) = do 32 poke ptr (Triangle p0 p1 p2) = do
38 pokeByteOff ptr 0 p0 33 pokeByteOff ptr 0 p0
39 pokeByteOff ptr (1*sizeVector3) p1 34 pokeByteOff ptr ((1::Int) * sizeVector3) p1
40 pokeByteOff ptr (2*sizeVector3) p2 35 pokeByteOff ptr ((2::Int) * sizeVector3) p2