From jamin1001 at yahoo.com Wed Jan 3 17:23:02 2007 From: jamin1001 at yahoo.com (Jamin A. Ohmoto-Frederick) Date: Wed Jan 3 17:19:27 2007 Subject: [HOpenGL] Vector3 <-> Vertex3 Message-ID: <20070103222302.79391.qmail@web36206.mail.mud.yahoo.com> Hello, I am trying to use the GLU function unProject, which returns a Vertex3, but I want a Vector3. How do I convert Vertex3, or get at the coordinate values? Jamin __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From jamin1001 at yahoo.com Fri Jan 5 07:59:26 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 5 07:55:47 2007 Subject: [HOpenGL] Vector3 <-> Vertex3 In-Reply-To: <20070103222302.79391.qmail@web36206.mail.mud.yahoo.com> References: <20070103222302.79391.qmail@web36206.mail.mud.yahoo.com> Message-ID: <8177524.post@talk.nabble.com> Never mind, the following can be done w/ pattern matching: vertexToVector :: Vertex3 a -> Vector3 a vertexToVector (Vertex3 x y z) = Vector3 x y z jamin1001 wrote: > > Hello, > > I am trying to use the GLU function unProject, which > returns a Vertex3, but I want a Vector3. How do I > convert Vertex3, or get at the coordinate values? > > Jamin > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > HOpenGL mailing list > HOpenGL@haskell.org > http://www.haskell.org/mailman/listinfo/hopengl > > -- View this message in context: http://www.nabble.com/Vector3-%3C-%3E-Vertex3-tf2916372.html#a8177524 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com. From jamin1001 at yahoo.com Fri Jan 5 12:10:02 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 5 12:06:21 2007 Subject: [HOpenGL] (not?) using preservingMatrix Message-ID: <8181860.post@talk.nabble.com> 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 -- View this message in context: http://www.nabble.com/%28not-%29-using-preservingMatrix-tf2926697.html#a8181860 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com. From sebastian.sylvan at gmail.com Fri Jan 5 13:28:15 2007 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Jan 5 13:24:34 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <8181860.post@talk.nabble.com> References: <8181860.post@talk.nabble.com> Message-ID: <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> On 1/5/07, jamin1001 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 From jamin1001 at yahoo.com Fri Jan 5 13:58:02 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 5 13:54:20 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> Message-ID: <8183683.post@talk.nabble.com> 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 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 > > -- View this message in context: http://www.nabble.com/%28not-%29-using-preservingMatrix-tf2926697.html#a8183683 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com. From sebastian.sylvan at gmail.com Fri Jan 5 14:15:52 2007 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Jan 5 14:12:13 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <8183683.post@talk.nabble.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> Message-ID: <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> On 1/5/07, jamin1001 wrote: > > 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 indeed compile for me. GHC 6.6. -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From sebastian.sylvan at gmail.com Fri Jan 5 14:22:18 2007 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Jan 5 14:18:37 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> Message-ID: <3d96ac180701051122w72101ba8of57b192ffa74b15d@mail.gmail.com> On 1/5/07, Sebastian Sylvan wrote: > On 1/5/07, jamin1001 wrote: > > > > 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 indeed compile for me. GHC 6.6. > Though I would've probably avoidd all those ugly type signatures and either put one on the action which does this, or (probably) just not specify the type at all since whatever you do with rs will likely narrow the type down to GLmatrix GLdouble anyway. Or if it still doesn't work you could write: s <- get $ matrix $ Just $ Modelview 0 :: IO (GLmatrix GLdouble) And get rid of some of the clutter. The reason you need a type is due to the monomorphism restriction, which you can get rid of using -fno-monomorphis-restriction. Also you don't need to use "matrix", you can use "currentMatrix" (analogous to your C code), which will retrieve whatever matrix is set using the matrixMode state variable. -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From sebastian.sylvan at gmail.com Fri Jan 5 14:28:20 2007 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Jan 5 14:24:39 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <3d96ac180701051122w72101ba8of57b192ffa74b15d@mail.gmail.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> <3d96ac180701051122w72101ba8of57b192ffa74b15d@mail.gmail.com> Message-ID: <3d96ac180701051128r523d3b5eiadf2b3d98b71c17a@mail.gmail.com> On 1/5/07, Sebastian Sylvan wrote: > Also you don't need to use "matrix", you can use "currentMatrix" > (analogous to your C code), which will retrieve whatever matrix is set > using the matrixMode state variable. > Eek! Sorry, I see that "currentMatrix" is deprecated, so you should probably use "matrix" instead :-) -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From jamin1001 at yahoo.com Fri Jan 5 14:30:22 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 5 14:26:43 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> Message-ID: <8184318.post@talk.nabble.com> Sebastian Sylvan wrote: > > On 1/5/07, jamin1001 wrote: >> >> 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 indeed compile for me. GHC 6.6. > > -- > Sebastian Sylvan > +46(0)736-818655 > UIN: 44640862 > _______________________________________________ > HOpenGL mailing list > HOpenGL@haskell.org > http://www.haskell.org/mailman/listinfo/hopengl > > -- View this message in context: http://www.nabble.com/%28not-%29-using-preservingMatrix-tf2926697.html#a8184318 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com. From jamin1001 at yahoo.com Fri Jan 5 14:54:18 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 5 14:50:37 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <8184318.post@talk.nabble.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> <8184318.post@talk.nabble.com> Message-ID: <8184711.post@talk.nabble.com> My last post was eaten by this "Nabble Forums" web page! ... Ah, you're right. What didn't compile for me was this additional line after the preservingMatrix call: putStr $ "Result matrix: " ++ (show rs) ++ "\n" Instead, I want to return that value to use outside the call. This is what I was after, I think: rs2 <- preservingMatrix $ do loadIdentity -- do whatever you want with your your matrix rs <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLdouble)) return (rs) putStr $ "Result matrix: " ++ (show rs2) ++ "\n" Now, as for question #2, are there any pre-made ways to transform a vector with a matrix, or do I have to do it by hand (same goes for cross product!) (see the post http://groups.google.com/group/comp.graphics.api.opengl/browse_thread/thread/831ee85b6f97eb15/2de3e6d9c6a1a9e5) jamin1001 wrote: > > > > Sebastian Sylvan wrote: >> >> On 1/5/07, jamin1001 wrote: >>> >>> 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 indeed compile for me. GHC 6.6. >> >> -- >> Sebastian Sylvan >> +46(0)736-818655 >> UIN: 44640862 >> _______________________________________________ >> HOpenGL mailing list >> HOpenGL@haskell.org >> http://www.haskell.org/mailman/listinfo/hopengl >> >> > > -- View this message in context: http://www.nabble.com/%28not-%29-using-preservingMatrix-tf2926697.html#a8184711 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com. From sebastian.sylvan at gmail.com Fri Jan 5 15:08:32 2007 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Jan 5 15:04:52 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <8184711.post@talk.nabble.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> <8184318.post@talk.nabble.com> <8184711.post@talk.nabble.com> Message-ID: <3d96ac180701051208q78ae1a1ftbfe54cbf8b2e3372@mail.gmail.com> On 1/5/07, jamin1001 wrote: > > My last post was eaten by this "Nabble Forums" web page! > > ... > > Ah, you're right. What didn't compile for me was this additional line after > the preservingMatrix call: > putStr $ "Result matrix: " ++ (show rs) ++ "\n" > > > Instead, I want to return that value to use outside the call. This is what > I was after, I think: > > rs2 <- preservingMatrix $ do > loadIdentity > -- do whatever you want with your your matrix > rs <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLdouble)) > return (rs) > putStr $ "Result matrix: " ++ (show rs2) ++ "\n" > > Now, as for question #2, are there any pre-made ways to transform a vector > with a matrix, or do I have to do it by hand (same goes for cross product!) Not with OpenGL. If you go to the haskell.org website and check out the libraries page I'm sure you'll find plenty of linear algebra libraries. This is a problem that you have to face in any language, btw, at least any language which doesn't include linear algebra operations. Oh, and also do bar xs <- foo return xs is equal to do bar foo I'e you can loose the arrow and the "return". /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From jamin1001 at yahoo.com Fri Jan 5 16:19:43 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 5 16:16:02 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <3d96ac180701051208q78ae1a1ftbfe54cbf8b2e3372@mail.gmail.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051028m74b02921wa74cab31903ee232@mail.gmail.com> <8183683.post@talk.nabble.com> <3d96ac180701051115g4d305e19la47a97720391c7a1@mail.gmail.com> <8184318.post@talk.nabble.com> <8184711.post@talk.nabble.com> <3d96ac180701051208q78ae1a1ftbfe54cbf8b2e3372@mail.gmail.com> Message-ID: <8186202.post@talk.nabble.com> Thank you very much. I appreciate the detailed response and extra tips! Jamin Sebastian Sylvan wrote: > > On 1/5/07, jamin1001 wrote: >> >> My last post was eaten by this "Nabble Forums" web page! >> >> ... >> >> Ah, you're right. What didn't compile for me was this additional line >> after >> the preservingMatrix call: >> putStr $ "Result matrix: " ++ (show rs) ++ "\n" >> >> >> Instead, I want to return that value to use outside the call. This is >> what >> I was after, I think: >> >> rs2 <- preservingMatrix $ do >> loadIdentity >> -- do whatever you want with your your matrix >> rs <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix >> GLdouble)) >> return (rs) >> putStr $ "Result matrix: " ++ (show rs2) ++ "\n" >> >> Now, as for question #2, are there any pre-made ways to transform a >> vector >> with a matrix, or do I have to do it by hand (same goes for cross >> product!) > > Not with OpenGL. If you go to the haskell.org website and check out > the libraries page I'm sure you'll find plenty of linear algebra > libraries. This is a problem that you have to face in any language, > btw, at least any language which doesn't include linear algebra > operations. > > Oh, and also > > do bar > xs <- foo > return xs > > is equal to > > do bar > foo > > I'e you can loose the arrow and the "return". > > > /S > -- > Sebastian Sylvan > +46(0)736-818655 > UIN: 44640862 > _______________________________________________ > HOpenGL mailing list > HOpenGL@haskell.org > http://www.haskell.org/mailman/listinfo/hopengl > > -- View this message in context: http://www.nabble.com/%28not-%29-using-preservingMatrix-tf2926697.html#a8186202 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com. From sven.panne at aedion.de Sat Jan 6 11:20:10 2007 From: sven.panne at aedion.de (Sven Panne) Date: Sat Jan 6 11:17:27 2007 Subject: [HOpenGL] (not?) using preservingMatrix In-Reply-To: <8186202.post@talk.nabble.com> References: <8181860.post@talk.nabble.com> <3d96ac180701051208q78ae1a1ftbfe54cbf8b2e3372@mail.gmail.com> <8186202.post@talk.nabble.com> Message-ID: <200701061720.10213.sven.panne@aedion.de> Am Freitag, 5. Januar 2007 22:19 schrieb jamin1001: > Thank you very much. I appreciate the detailed response and extra tips! Thanks to Sebastian, too. Just a few remarks from my side: * preservingMatrix actually does a little bit more: It uses the current matrix mode in effect at the time it was called when popping the matrix, and does this in an exception-safe way. There is a variant for performance freaks and/or people who can guarantee that an exception will never be thrown by the action passed (unsafePreservingMatrix). In the same spirit, there is an unsafe variant of renderPrimitive, too. * "currentMatrix" is equivalent to "matrix Nothing", using whichever matrix mode is currently set. The example given states an explicit matrix to be accessed. * Sometimes explicit type signatures are needed when the OpenGL package is used, although this rarely happens for non-toy programs. This is a consequence of a design decision to be quite flexible regarding the represenation of some data structures (matrices, in our example). Although there is already a ready-to-use GLmatrix type, one could use custom data structures for matrices, as long as they are an instance of the class Matrix (define withNewMatrix or newMatrix, plus withMatrix or getMatrixComponents). Similar examples are the Map1/Map2/PolygonStipple classes. * A hopefully good source of examples is the "examples" subdirectory of the GLUT package (http://darcs.haskell.org/packages/GLUT/examples/), which I intend to extend constantly. The style follows the books in question very closely, so it should be easy to see how the OpenGL package can be used. An example which retrieves a calculated matrix is in http://darcs.haskell.org/packages/GLUT/examples/RedBook/ShadowMap.hs (see generateTextureMatrix). Cheers, S. From jamin1001 at yahoo.com Fri Jan 12 10:08:10 2007 From: jamin1001 at yahoo.com (jamin1001) Date: Fri Jan 12 10:04:09 2007 Subject: [HOpenGL] any auxillary hopengl modules? Message-ID: <8299870.post@talk.nabble.com> Hello, I was wondering if anyone made any additional utilities to complement HOpenGL. For example, I was wondering why there weren't any math operations such as "negate" defined on Vector3, or why it wasn't made an instance of Num in HOpenGL. Thanks, Jamin -- View this message in context: http://www.nabble.com/any-auxillary-hopengl-modules--tf2966417.html#a8299870 Sent from the Haskell - HOpenGL mailing list archive at Nabble.com.