0% found this document useful (0 votes)
7 views21 pages

1-In This Project You Will Create A Unique 3 Scene

The document outlines a project to create a unique 3D scene using JOGL and OpenGL with specific requirements including the use of at least six different shapes and transformation methods. It provides guidelines for development in Java, emphasizes adherence to the Google Java style guide, and suggests using JUNIT for testing. Sample Java code is included to demonstrate the implementation of the 3D scene and its components.

Uploaded by

SamYuan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views21 pages

1-In This Project You Will Create A Unique 3 Scene

The document outlines a project to create a unique 3D scene using JOGL and OpenGL with specific requirements including the use of at least six different shapes and transformation methods. It provides guidelines for development in Java, emphasizes adherence to the Google Java style guide, and suggests using JUNIT for testing. Sample Java code is included to demonstrate the implementation of the 3D scene and its components.

Uploaded by

SamYuan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

  

NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

home / study / engineering / computer science / computer science questions and answers / in this project you will create a unique 3 scene compo…

Question: In this project you will create a unique 3 scene composed of O… Post a question
Answers from our experts for your tough
homework questions
See this question in the app
Enter question
(3 bookmarks)
In this project you will create a unique 3 scene composed of OpenGL graphic components using
transformation methods.
Requirements: Continue to post
1. Using Netbeans or Eclipse, develop a JOGL application that displays a unique 3D scene. The scene has
20 questions remaining
the following speci cations:
a. Size: 640x480
b. Includes at least 6 different shapes
c. Uses at least 6 different transformation methods My Textbook Solutions
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 each method is functioning properly. (Hint: Using
JUNIT tests are recommended)

Introductio... The...
Expert Answer 2nd Edition 4th Edition

Heisenberg answered this


Was this answer helpful? 3 0
140 answers

Provided Java Open GL code done as per your requirements.

"Screen shot program code" for better understanding. Intro to...


"Code to copy" for run the program in your IDE.
10th Edition
Screen shot program code:
View all solutions

My3DScene.java:

Computer Science Chegg


tutors who can help right
now

Matthew Z.
967
University of Colora…

Nivita A.
10
Columbia University

Piyush A.
456
Indian Institute Of E…

Find me a tutor

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

MyShapes.java

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

Output:

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

TUTORS CHAT /
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

Code to copy:

MY3DScene.java:

// My3DScene.java

import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLJPanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public class My3DScene extends JPanel implements GLEventListener
{

public static void main(String[] args)


{
JFrame window = new JFrame("My 3D Graphics Scene");
My3DScene panel = new My3DScene();
window.setContentPane(panel);
window.pack(); // Set window size based on the preferred sizes of its contents.
window.setResizable(false);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation( // Center window on screen.
(screen.width - window.getWidth())/2,
(screen.height - window.getHeight())/2 );
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}

private MyShapes myShapes = new MyShapes(); // An instance of the MyShpaes class containing all the
shapes that I have drawn.
private int frameNumber; // Current frame number, increases by 1 in each frame.
private Timer animationTimer;

public My3DScene()
{
GLCapabilities caps = new GLCapabilities(null);

GLJPanel display = new GLJPanel(caps);


display.setPreferredSize( new Dimension(640,480) ); //sets display size of the viewing screen to 640-by-480
display.addGLEventListener(this);
setLayout(new BorderLayout());
add(display, BorderLayout.CENTER);

//start the animation


animationTimer = new Timer(20, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
frameNumber++; TUTORS CHAT /
display.repaint();
 
}

NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  
});
animationTimer.start();
}

//Methods of the GLEventListener interface


public void init(GLAutoDrawable drawable)
{
// called when the panel is created
GL2 gl2 = drawable.getGL().getGL2();

gl2.glEnable(GL2.GL_DEPTH_TEST); // Required for 3D drawing, not usually for 2D.


gl2.glLineWidth(2);
gl2.glShadeModel(GL2.GL_SMOOTH);
gl2.glEnable(GL2.GL_COLOR_MATERIAL);
gl2.glClearColor(0.5f,0.5f,0.5f,1); // Set background color

// The next three lines set up the coordinates system.


gl2.glMatrixMode(GL2.GL_PROJECTION);
gl2.glLoadIdentity();
gl2.glOrtho(-10, 10, -10, 10, -5, 5); //sets up the orthographic projection with the near and far perspective to
5.
gl2.glMatrixMode(GL2.GL_MODELVIEW);

gl2.glClearDepth(1.0f);
gl2.glDepthFunc(GL2.GL_LEQUAL);
gl2.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);

