Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

Project 2 . . . . . .. . .

Project 2 . . . . . .. . .

Project 2 . . . . . .. . .

Question Description

Below is a good start for project 2

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import com.jogamp.opengl.*;

import com.jogamp.opengl.awt.*;

/**

* Use JOGL to draw a simple cube

* with each face being a different color. Rotations

* can be applied with the arrow keys, the page up

* key, and the page down key. The home key will set

* all rotations to 0. Initial rotations about the

* x, y, and z axes are 15, -15, and 0.

*

* This program is meant as an example of using modeling

* transforms, with glPushMatrix and glPopMatrix.

*

* Note that this program does not use lighting.

*/

public class UnlitCube extends GLJPanel implements GLEventListener, KeyListener {

/**

* A main routine to create and show a window that contains a

* panel of type UnlitCube. The program ends when the

* user closes the window.

*/

public static void main(String[] args) {

JFrame window = new JFrame(“A Simple Unlit Cube — ARROW KEYS ROTATE”);

UnlitCube panel = new UnlitCube();

window.setContentPane(panel);

window.pack();

window.setLocation(50,50);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

window.setVisible(true);

panel.requestFocusInWindow();

}

/**

* Constructor for class UnlitCube.

*/

public UnlitCube() {

super( new GLCapabilities(null) ); // Makes a panel with default OpenGL “capabilities”.

setPreferredSize( new Dimension(500,500) );

addGLEventListener(this); // A listener is essential! The listener is where the OpenGL programming lives.

addKeyListener(this);

}

//——————– methods to draw the cube ———————-

double rotateX = 15; // rotations of the cube about the axes

double rotateY = -15;

double rotateZ = 0;

private void square(GL2 gl2, double r, double g, double b) {

gl2.glColor3d(r,g,b);

gl2.glBegin(GL2.GL_TRIANGLE_FAN);

gl2.glVertex3d(-0.5, -0.5, 0.5);

gl2.glVertex3d(0.5, -0.5, 0.5);

gl2.glVertex3d(0.5, 0.5, 0.5);

gl2.glVertex3d(-0.5, 0.5, 0.5);

gl2.glEnd();

}

private void cube(GL2 gl2, double size) {

gl2.glPushMatrix();

gl2.glScaled(size,size,size); // scale unit cube to desired size

// Move the squares to offset 3,3

gl2.glTranslated(3,3,0);

square(gl2,1, 0, 0); // red front face

gl2.glPushMatrix();

gl2.glRotated(90, 0, 1, 0);

square(gl2,0, 1, 0); // green right face

gl2.glPopMatrix();

gl2.glPushMatrix();

gl2.glRotated(-90, 1, 0, 0);

square(gl2,0, 0, 1); // blue top face

gl2.glPopMatrix();

gl2.glPushMatrix();

gl2.glRotated(180, 0, 1, 0);

square(gl2,0, 1, 1); // cyan back face

gl2.glPopMatrix();

gl2.glPushMatrix();

gl2.glRotated(-90, 0, 1, 0);

square(gl2,1, 0, 1); // magenta left face

gl2.glPopMatrix();

gl2.glPushMatrix();

gl2.glRotated(90, 1, 0, 0);

square(gl2,1, 1, 0); // yellow bottom face

gl2.glPopMatrix();

gl2.glPopMatrix(); // Restore matrix to its state before cube() was called.

}

//——————– GLEventListener Methods ————————-

/**

* The display method is called when the panel needs to be redrawn.

* The is where the code goes for drawing the image, using OpenGL commands.

*/

public void display(GLAutoDrawable drawable) {

GL2 gl2 = drawable.getGL().getGL2(); // The object that contains all the OpenGL methods.

gl2.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );

gl2.glLoadIdentity(); // Set up modelview transform.

gl2.glRotated(rotateZ,0,0,1);

gl2.glRotated(rotateY,0,1,0);

gl2.glRotated(rotateX,1,0,0);

cube(gl2,1);

// Add an Index Face set

// Note using Graph paper is the best way to figure these vertices.

// You can make about any shape you want this way

double[][] vertexList =

{ {1,-0.5,1}, {1,-.5,-1}, {1,.5,-1}, {1,.5,1}, {.75,.75,0},

{-.75,.75,0}, {-1,-.5,1}, {-1,.5,1}, {-1,.5,-1}, {-1,-.5,-1} };

int[][] faceList =

{ {0,1,2,3}, {3,2,4}, {7,3,4,5}, {2,8,5,4}, {5,8,7},

{0,3,7,6}, {0,6,9,1}, {2,1,9,8}, {6,7,8,9} };

for (int i = 0; i < faceList.length; i++) {

gl2.glColor3f(1,0,1 ); // Set color for face number i.

gl2.glBegin(GL2.GL_TRIANGLE_FAN);

for (int j = 0; j < faceList[i].length; j++) {

int vertexNum = faceList[i][j]; // Index for vertex j of face i.

double[] vertexCoords = vertexList[vertexNum]; // The vertex itself.

gl2.glVertex3dv( vertexCoords, 0 );

}

gl2.glEnd();

// You can add more shapes here.

}

} // end display()

public void init(GLAutoDrawable drawable) {

// called when the panel is created

GL2 gl2 = drawable.getGL().getGL2();

gl2.glMatrixMode(GL2.GL_PROJECTION);

// gl2.glOrtho(-1, 1 ,-1, 1, -1, 1);

// Changing this is your coordinate -x,x,-y,y,-z,z)

// Larger numbers zooms out.

// Play with this to make sure you see your shapes.

gl2.glOrtho(-5, 5 ,-5, 5, -5, 5);

gl2.glMatrixMode(GL2.GL_MODELVIEW);

gl2.glClearColor( 0, 0, 0, 1 );

gl2.glEnable(GL2.GL_DEPTH_TEST);

}

public void dispose(GLAutoDrawable drawable) {

// called when the panel is being disposed

}

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

// called when user resizes the window

}

// —————- Methods from the KeyListener interface ————–

public void keyPressed(KeyEvent evt) {

int key = evt.getKeyCode();

if ( key == KeyEvent.VK_LEFT )

rotateY -= 15;

else if ( key == KeyEvent.VK_RIGHT )

rotateY += 15;

else if ( key == KeyEvent.VK_DOWN)

rotateX += 15;

else if ( key == KeyEvent.VK_UP )

rotateX -= 15;

else if ( key == KeyEvent.VK_PAGE_UP )

rotateZ += 15;

else if ( key == KeyEvent.VK_PAGE_DOWN )

rotateZ -= 15;

else if ( key == KeyEvent.VK_HOME )

rotateX = rotateY = rotateZ = 0;

repaint();

}

public void keyReleased(KeyEvent evt) {

}

public void keyTyped(KeyEvent evt) {

}

}

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20