diff options
Diffstat (limited to 'Spear/Math/Triangle.hs')
| -rw-r--r-- | Spear/Math/Triangle.hs | 29 |
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 | ) |
| 5 | where | 5 | where |
| 6 | 6 | ||
| 7 | import Spear.Math.Algebra | ||
| 8 | import Spear.Math.Vector | ||
| 7 | 9 | ||
| 8 | import Spear.Math.Vector | 10 | import Foreign.C.Types |
| 9 | 11 | import Foreign.Storable | |
| 10 | import Foreign.C.Types | 12 | import Prelude hiding ((*)) |
| 11 | import Foreign.Storable | ||
| 12 | 13 | ||
| 13 | 14 | ||
| 14 | data Triangle = Triangle | 15 | data Triangle = Triangle |
| @@ -18,23 +19,17 @@ data Triangle = Triangle | |||
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | sizeVector3 = 3 * sizeOf (undefined :: CFloat) | ||
| 22 | |||
| 23 | |||
| 24 | instance Storable Triangle where | 22 | instance 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 |
