代码之家  ›  专栏  ›  技术社区  ›  Stéphane Laurent

使用Haskell OpenGL应用转换

  •  2
  • Stéphane Laurent  · 技术社区  · 6 年前

    使用haskell opengl,可以对如下对象应用转换:

      preservingMatrix $ do
        translate myvector
        renderObject Solid $ Sphere' 0.2 50 50
    

    转变 translate , rotate scale 可用。我想应用对应于正交的变换 3x3 矩阵 M 这不是旋转。可能吗?怎么可能?

    当然,作为一个绝望的解决方案,我可以分解 翻译和旋转(如果我正确记得数学课程,这是可能的)。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Stéphane Laurent    6 年前

    是的,这是 multMatrix . 我已经跟踪了 this example 。如果你的矩阵是

    a b c 
    d e f 
    g h i
    

    然后做一些类似的事情

      ......
      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
    

    如果要添加翻译,请执行

      m <- (newMatrix RowMajor [ a, b, c, x
                               , d, e, f, y
                               , g, h, i, z
                               , 0, 0, 0, 1]) :: IO (GLmatrix GLfloat)
    

    在哪里? (x,y,z) 是转换向量。

    teapot

        2
  •  0
  •   Thomas    6 年前

    我的haskell生锈了,我以前从未用过OpenGL,但也许你在找 multMatrix ?