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