Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1.  
  2. public class Projections extends JPanel implements GLEventListener, KeyListener {
  3.  
  4.     static GLAutoDrawable glDraw;
  5.    
  6.     double ctrlpoints[] = {
  7.             -1.5, -1.5, 4.0, -0.5, -1.5, 2.0,
  8.                 0.5, -1.5, -1.0, 1.5, -1.5, 2.0,
  9.             -1.5, -0.5, 1.0, -0.5, -0.5, 3.0,
  10.                 0.5, -0.5, 0.0, 1.5, -0.5, -1.0,
  11.             -1.5, 0.5, 4.0, -0.5, 0.5, 0.0,
  12.                 0.5, 0.5, 3.0, 1.5, 0.5, 4.0,
  13.             -1.5, 1.5, -2.0, -0.5, 1.5, -2.0,
  14.                 0.5, 1.5, 0.0, 1.5, 1.5, -1.0
  15.         };
  16.  
  17.     @Override
  18.     public void display(GLAutoDrawable gLDrawable) {
  19.         GL gl = gLDrawable.getGL();
  20.         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  21.         gl.glColor3d(1.0, 0.0, 0.0);
  22.  
  23.         gl.glMapGrid2d(1/60,0.0,1.0,1/60,0.0,1.0);        
  24.         gl.glEvalMesh2(GL.GL_LINE, 0, 1/60, 0, 1/60);
  25.        
  26.     }
  27.  
  28.     @Override
  29.     public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
  30.         // TODO Auto-generated method stub
  31.  
  32.     }
  33.  
  34.     @Override
  35.     public void init(GLAutoDrawable gLDrawable) {
  36.         glDraw = gLDrawable;
  37.         GL gl = gLDrawable.getGL();
  38.         gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  39.         gl.glMap2d(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4,
  40.                    0, 1, 12, 4, ctrlpoints,0);
  41.  
  42.         gl.glEnable(GL.GL_MAP2_VERTEX_3);
  43.  
  44.        
  45.     }
  46.  
  47.     @Override
  48.     public void reshape(GLAutoDrawable drawable, int x, int y, int width,
  49.             int height) {
  50.         GL gl = drawable.getGL();
  51.         GLU glu = new GLU();
  52.         gl.glViewport(0, 0, width, height);
  53.         gl.glMatrixMode(GL.GL_PROJECTION);
  54.         gl.glLoadIdentity();
  55.         if (width <= height)
  56.             gl.glOrtho(-5.0, 5.0, -5.0*(double)height/(double)width,
  57.                 5.0*(double)height/(double)width, -5.0, 5.0);
  58.         else
  59.             gl.glOrtho(-5.0*(double)width/(double)height,
  60.                 5.0*(double)width/(double)height, -5.0, 5.0, -5.0, 5.0);
  61.  
  62.         gl.glMatrixMode(GL.GL_MODELVIEW);
  63.         gl.glLoadIdentity();
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement