Previously we how to draw a hexagon, octagon and a circle with JOGL but never resize the frame that contained them. The reason? it because we had not modified the method reshape () interface used by GLEventListener , then, to resize a frame may be that our figures are distorted as shown in this image:
deformed circle to resize the JFrame.
To prevent this, we must modify the code contained within the method reshape () as follows:
public void reshape ( GLAutoDrawable drawable, int x, int and int width, int height) {
/ / Load the projection of our image
gl . glMatrixMode (GL.GL_PROJECTION)
gl.glLoadIdentity ();
/ / When the height is larger than the width
if (w \u0026lt;= h) {
/ / Update the background (bottom ) and top (top) of
/ / so as not to warp our picture
gl.glOrtho (-xrange, xrange, yrange
-* ((float) h / (float) w) yrange * ((float) h / (float) w)-zRange, zRange)
} / / When the width is bigger than the high
else {
/ / Update the left side (left ) and the right side (right) of
/ / so as not to warp our picture
gl.glOrtho (-xrange * ((float) w / (float) h), xrange * ((float) w / (float) h),
-yrange, yrange, "zRange, zRange);}
/ / Load the model view
/ / with the new dimensions (width, height)
gl . glMatrixMode (GL.GL_MODELVIEW)
gl.glViewport (x, y, width, height);
/ / redraw the object
canvas.repaint ();}
As can be seen in the previous method, we used three new variables: xrange, yrange, zRange, these variables define our work space and must be declared and initialized in the constructor of our program
float xrange = 5.0f;
float yrange = 5.0f;
zRange float = 5.0f;
With this, our space Work will continue to comprise the ranges:
- x = [-5.5]
- y = [-5.5]
- z = [-5.5]
- GLAutodrawable
- int drawable x
- and int int
- int width height
If you wish to download the source code you can click on the following link: Download
dibujarCircunferenciaNODeforme.java source
far
0 comments:
Post a Comment