We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Applying a matrix to a vector
Page Index Toggle Pages: 1
Applying a matrix to a vector (Read 1313 times)
Applying a matrix to a vector
Apr 7th, 2008, 1:45am
 
Hey everyone, i'm drawing a shape using gl.glBegin(Gl.GL_Quad_Strip) and am trying to apply a matrix to re orientate some of the vertices.  Opengl doesn't seem to allow gl.glPushmatrix, gl.glPopMatrix, gl.glLoadMatrixf etc while the shape is being constructed  for example:

gl.glBegin(Gl.GL_Quad_Strip)
vertex bla bla bla
gl.glLoadMatrixf(m,0);
vertex bla bla bla
gl.glEnd();

it gives me a:
GL_ERROR at top endDraw(): 0502 GL_INVALID_OPERATION
Which is understandable.  My question is how do i apply these matrix transformations to these vertices while i'm still creating a shape?  I'm aware that in c++ you can use the Math3d libraries to perform the matrix multiplications manually, is there any way to do this in processing or Java?
Re: Applying a matrix to a vector
Reply #1 - Apr 7th, 2008, 3:49am
 
it all depends on what matrix/vector library you're using, check its docs.  there are many such libs out there, processing even has one (though it's not advertised), used something like this:

PMatrix mat = new PMatrix();
mat.translate(x,y,z);
mat.rotateX(theta);
// mat.bla bla bla...finally:
mat.mult(/*float [4]*/ vectorIn, /*float [4]*/ vectorOut);
Re: Applying a matrix to a vector
Reply #2 - Apr 7th, 2008, 4:28pm
 
that's exactly what i need, i guess i could write my own lib. but why reinvent the wheel?  Are there any libraries you'de recommend?  I'm currently using Toxi's Vec3D class which has served me pretty well so far but it doesn't have any methods to handle matrices.  Thanks again for all the great advice.
Re: Applying a matrix to a vector
Reply #3 - Apr 18th, 2008, 12:39am
 
In case anyone else has the same question i'de recommend using using the java3d vecmath package.  The java 1.5 version isn't  compatible with processing so download 1.4.  Download the manual installation files and extract the .jar files into a folder in processing's library directory.  This library rocks! it's got methods for dealing with vectors, matrices and quaternions.
Re: Applying a matrix to a vector
Reply #4 - Apr 18th, 2008, 5:13pm
 
FYI, J3D 1.5 should work fine with Processing 0135, at least it does for me, on Windows.  Just drop vecmath.jar into %processing%\libraries\vecmath\library\ and import it.  (and optionally, though you probably won't need it, drop j3dcore.jar into corresponding folder, it'll import as javax.media.j3d)
p.s. - sorry i missed your message, but i see you've already answered the q yourself Smiley
Re: Applying a matrix to a vector
Reply #5 - Apr 18th, 2008, 11:06pm
 
I'm using windows also, i tried installing the whole 1.5 package and manually extracted the files but was getting errors when making calls to any of the methods.  I reverted to version 1.4 and it worked, that's good enough for me Smiley

no need to apologize, you've been alot help.

thanks again.
Page Index Toggle Pages: 1