//turn transparency on
gl2.glEnable(GL2.GL_BLEND);
gl2.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

@SuppressWarnings("static-access")
public void display(GLAutoDrawable drawable)
{
GL2 gl2 = drawable.getGL().getGL2();
gl2.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // need depth buffer for 3D.

gl2.glLoadIdentity();

/* Draw the 3D Triangle. The drawTriangle method draws the shape with the center at (0,0).
* The image will be rotating in an in nite loop about the z-axis
* It will be uniformly scaled by 1.5 so that it's displayed proportionally on the window.
* It will be rotated 90 degrees about the line through the points (0,0,0) and (5,5,5).
* A translation is applied to move the triangle to the coordinate (-6,5,0).
*/

gl2.glPushMatrix();
gl2.glLineWidth(2);
gl2.glTranslated(-6.0,5.0,0);
gl2.glRotated(90,1.5,2,-3);
gl2.glScaled(1.5,1.5,1.5);
gl2.glRotated(frameNumber*0.7,0,0,1);
myShapes.drawTriangle(gl2);
gl2.glPopMatrix();

// Draw the 3D Cube.


gl2.glPushMatrix();
gl2.glLineWidth(1);
gl2.glTranslated(0,5.0,0);
gl2.glRotated(30,1.5,-2,3);
gl2.glScaled(1.5,1.5,1.5);
gl2.glRotated(-frameNumber*0.7,1,0,0);
myShapes.drawCube(gl2);
gl2.glPopMatrix();

// Draw the 3D Cylinder.


gl2.glPushMatrix();
gl2.glTranslated(2*Math.cos(.015*frameNumber) + 0, 2*Math.sin(.015*frameNumber) + 0, 0.0);
gl2.glTranslated(6.0,5.0,0);
gl2.glRotated(45,1.5,-2,3);
gl2.glScaled(1.6,1.6,1.6);
gl2.glRotated(-frameNumber*0.7,0,1,0);
myShapes.drawCylinder(gl2,0.5,1,32,10,5);
gl2.glPopMatrix();
TUTORS CHAT /
 
// Draw the 3D Plus symbol.

NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

gl2.glPushMatrix();
gl2.glLineWidth(2);
gl2.glTranslated(-12 + 24*(frameNumber % 500) / 500.0, 0, 0);
gl2.glRotated(45,1.5,-2,3);
gl2.glScaled(.275,.275,.275);
gl2.glRotated(-frameNumber*0.7,0,1,0);
myShapes.drawPlusSymbol(gl2);
gl2.glPopMatrix();

// Draw the 3D Tetrahedron.


gl2.glPushMatrix();
gl2.glLineWidth(1);
gl2.glTranslated(-6.0,-5.0,0);
gl2.glRotated(20,1.5,-2,3);
gl2.glScaled(.99*(frameNumber % 250) /250,.99*(frameNumber % 250) / 250,.99*(frameNumber % 250) /
250);
gl2.glRotated(-frameNumber*0.7,1,0,0);
myShapes.drawTetrahedron(gl2);
gl2.glPopMatrix();

// Draw the 3D Icosahedron.


gl2.glPushMatrix();
gl2.glLineWidth(2);
gl2.glTranslated(0.0,-5.0,0);
gl2.glRotated(30,1.5,-2,3);
gl2.glScaled(1.1,1.1,1.1);
gl2.glRotated(-frameNumber*0.7,1,0,0);
myShapes.drawIcosahedron(gl2);
gl2.glPopMatrix();

// Draw the 3D Diamond.


gl2.glPushMatrix();
gl2.glLineWidth(2);
gl2.glTranslated(6.0,-5.0,0);
gl2.glRotated(35,1.5,-2,3);
gl2.glScaled(.35,.35,.35);
gl2.glRotated(-frameNumber*0.7,0,1,0);
myShapes.drawDiamond(gl2);
gl2.glPopMatrix();
}

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

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)


{
}

public void dispose(GLAutoDrawable arg0) {


}
}

MyShapes.java:

//MyShapes.java
import com.jogamp.opengl.GL2;

public class MyShapes


