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