JOGL 3D Paddle Wheel

JOGL 3D Paddle Wheel with Introduction, Installation, Interfaces, Classes, Frame using AWT, Frame using Swing, 2D Objects, Primitives Shapes, 3D Cube, 3D Triangle, 3D Basic Shape, 3D Objects etc.

JOGL 3D Paddle Wheel

JOGL 3D Paddle Wheel

So far, we have learned how to create different geometrical shapes in JOGL such as triangle, cube and cuboid. Now, we will create a paddle wheel and try to rotate it.

3D image of rotating paddle wheel

To rotate a paddle wheel through coding, go through the below example: -

JPaddle.java

  1. package com.tpoint.jogl;  
  2.   
  3.   
  4. import javax.media.opengl.*;  
  5. import javax.media.opengl.awt.GLCanvas;  
  6. import javax.swing.JFrame;  
  7. import com.jogamp.opengl.util.FPSAnimator;  
  8.   
  9. public class JPaddle implements GLEventListener {  
  10.   
  11.     
  12.   
  13.    private float rotation = 0.0f;  
  14.         
  15.    @Override  
  16.    public void display( GLAutoDrawable drawable ) {  
  17.       
  18.            GL2 gl = drawable.getGL().getGL2();  
  19.            gl.glClear(GL2.GL_COLOR_BUFFER_BIT);  
  20.            gl.glLoadIdentity();    
  21.            gl.glTranslatef( 0f, 0f, -2.0f );   
  22.            gl.glRotatef(rotation, 1f, 0f, 0f);     
  23.   
  24.            gl.glColor3f(1f, 0f, 0f);  
  25.            gl.glBegin(GL2.GL_POLYGON);   
  26.            gl.glVertex3d(-0.5,0.3,0.8);   
  27.            gl.glVertex3d(0.5,0.3,0.8);   
  28.            gl.glVertex3d(0.8,0.7,0.8);  
  29.            gl.glVertex3d(-0.8,0.7,0.8);  
  30.            gl.glEnd();  
  31.   
  32.            int paddles=40;  
  33.            for (int i = 0; i < paddles; i++) {  
  34.            gl.glRotated(360.0/paddles, 100);  
  35.            gl.glBegin(GL2.GL_POLYGON);  
  36.            gl.glVertex3d(-0.5,0.3,0.8);   
  37.            gl.glVertex3d(0.5,0.3,0.8);   
  38.            gl.glVertex3d(0.8,0.7,0.8);  
  39.            gl.glVertex3d(-0.8,0.7,0.8);  
  40.   
  41.            gl.glEnd();  
  42.   
  43.            }  
  44.   
  45.   
  46.            rotation -= 0.2f;    
  47.   
  48.            }  
  49.      
  50.            public void reshape(GLAutoDrawable drawable, int x, int y,  
  51.                    int width, int height) {  
  52.   
  53.                    }  
  54.                    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,  
  55.                    boolean deviceChanged) {  
  56.                    }  
  57.                    @Override  
  58.                    public void dispose(GLAutoDrawable arg0) {  
  59.                       
  60.                       
  61.                    }  
  62.                    @Override  
  63.                    public void init(GLAutoDrawable arg0) {  
  64.                       
  65.                       
  66.                    }  
  67.         
  68.    public static void main( String[] args ) {  
  69.       
  70.       final GLProfile gp = GLProfile.get( GLProfile.GL2 );  
  71.       GLCapabilities cap = new GLCapabilities( gp );  
  72.         
  73.         
  74.       final GLCanvas gc = new GLCanvas(cap);  
  75.       JPaddle paddle = new JPaddle();  
  76.           
  77.       gc.addGLEventListener( paddle );  
  78.       gc.setSize( 400400 );  
  79.           
  80.       final JFrame frame = new JFrame ("Motor Paddle");  
  81.       frame.add(gc);  
  82.       frame.setSize(600,500);  
  83.       frame.setVisible(true);   
  84.         
  85.       final FPSAnimator animator = new FPSAnimator(gc, 200,true);  
  86.       animator.start();  
  87.    }  
  88.       
  89. }