blob: c47879b117b60fd80a04b0f074025c2856dd3804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
module Spear.Math.Triangle
(
Triangle(..)
)
where
import Spear.Math.Algebra
import Spear.Math.Vector
import Foreign.C.Types
import Foreign.Storable
import Prelude hiding ((*))
data Triangle = Triangle
{ p0 :: {-# UNPACK #-} !Vector3
, p1 :: {-# UNPACK #-} !Vector3
, p2 :: {-# UNPACK #-} !Vector3
}
instance Storable Triangle where
sizeOf _ = (3::Int) * sizeVector3
alignment _ = alignment (undefined :: CFloat)
peek ptr = do
p0 <- peekByteOff ptr 0
p1 <- peekByteOff ptr $ (1::Int) * sizeVector3
p2 <- peekByteOff ptr $ (2::Int) * sizeVector3
return $ Triangle p0 p1 p2
poke ptr (Triangle p0 p1 p2) = do
pokeByteOff ptr 0 p0
pokeByteOff ptr ((1::Int) * sizeVector3) p1
pokeByteOff ptr ((2::Int) * sizeVector3) p2
|