Javaturtle
Javaturtle

Reputation: 329

Computer Graphics Coordinates with glu (OpenGL)

I am having difficulty figuring out how the coordinate system in glu works, several problems to solve.

GLJPanel canvas = new GLJPanel();
frame.setSize(400,600); // Size in pixels of the frame we draw on
frame.getContentPane().add(canvas);

glu.gluOrtho2D(-100.0, 100.0, -200.0, 200.0);

gl.glViewport(100,100,200,300);

If a point has world coordinates (-50,-75), what are its coordinates in the viewport coordinate system?

and another one (not really specific code):

gluOrtho2D(-1.0, 0.0, -1.5, 0.0) and glViewport(0,300,200,300)
gluOrtho2D(0.0, 1.0, 0.0, 1.5) and glViewport(200,0,200,300)

Where would the two truncated genie curves be positioned?

Now I think I would be able to solve these, but am lost on how the coordinate system works.

Upvotes: 0

Views: 180

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213338

The world coordinates are arbitrary, and you get to choose them. In this case, (-50, -75).

The MVP matrix and projection transformation convert these to clip space coordinates which vary from (-1, -1, -1) to (+1, +1, +1). In this case, (-0.5, -0.375). This conversion is affected by your use of gluOrtho2D(), or in more modern programs, the output of the vertex shader.

The viewport coordinates are pixels, from (100, 100) to (300, 400) in this case. You just scale the clip space coordinates to convert. The pixel centers are located at half-integer coordinates, so the lower-left pixel of the window is at (0.5, 0.5). Your point is located at (200, 193.75). This conversion is affected by the use of glViewport().

I have no idea what a "genie curve" is.

Upvotes: 1

Related Questions