Question
I am looking for help with a solution to an assignment I have been working on. I have attempted to write code that I cannot
I am looking for help with a solution to an assignment I have been working on. I have attempted to write code that I cannot seem to get to work and it is unclear as to whether it's due to the code I have written or if it is due to incorrectly setting up the JOGL files in my library which help run the program. Any help would be highly appreciated! Feedback as to whether someone can get it to run would also be an indicator of a failed library path. Thanks in advance!
In this project you will create a unique 3 graphics scene composed of OpenGL graphic components using transformation methods. Requirements: 1. Using Netbeans or Eclipse, develop a JOGL application that displays a unique 3D scene. The scene has the following specifications: a. Size: minimum 640x480 b. Includes at least 6 different shapes c. Uses at least 6 different transformation methods 2. Use Java and JOGL for your implementation of OpenGL 3. All Java source code should be written using Google Java style guide. 4. Prepare, conduct and document a test plan verifying your application is working as expected. This plan should include a test matrix listing each method you tested, how you tested it, and the results of testing.
My Code:
import java.awt.Frame;
import java.awt.event.*;
import javax.swing.*;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL2ES1;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.gl2.GLUT;
public abstract class CoolShapes extends JFrame implements GLEventListener, KeyListener
{
private static final long serialVersionUID = 1L;
private GLU glu;
private GLUT glut;
private GLCapabilities caps;
private GLCanvas canvas;
@SuppressWarnings("unused")
private FPSAnimator animator;
private static int fps = 1;
public CoolShapes()
{
super("CoolShapes");
caps = new GLCapabilities(null);
canvas = new GLCanvas(caps);
canvas.addGLEventListener(this);
canvas.addKeyListener(this);
getContentPane().add(canvas);
}
public static void main(String[] args)
{
// new CoolShapes().run();
GLCanvas canvas = new GLCanvas();
Frame frame = new Frame("Shapes");
frame.setSize(700, 700);
frame.add(canvas);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
FPSAnimator animator = new FPSAnimator(canvas, fps);
CoolShapes scene = new CoolShapes() {
@Override
public void dispose(GLAutoDrawable glad) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
canvas.requestFocus();
canvas.addGLEventListener(scene);
canvas.addKeyListener(scene);
animator.start();
}
public void init(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
//
gl.glClearColor(0f, 0f, 0f, 0f);
gl.glShadeModel(GL.GL_FLAT);
}
/*
* Clear the screen. For six shape, set the current color and modify the
* sixshape3d view matrix.
*/
public void display(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
((GL2) gl).glColor3f(1f, 1f, 1f);
((GLMatrixFunc) gl).glLoadIdentity();
drawTriangle(gl);
drawTriangle(gl);
square(gl, 12,12.5,4.5);
drawsemicircle((GL2) gl);
drawDisk((GL2) gl, 3);
cube((GL2) gl);
drawsemicircle((GL2) gl);
gl.glEnable(GL.GL_LINE_STIPPLE);
((GL2) gl).glLineStipple(1, (short) 0xf0f0);
((GLMatrixFunc) gl).glLoadIdentity();
((GLMatrixFunc) gl).glTranslatef(-20f, 0f, 0f);
drawTriangle(gl);
square(gl, 12,12.5,4.5);
drawsemicircle((GL2) gl);
drawDisk((GL2) gl, 3);
cube((GL2) gl);
drawsemicircle((GL2) gl);
((GL2) gl).glLineStipple(1, (short) 0xF00F);
((GLMatrixFunc) gl).glLoadIdentity();
((GLMatrixFunc) gl).glScalef(1.5f, 0.5f, 1.0f);
drawTriangle(gl);
square(gl, 12,12.5,4.5);
drawsemicircle((GL2) gl);
drawDisk((GL2) gl, 3);
cube((GL2) gl);
drawsemicircle((GL2) gl);
((GL2) gl).glLineStipple(1, (short) 0x8888);
((GLMatrixFunc) gl).glLoadIdentity();
((GLMatrixFunc) gl).glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
drawTriangle(gl);
GL2 g1 = null;
drawflower(g1);
square(gl, 12,12.5,4.5);
drawsemicircle((GL2) gl);
drawDisk((GL2) gl, 3);
cube((GL2) gl);
drawsemicircle((GL2) gl);
gl.glDisable(GL.GL_LINE_STIPPLE);
square(gl, 12,12.5,4.5);
drawsemicircle((GL2) gl);
drawDisk((GL2) gl, 3);
cube((GL2) gl);
drawsemicircle((GL2) gl);
gl.glFlush();
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
{
GL gl = drawable.getGL();
gl.glViewport(0, 0, w, h);
gl.glMatrixMode(GL.GL_PROJECTION);
((GLMatrixFunc) gl).glLoadIdentity();
if (w <= h) ((GL2ES1) gl).glOrtho(-50.0, 50.0, -50.0 * (float) h / (float) w,
50.0 * (float) h / (float) w, -1.0, 1.0);
else ((GL2ES1) gl).glOrtho(-50.0 * (float) w / (float) h,
50.0 * (float) w / (float) h, -50.0, 50.0, -1.0, 1.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
boolean deviceChanged)
{
}
private void drawTriangle(GL gl)
{
((GL2) gl).glBegin(GL.GL_LINE_LOOP);
((GL2) gl).glVertex2f(0.0f, 25.0f);
((GL2) gl).glVertex2f(25.0f, -25.0f);
((GL2) gl).glVertex2f(-25.0f, -25.0f);
((GL2) gl).glEnd();
}
private void square(GL gl, float r, double d, double e) {
((GL2) gl).glColor3f(r,d,e); // The color for the square.
((GLMatrixFunc) gl).glTranslatef(0,0,0.5f); // Move square 0.5 units forward.
((GL2ES1) gl).glNormal3f(0,0,1); // Normal vector to square (this is actually the default).
((GL2) gl).glBegin(GL2.GL_TRIANGLE_FAN);
((GL2) gl).glVertex2f(-0.5f,-0.5f); // Draw the square (before the
((GL2) gl).glVertex2f(0.5f,-0.5f); // the translation is applied)
((GL2) gl).glVertex2f(0.5f,0.5f); // on the xy-plane, with its
((GL2) gl).glVertex2f(-0.5f,0.5f); // at (0,0,0).
((GL2) gl).glEnd();
}
private void drawsemicircle(GL2 gl) {
gl.glColor3f(1,1,0);
for (int i = 0; i < 13; i++) {
gl.glRotatef( 360f / 13, 0, 0, 1 );
gl.glBegin(GL2.GL_LINES);
gl.glVertex2f(0, 0);
gl.glVertex2f(0.75f, 0);
gl.glEnd();
}
drawDisk(gl, 0.5);
gl.glColor3f(0,0,0);
}
private void drawflower(GL2 gl) {
gl.glColor3f(0.8f, 0.8f, 0.9f);
gl.glBegin(GL2.GL_POLYGON);
gl.glVertex2f(-0.05f, 0);
gl.glVertex2f(0.05f, 0);
gl.glVertex2f(0.05f, 3);
gl.glVertex2f(-0.05f, 3);
gl.glEnd();
gl.glTranslatef(0, 3, 0);
gl.glRotated(180.0/46, 0, 0, 1);
gl.glColor3f(0.4f, 0.4f, 0.8f);
for (int i = 0; i < 3; i++) {
gl.glRotated(120, 0, 0, 1);
gl.glBegin(GL2.GL_POLYGON);
gl.glVertex2f(0,0);
gl.glVertex2f(0.5f, 0.1f);
gl.glVertex2f(1.5f,0);
gl.glVertex2f(0.5f, -0.1f);
gl.glEnd();
}
}
private void drawDisk(GL2 gl, double radius) {
gl.glBegin(GL2.GL_POLYGON);
for (int d = 0; d < 32; d++) {
double angle = 2*Math.PI/32 * d;
gl.glVertex2d( radius*Math.cos(angle), radius*Math.sin(angle));
}
gl.glEnd();
}
private void cube(GL2 gl) {
gl.glPushMatrix();
square(gl,1,0,0); // front face is red
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(180,0,1,0); // rotate square to back face
square(gl,0,1,1); // back face is cyan
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(-90,0,1,0); // rotate square to left face
square(gl,0,1,0); // left face is green
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(90,0,1,0); // rotate square to right face
square(gl,1,0,1); // right face is magenta
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(-90,1,0,0); // rotate square to top face
square(gl,0,0,1); // top face is blue
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(90,1,0,0); // rotate square to bottom face
square(gl,1,1,0); // bottom face is yellow
gl.glPopMatrix();
}
public void keyTyped(KeyEvent key)
{
// TODO Auto-generated method stub
}
public void keyPressed(KeyEvent key)
{
switch (key.getKeyCode()) {
case KeyEvent.VK_ESCAPE:
System.exit(0);
break;
default:
break;
}
}
public void keyReleased(KeyEvent key)
{
// TODO Auto-generated method stub
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started