-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransform.hs
More file actions
31 lines (25 loc) · 1.01 KB
/
Transform.hs
File metadata and controls
31 lines (25 loc) · 1.01 KB
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
module Transform where
import Graphics.Rendering.OpenGL
type TograMatrix = ((GLdouble, GLdouble, GLdouble, GLdouble),
(GLdouble, GLdouble, GLdouble, GLdouble),
(GLdouble, GLdouble, GLdouble, GLdouble),
(GLdouble, GLdouble, GLdouble, GLdouble))
translateM :: GLdouble -> GLdouble -> GLdouble -> TograMatrix
translateM x y z = ((1, 0, 0, x), (0, 1, 0, y), (0, 0, 1, z), (0, 0, 0, 1))
rotateM :: GLdouble -> GLdouble -> GLdouble -> GLdouble -> TograMatrix
rotateM x y z r = ((x2+(1-x2)*c, x*y*(1-c)-z*s, x*z*(1-c)+y*s, 0),
(x*y*(1-c)+z*s, y2+(1-y2)*c, y*z*(1-c)-x*s, 0),
(x*z*(1-c)-y*s, y*z*(1-c)+x*s, z2+(1-z2)*c, 0),
(0, 0, 0, 1))
where
x2 = x*x
y2 = y*y
z2 = z*z
c = cos r
s = sin r
t :: TograMatrix -> TograMatrix
t ((a,b,c,d),(e,f,g,h),(i,j,k,l),(m,n,o,p)) =
((a,e,i,m),(b,f,j,n),(c,g,k,o),(d,h,l,p))
toGLMatrix :: TograMatrix -> IO (GLmatrix GLdouble)
toGLMatrix ((a,b,c,d),(e,f,g,h),(i,j,k,l),(m,n,o,p)) =
newMatrix RowMajor [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p]