Saturday, 24 August 2013

Convert to pixel coordinates in JOGL OpenGL

Convert to pixel coordinates in JOGL OpenGL

I've been working in openGL for all of a month now, and I've run into an
issue with the coordinate systems.
I've got a small class that creates a hexagon using this code:
for(int i = 0; i < 6; ++i) {
gl.glVertex2d(radius * Math.sin(i/6.0*2*Math.PI)-(radius*(x*1.75)),
radius * Math.cos(i/6.0*2*Math.PI)+(radius*(y*1.25)));
}
Note, all this is in java using the JOGL library.
When the Hexagons are created, they have the coordinate system with the
center of the screen as 0,0 and the top left set as -1,1
I want to convert these coordinate into screen coordinates, so the top
left is 0,0 and the center is windowX/2, -windowY/2. So, if the window is
500 pixels by 500 pixels, the center would be 250,-250.
Any help would be appreciated!

No comments:

Post a Comment