Author Topic: Use world camera matrix in GL11 to render points  (Read 2536 times)

Offline kakashi

  • byte
  • *
  • Posts: 5
    • View Profile
Use world camera matrix in GL11 to render points
« on: June 05, 2009, 01:14:10 am »
Hi,

I want to know how to use the world camera and projection matrix with the glBegin, glVertex3f, glEnd functions to render a list of points with GL_POINTS, but I want to use the same camera and projection of the world object.
Any idea of how to do this?

Thanks a lot for any help  :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Use world camera matrix in GL11 to render points
« Reply #1 on: June 05, 2009, 07:59:25 am »
There should be no need to setup a projection matrix. jPCT will do this for you. For the rest, something like this may work (not tested):

Code: [Select]
FloatBuffer floatBuffer64 = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer();
Matrix mat = new Matrix();
Matrix m3 = new Matrix();

GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();

SimpleVector poss = cam.getPosition();
m3.mat[3][0] = -poss.x;
m3.mat[3][1] = -poss.y;
m3.mat[3][2] = -poss.z;

Matrix mo=obj.getWorldTransformation(); // or new Matrix() if no Object3D involved...or whatever...

mat.setTo(cam.getBack());
mat.rotateX((float) Math.PI); // Transform into GL

mo.matMul(m3);
mo.matMul(mat);
dump=mo.getDump();

floatBuffer64.put(dump);
floatBuffer64.rewind();

GL11.glLoadMatrix(floatBuffer64);

// Render your stuff here...

GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix();

Edit: Keep in mind that, when using a threaded renderer (like the AWTGLRenderer), this has to happen in IPaintListener's finishedPainting()-method or otherwise, the application will crash.
« Last Edit: June 05, 2009, 08:02:01 am by EgonOlsen »

Offline kakashi

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Use world camera matrix in GL11 to render points
« Reply #2 on: June 05, 2009, 07:29:50 pm »
Thanks a lot!!, it worked very well!  :)