Reputation: 84699
With Haskell OpenGL, it is possible to apply a transformation to an object like this:
preservingMatrix $ do
translate myvector
renderObject Solid $ Sphere' 0.2 50 50
The transformations translate
, rotate
, and scale
are available. I would like to apply the transformation corresponding to an orthonormal 3x3
matrix M
which is not a rotation. Is it possible and how ?
Of course, as a desperate solution I could decompose M
into translations and rotations (this is possible if I correctly remember my maths courses).
Upvotes: 2
Views: 171
Reputation: 84699
Yes, this is multMatrix
. I've followed this example. If your matrix is
a b c
d e f
g h i
then do something like
......
preservingMatrix $ do
myTransformation
materialDiffuse Front $= green
renderObject Solid $ Teapot 5
swapBuffers
where
myTransformation = do
m <- (newMatrix RowMajor [ a, b, c, 0
, d, e, f, 0
, g, h, i, 0
, 0, 0, 0, 1]) :: IO (GLmatrix GLfloat)
multMatrix m
If you want to add a translation, do
m <- (newMatrix RowMajor [ a, b, c, x
, d, e, f, y
, g, h, i, z
, 0, 0, 0, 1]) :: IO (GLmatrix GLfloat)
where (x,y,z)
is the translation vector.
Upvotes: 1
Reputation: 182038
My Haskell is rusty and I've never used it with OpenGL before, but maybe you are looking for multMatrix
?
Upvotes: 0