Question: CodeLab1.java import javax.swing.JPanel; import org.jogamp.java3d.*; import org.jogamp.vecmath.*; public class CodeLab1 extends JPanel { private static final long serialVersionUID = 1L; private static Shape3D lineShape() {

 CodeLab1.java import javax.swing.JPanel; import org.jogamp.java3d.*; import org.jogamp.vecmath.*; public class CodeLab1 extends

JPanel { private static final long serialVersionUID = 1L; private static Shape3D

CodeLab1.java

import javax.swing.JPanel;

import org.jogamp.java3d.*; import org.jogamp.vecmath.*;

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

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

LineArray lineArr = new LineArray(10, 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(Commons.rotateBehavior(10000, sceneTG)); // make sceneTG continuously rotating sceneTG.addChild(lineShape()); 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() { Commons.setEye(new Point3d(1.35, 0.35, 2.0)); new Commons.MyGUI(createScene(), "XY's Lab 1"); } }); } }

Commons.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 Commons 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 Commons(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 Commons(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 Commons(branchGroup)); pack(); } } }

Assignment #1 (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 2 has three parameters color, size, and scale as instances of classes Color3f, Point3f, and Vector2f respectively. This function returns a Shape 3D 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 Shape 3D. This function returns a ColorCube (0.35) when n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!