Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here are the mentioned codes needed: Code1Lab.java: import javax.swing.JPanel; import org.jogamp.java3d.*; import org.jogamp.java3d.utils.geometry.ColorCube; import org.jogamp.vecmath.*; public class CodeLab1 extends JPanel { private static final long

image text in transcribed

Here are the mentioned codes needed:

Code1Lab.java:

import javax.swing.JPanel; import org.jogamp.java3d.*; import org.jogamp.java3d.utils.geometry.ColorCube; import org.jogamp.vecmath.*;

public class CodeLab1 extends JPanel { private static final long serialVersionUID = 1L;

private static Shape3D lineShape(int n) { float r = 0.6f, x, y; // vertex at 0.06 away from origin Point3f coor[] = new Point3f[n]; if(n

LineArray lineArr = new LineArray(1000, LineArray.COLOR_3 | LineArray.COORDINATES); for (int i = 0; i

for (int i = 0; i

/* a function to create and return the scene BranchGroup */ public static BranchGroup createScene() { BranchGroup sceneBG = new BranchGroup(); // create 'objsBG' for content TransformGroup sceneTG = new TransformGroup(); // create a TransformGroup (TG) sceneBG.addChild(sceneTG); // add TG to the scene BranchGroup sceneBG.addChild(CommonsXY.rotateBehavior(10000, sceneTG)); // make sceneTG continuously rotating sceneTG.addChild(lineShape(2)); sceneBG.compile(); // optimize objsBG return sceneBG; }

/* the main entrance of the application via 'MyGUI()' of "CommonXY.java" */ public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { CommonsXY.setEye(new Point3d(1.35, 0.35, 2.0)); new CommonsXY.MyGUI(createScene(), "CB's Lab 2"); } }); } }

CommonsXY.java:

import java.awt.BorderLayout; import java.awt.GraphicsConfiguration; import javax.swing.JFrame; import javax.swing.JPanel; import org.jogamp.java3d.*; import org.jogamp.java3d.utils.geometry.ColorCube; import org.jogamp.java3d.utils.universe.SimpleUniverse; import org.jogamp.vecmath.*;

public class CommonsXY extends JPanel { private static final long serialVersionUID = 1L; public final static Color3f Red = new Color3f(1.0f, 0.0f, 0.0f); public final static Color3f Green = new Color3f(0.0f, 1.0f, 0.0f); public final static Color3f Blue = new Color3f(0.0f, 0.0f, 1.0f); public final static Color3f Yellow = new Color3f(1.0f, 1.0f, 0.0f); public final static Color3f Cyan = new Color3f(0.0f, 1.0f, 1.0f); public final static Color3f Orange = new Color3f(1.0f, 0.5f, 0.0f); public final static Color3f Magenta = new Color3f(1.0f, 0.0f, 1.0f); public final static Color3f White = new Color3f(1.0f, 1.0f, 1.0f); public final static Color3f Grey = new Color3f(0.5f, 0.5f, 0.5f); public final static Color3f[] Clrs = {Blue, Green, Red, Yellow, Cyan, Orange, Magenta, Grey}; public final static int clr_num = 8;

private static JFrame frame; private static Point3d eye = new Point3d(1.35, 0.35, 2.0);

/* a function to create a rotation behavior and refer it to 'my_TG' */ public static RotationInterpolator rotateBehavior(int r_num, TransformGroup my_TG) {

my_TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, r_num); RotationInterpolator rot_beh = new RotationInterpolator( rotationAlpha, my_TG, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rot_beh.setSchedulingBounds(bounds); return rot_beh; } /* a function to position viewer to 'eye' location */ public static void defineViewer(SimpleUniverse su) {

TransformGroup viewTransform = su.getViewingPlatform().getViewPlatformTransform(); Point3d center = new Point3d(0, 0, 0); // define the point where the eye looks at Vector3d up = new Vector3d(0, 1, 0); // define camera's up direction Transform3D view_TM = new Transform3D(); view_TM.lookAt(eye, center, up); view_TM.invert(); viewTransform.setTransform(view_TM); // set the TransformGroup of ViewingPlatform }

/* a function to build the content branch and attach to 'scene' */ private static BranchGroup createScene() { BranchGroup scene = new BranchGroup(); TransformGroup content_TG = new TransformGroup(); // create a TransformGroup (TG) content_TG.addChild(new ColorCube(0.4f)); scene.addChild(content_TG); // add TG to the scene BranchGroup scene.addChild(rotateBehavior(10000, content_TG)); // make TG continuously rotating return scene; } public static void setEye(Point3d eye_position) { eye = eye_position; }

/* a constructor to set up and run the application */ public CommonsXY(BranchGroup sceneBG) { GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas_3D = new Canvas3D(config); SimpleUniverse su = new SimpleUniverse(canvas_3D); // create a SimpleUniverse defineViewer(su); // set the viewer's location

sceneBG.compile(); su.addBranchGraph(sceneBG); // attach the scene to SimpleUniverse setLayout(new BorderLayout()); add("Center", canvas_3D); frame.setSize(600, 600); // set the size of the JFrame frame.setVisible(true); }

public static void main(String[] args) { frame = new JFrame("XY's Commons"); // call constructor with 'createScene()' frame.getContentPane().add(new CommonsXY(createScene())); } public static class MyGUI extends JFrame { private static final long serialVersionUID = 1L; public MyGUI(BranchGroup branchGroup, String title) { frame = new JFrame(title); // call constructor with 'branchGroup' frame.getContentPane().add(new CommonsXY(branchGroup)); pack(); } } }

(A) Modify either your or the provided CodeLab1.java file to create within the package of your Labl a new class CodeAssign1.java that has four functions as described below: 1. Function fi has two parameters. The first is yColor in an instance of Color3f, and the second is length in the type of float. This function creates a three-axis frame and returns an instance of) Shape 3D with the frame being its geometry. (a) Each of the three axes is a line segment in the length of length. While the three axes are perpendicular to each other, their joint point is at the origin of the SimpleUniverse. (b) Among the three axes, the Z-axis points towards the viewer, X-axis horizontally to the right, and Y-axis vertically upwards. (C) The color of the Z-axis is red, X-axis green, and Y-axis in the color of yColor. 2. Function f2 has three parameters color, size, and scale as instances of classes Color3f, Point3f, and Vector2f respectively. This function returns a Shape3D whose geometry is a rectangle colored uniformly in color. While the center of the rectangle is size.z off the origin on the Z-axis, its surface normal faces the viewer and its size is 2 * size. x * scale.x in width and 2 * size.y * scale.y in height. 3. Function f3 has a single parameter of integer n and returns a Shape3D. This function returns a ColorCube (0.35) when n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 17th International Conference Dasfaa 2012 Busan South Korea April 2012 Proceedings Part 1 Lncs 7238

Authors: Sang-goo Lee ,Zhiyong Peng ,Xiaofang Zhou ,Yang-Sae Moon ,Rainer Unland ,Jaesoo Yoo

2012 Edition

364229037X, 978-3642290374

More Books

Students also viewed these Databases questions

Question

1. Does your voice project confidence? Authority?

Answered: 1 week ago