« Return to Thread: (not?) using preservingMatrix

Re: (not?) using preservingMatrix

by jamin1001 :: Rate this Message:

Reply to Author | View in Thread

Right, I buy that.  But I don't see how the C line

glGetFloatv (GL_MODELVIEW_MATRIX, your_matrix_result) ;

can be done, since it writes a result into your_matrix_result, so I would need something like:

preservingMatrix $ do
    loadIdentity
    -- do whatever you want with your your matrix
    rs <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLdouble)) -- this does not compile, but I need rs
    return ()

I want the matrix so that I can then transform a vector.  

Speaking of which, are there any ready-made ways to transform a vector with a matrix, or do I need to do that by hand (eg., see the post http://groups.google.com/group/comp.graphics.api.opengl/browse_thread/thread/831ee85b6f97eb15/2de3e6d9c6a1a9e5)

 
Thanks again,

Jamin


Sebastian Sylvan wrote:
On 1/5/07, jamin1001 <jamin1001@yahoo.com> wrote:
>
> In C OpenGL, you can do something like this to use matrices for computation
> without affecting context:
>
> glMatrixMode (GL_MODELVIEW) ;
> glPushMatrix () ;
> glLoadMatrix (your_matrix) ;
> // do whatever you want with your your matrix
> // for exampl glMultMatrix (your_matrix2) ;
> ...
> // at the end of your calculations use
> glGetFloatv (GL_MODELVIEW_MATRIX, your_matrix_result) ;
> glPopMatrix () ; // nothing has changed !!!
>
> I'm not exactly sure how this is done with HOpenGL. i.e., how can I get the
> result of a matrix transformation not effecting the MODELVIEW, etc.
> matrices?  Could someone give an example?
>
>
> Thanks,
>
> Jamin

glPushMatrix() ; foo ; glPopMatrix();

Is written like so:

preservingMatrix foo

Often you would write things like
do foo
    preservingMatrix $
        do bar
            baz
    foo2

Here bar and baz may modify the matrices, but as soon as you leave the
scope of the action passed to preservingMatrix, the matrix stack is
popped (glPopMatrix()).

The Haskell way is better, since there is no way of ever forgetting to
pop the matrix - preservingMatrix is like a user defined control
structure. That's what first class actions buys you.

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
_______________________________________________
HOpenGL mailing list
HOpenGL@haskell.org
http://www.haskell.org/mailman/listinfo/hopengl

 « Return to Thread: (not?) using preservingMatrix