{
//Creates a 3D Triangle with only the edges drawn.
public static void drawTriangle(GL2 gl2)
{
//Draws the triangle using a GL_LINE_LOOP, so only the edges are shown and the triangle is not lled in.
gl2.glBegin(GL2.GL_LINE_LOOP);

// Front side
gl2.glColor3f( 1.0f, 0.0f, 0.0f ); // Red
gl2.glVertex3f( 0f, 1.5f, 0.0f ); // Top Of Triangle (Front)

gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green


gl2.glVertex3f( -.5f, -.5f, .5f ); // Left Of Triangle (Front)

gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue TUTORS CHAT /


gl2.glVertex3f( .5f, -.5f, .5f ); // Right Of Triangle (Front)
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  
// Right side
gl2.glColor3f( 1.0f, 0.0f, 0.0f ); // Red
gl2.glVertex3f( 0f, 1.5f, 0.0f ); // Top Of Triangle (Right)

gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue


gl2.glVertex3f( .5f, -.5f, .5f ); // Left Of Triangle (Right)

gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green


gl2.glVertex3f( .5f, -.5f, -.5f ); // Right Of Triangle (Right)

// Back side
gl2.glColor3f( 1.0f, 0.0f, 0.0f ); // Red
gl2.glVertex3f( 0f, 1.5f, 0.0f ); // Top Of Triangle (Back)

gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green


gl2.glVertex3f( .5f, -.5f, -.5f ); // Left Of Triangle (Back)

gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue


gl2.glVertex3f( -.5f, -.5f, -.5f ); // Right Of Triangle (Back)

//Left side
gl2.glColor3f( 1.0f, 0.0f, 0.0f ); // Red
gl2.glVertex3f( 0f, 1.5f, 0.0f ); // Top Of Triangle (Left)

gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue


gl2.glVertex3f( -.5f, -.5f, -.5f ); // Left Of Triangle (Left)

gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green


gl2.glVertex3f( -.5f, -.5f, .5f ); // Right Of Triangle (Left)

gl2.glEnd(); // Done Drawing 3d triangle (Pyramid)


gl2.glFlush();
}

//Creates a square, which will be used to create the 6 sides of a 3D cube.

public static void square(GL2 gl2)


{
//Will use a GL_TRIANGLE_FAN in order to create a solid lled in square.
// Each of the 4 corners of the square will be a different color
gl2.glBegin(GL2.GL_TRIANGLE_FAN);
gl2.glColor3f( 1.0f, 0.0f, 0.0f ); // Red
gl2.glVertex3d(-0.5, -0.5, 0.5); // Bottom left corner

gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green


gl2.glVertex3d(0.5, -0.5, 0.5); // Bottom right corner

gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue


gl2.glVertex3d(0.5, 0.5, 0.5); //Top right corner

gl2.glColor3f( 1.0f, 1.0f, 0.0f ); // Yellow


gl2.glVertex3d(-0.5, 0.5, 0.5); //Top left corner
gl2.glEnd();

//Will use a GL_LINE_LOOP in order to outline the edges of the square in black
gl2.glColor3d(0,0,0); //black
gl2.glBegin(GL2.GL_LINE_LOOP);
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();
}

// Creates a 3D cube using the square method to create each of the 6 sides.

public static void drawCube(GL2 gl2)


{
gl2.glPushMatrix();
square(gl2); //Front face
gl2.glPopMatrix();

gl2.glPushMatrix();
gl2.glRotated(90, 0, 1, 0); //Right face
square(gl2);
gl2.glPopMatrix();

gl2.glPushMatrix();
gl2.glRotated(-90, 1, 0, 0); //Top face
square(gl2);
TUTORS CHAT /
gl2.glPopMatrix();
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  
gl2.glPushMatrix();
gl2.glRotated(180, 0, 1, 0); //Back face
square(gl2);
gl2.glPopMatrix();

gl2.glPushMatrix();
gl2.glRotated(-90, 0, 1, 0); //Left face
square(gl2);
gl2.glPopMatrix();

gl2.glPushMatrix();
gl2.glRotated(90, 1, 0, 0); //Bottom face
square(gl2);
gl2.glPopMatrix();
gl2.glFlush();
}

//Creates a transparent 3D cylinder with a given radius, number of slices, number of stacks, and number of
rings.
public static void drawCylinder(GL2 gl2, double radius, double height, int slices, int stacks, int rings)
{
for (int j = 0; j < stacks; j++)
{
double z1 = (height/stacks) * j;
double z2 = (height/stacks) * (j+1);
gl2.glBegin(GL2.GL_QUAD_STRIP);
for (int i = 0; i <= slices; i++)
{
double longitude = (2*Math.PI/slices) * i;
double sinLong = Math.sin(longitude);
double cosLong = Math.cos(longitude);
double x = cosLong;
double y = sinLong;
gl2.glNormal3d(x,y,0);

gl2.glColor4f( 1.0f, 0.0f, 0.0f, 0.5f ); // Transparent red


gl2.glVertex3d(radius*x,radius*y,z2);
gl2.glVertex3d(radius*x,radius*y,z1);
}
gl2.glEnd();
}
if (rings > 0){ // draw top and bottom
gl2.glNormal3d(0,0,1);
for (int j = 0; j < rings; j++)
{
double d1 = (1.0/rings) * j;
double d2 = (1.0/rings) * (j+1);
gl2.glBegin(GL2.GL_QUAD_STRIP);
for (int i = 0; i <= slices; i++)
{
double angle = (2*Math.PI/slices) * i;
double sin = Math.sin(angle);
double cos = Math.cos(angle);
gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue
gl2.glVertex3d(radius*cos*d1,radius*sin*d1,height);
gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green
gl2.glVertex3d(radius*cos*d2,radius*sin*d2,height);
}
gl2.glEnd();
}

gl2.glNormal3d(0,0,-1);
for (int j = 0; j < rings; j++)
{
double d1 = (1.0/rings) * j;
double d2 = (1.0/rings) * (j+1);
gl2.glBegin(GL2.GL_QUAD_STRIP);
for (int i = 0; i <= slices; i++)
{
double angle = (2*Math.PI/slices) * i;
double sin = Math.sin(angle);
double cos = Math.cos(angle);

gl2.glColor3f( 0.0f, 0.0f, 1.0f ); // Blue


gl2.glVertex3d(radius*cos*d2,radius*sin*d2,0);

gl2.glColor3f( 0.0f, 1.0f, 0.0f ); // Green

gl2.glVertex3d(radius*cos*d1,radius*sin*d1,0);
} TUTORS CHAT /
gl2.glEnd();
 
}

NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  
}

gl2.glFlush();
}

// Creates a 3D plus symbol using an Indexed Face Set.


public static void drawPlusSymbol(GL2 gl2)
{
// An array of all the vertices of the plus symbol in no particular order.
double[][] vertices = new double[][]{
{ 2, -2, 2 },
{ 2, -2, -2 },
{ 2, 1, -2 },
{ 2, 1, 2 },
{ 1.5, 5.0, 0 },
{ -1.5, 5.0, 0 },
{ -2, -2, 2 },
{ -2, 1, 2 },
{ -2, 1, -2 },
{ -2, -2, -2 },
{ 1.5, -5.0, 0 },
{ -1.5, -5.0, 0 },
{ 7, 1.5, 0 },
{ 7, -1.5, 0 },
{ -7, 1.5, 0 },
{ -7, -1.5, 0 },
};

int[][] faces = new int[][] {


{ 0, 1, 2, 3 },
{ 3, 2, 4 },
{ 7, 3, 4, 5 },
{ 2, 8, 5, 4 },
{ 5, 8, 7 },
{ 0, 3, 7, 6 },
{ 2, 1, 9, 8 },
{ 6, 7, 8, 9 },
{ 0, 1, 10 },
{ 6, 9, 11 },
{ 6, 0, 10, 11 },
{ 9, 1, 10, 11 },
{ 3, 0, 13, 12 },
{ 1, 2, 12, 13 },
{ 2, 3, 12 },
{ 0, 1, 13 },
{ 6, 7, 14, 15 },
{ 9, 8, 14, 15 },
{ 7, 8, 14 },
{ 6, 9, 15 },
};

double[][] faceColors = new double[][] {


{1, 0, 0}, //red side
{1, 1, 0}, //yellow top side
{0, 0, 1}, //blue top side
{0, 0, 1}, //blue top side
{1, 1, 0}, //yellow top side
{0, 1, 0}, //green side
{0, 1, 0}, //green side
{1, 0, 0}, // red side
{1, 1, 0}, // yellow bottom side
{1, 1, 0}, // yellow bottom side
{0, 0, 1}, //blue bottom side
{0, 0, 1}, //blue bottom side

{0, 0, 1}, //blue right side


{0, 0, 1}, //blue right side
{1, 0, 0}, //yellow right side
{1, 0, 0}, //yellow right side

{0, 0, 1}, //blue left side


{0, 0, 1}, //blue left side
{1, 0, 0}, //yellow left side
{1, 0, 0}, //yellow left side
};

gl2.glPushMatrix();

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


{
TUTORS CHAT /
gl2.glColor4d(0,0,0, .3); //color the faces of the star shape a transparent black
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

gl2.glBegin(GL2.GL_TRIANGLE_FAN);
for (int j = 0; j < faces[i].length; j++)
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

//draw edges colored in black


gl2.glColor3f(0,0,0);
for (int i = 0; i < faces.length; i++)
{
gl2.glBegin(GL2.GL_LINE_LOOP);
for (int j = 0; j < faces[i].length; j++)
{
gl2.glColor3dv(faceColors[j], 0 );

int vertexNum = faces[i][j];


gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

gl2.glPopMatrix();
gl2.glFlush();
}

// Creates 3D Tetrahedron using an Indexed Face Set.


public static void drawTetrahedron(GL2 gl2)
{
// An array of all the vertices of the tetrahedron in no particular order.
double[][] vertices = new double[][] {
{1, -1, -1},
{-1, -1, 1},
{-1, 1, -1},
{1, 1, 1}
};

int[][] faces = new int[][] {


{0, 3, 2},
{3, 0, 1},
{0, 2, 1},
{2, 3, 1}
};

double[][] faceColors = new double[][] {


{1, 0, 0}, // red
{0, 1, 0}, // green
{0, 0, 1}, // blue
{1, 1, 0} // yellow
};

gl2.glPushMatrix();

//color the faces of the tetrahedron


for (int i = 0; i < faces.length; i++)
{
gl2.glColor3dv(faceColors[i], 0 );

gl2.glBegin(GL2.GL_TRIANGLE_FAN);
for (int j = 0; j < faces[i].length; j++)
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

//draw edges colored in black


gl2.glColor3f(0,0,0);
for (int i = 0; i < faces.length; i++)
{
gl2.glBegin(GL2.GL_LINE_LOOP);
for (int j = 0; j < faces[i].length; j++)
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 ); TUTORS CHAT /
}
 
gl2.glEnd();

NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  
}
gl2.glPopMatrix();
gl2.glFlush();
}

// Creates a transparent 3D Icosahedron using an Indexed Face Set.


public static void drawIcosahedron(GL2 gl2)
{
double[][] vertices = new double[][]{

// An array of all the vertices of the tetrahedron in no particular order.


{-1, -0.618034, 0},
{0, 1, 0.618034},
{0, 1, -0.618034},
{1, 0.618034, 0},
{1, -0.618034, 0},
{0, -1, -0.618034},
{0, -1, 0.618034},
{0.618034, 0, 1},
{-0.618034, 0, 1},
{0.618034, 0, -1},
{-0.618034, 0, -1},
{-1, 0.618034, 0}
};

int[][] faces = new int[][] {


{3, 7, 1},
{4, 7, 3},
{6, 7, 4},
{8, 7, 6},
{7, 8, 1},
{9, 4, 3},
{2, 9, 3},
{2, 3, 1},
{11, 2, 1},
{10, 2, 11},
{10, 9, 2},
{9, 5, 4},
{6, 4, 5},
{0, 6, 5},
{0, 11, 8},
{11, 1, 8},
{10, 0, 5},
{10, 5, 9},
{0, 8, 6},
{0, 10, 11}
};

// each face color will have a 4th column to indicate the level of transparency.
double[][] faceColors = new double[][] {
{1, 0, 0, 0.4},
{0, 1, 0, 0.4},
{0, 0, 1, 0.4},
{1, 1, 0, 0.4},
{0, 1, 1, 0.4},
{1, 0, 0, 0.4},
{0, 1, 0, 0.4},
{0, 0, 1, 0.4},
{1, 1, 0, 0.4},
{0, 1, 1, 0.4},
{1, 0, 0, 0.4},
{0, 1, 0, 0.4},
{0, 0, 1, 0.4},
{1, 1, 0, 0.4},
{0, 1, 1, 0.4},
{1, 0, 0, 0.4},
{0, 1, 0, 0.4},
{0, 0, 1, 0.4},
{1, 1, 0, 0.4},
{0, 1, 1, 0.4},
{0, 0, 1, 0.4},
};

gl2.glPushMatrix();
//color the faces of the tetrahedron
for (int i = 0; i < faces.length; i++)
{
gl2.glColor4dv(faceColors[i], 0 );
TUTORS CHAT /
gl2.glBegin(GL2.GL_TRIANGLE_FAN);
 
for (int j = 0; j < faces[i].length; j++) Solutions

NEW!
Textbook Expert Q&A Study Pack Practice Search  
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

//draw edges colored in black


gl2.glColor3f(0,0,0);
for (int i = 0; i < faces.length; i++)
{
gl2.glBegin(GL2.GL_LINE_LOOP);
for (int j = 0; j < faces[i].length; j++)
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

gl2.glPopMatrix();
gl2.glFlush();
}

//Creates a 3D diamond looking shape using an Indexed Face Set.


public static void drawDiamond(GL2 gl2)
{
// An array of all the vertices of the diamond shape in no particular order.
double[][] vertices = new double[][]{
{ 2, -2, 2 },
{ 2, -2, -2 },
{ 2, 1, -2 },
{ 2, 1, 2 },
{ 1.5, 5.0, 0 },
{ -1.5, 5.0, 0 },
{ -2, -2, 2 },
{ -2, 1, 2 },
{ -2, 1, -2 },
{ -2, -2, -2 },
{ 1.5, -5.0, 0 },
{ -1.5, -5.0, 0 },
};

int[][] faces = new int[][] {


{ 0, 1, 2, 3 }, // middle side
{ 3, 2, 4 }, // top side
{ 7, 3, 4, 5 }, //top side
{ 2, 8, 5, 4 }, // top side
{ 5, 8, 7 }, // top side
{ 0, 3, 7, 6 }, // middle side
{ 2, 1, 9, 8 }, // middle side
{ 6, 7, 8, 9 }, // middle side
{ 0, 1, 10 }, //bottom side
{ 6, 9, 11 }, //bottom side
{ 6, 0, 10, 11 }, //bottom side
{ 9, 1, 10, 11 }, //bottom side
};

double[][] faceColors = new double[][] {


{1,0,0}, //red middle side
{1,1,0}, //yellow top side
{0,0,1}, //blue top side
{0,0,1}, //blue top side
{1,1,0}, //red top side
{0,1,0}, //green middle side
{0,1,0}, //green middle side
{1,0,0}, // red middle side
{1,1,0}, // yellow bottom side
{1,1,0}, // yellow bottom side
{0,0,1}, //blue bottom side
{0,0,1}, //blue bottom side

};

gl2.glPushMatrix();
//color the faces of the diamond shape
for (int i = 0; i < faces.length; i++)
{
gl2.glColor3dv(faceColors[i], 0 );
TUTORS CHAT /
 
gl2.glBegin(GL2.GL_TRIANGLE_FAN);

NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  
for (int j = 0; j < faces[i].length; j++)
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

//draw edges colored in black


gl2.glColor3f(0,0,0);
for (int i = 0; i < faces.length; i++)
{
gl2.glBegin(GL2.GL_LINE_LOOP);
for (int j = 0; j < faces[i].length; j++)
{
int vertexNum = faces[i][j];
gl2.glVertex3dv( vertices[vertexNum], 0 );
}
gl2.glEnd();
}

gl2.glPopMatrix();
gl2.glFlush();
}
}

Comment


Practice with similar questions

Q: 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 speci cations: a. Size: minimum 640x480 b. Includes at least 6 different
shapes c. Uses at least 6 different transformation...

A: See answer

Questions viewed by other students

Q: Project 3 Three js Project Overview In this project you will create a unique 3D animated scene composed of Three.js
graphic components. The scene should include animation, lighting and multiple objects. Requirements: 1. Using
Three.js create a unique 3D animated scene. The scene has the following speci cations: a. Size: minimum of 640x480
b. Includes at least 6 different shapes c...

A: See answer

Q: home / study / engineering / computer science / computer science questions and answers / In This Project You Will
Create A Unique 3 Graphics Scene Composed Of OpenGL Graphic Components ... Your question has been answered
Let us know if you got a helpful answer. Rate this answer Question: In this project you will create a unique 3 graphics
scene composed of OpenGL graphic components...

A: See answer 100% (1 rating)

Show more 

ABOUT CHEGG

LEGAL & POLICIES

CHEGG PRODUCTS AND SERVICES


TUTORS CHAT /
CHEGG NETWORK
  
NEW!
Textbook Solutions Expert Q&A Study Pack Practice Search  

CUSTOMER SERVICE

© 2003-2020 Chegg Inc. All rights reserved.

TUTORS CHAT /

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy