説明およびサンプルコード 2
Java3D010クラスの開始
前述のとおり、完全なプログラムリストはリスト15に示してあります。Sceneクラスのコンストラクタが始まるまでのコードはすべて、全体的に単純です。そのコードでは、GUIの作成や[Replot]ボタンの処理などを行っています。
Sceneクラスのコンストラクタの開始
Sceneクラスは、ユニバースのインスタンス化が行われる内部クラスです。[Replot]ボタンの機能の1つは、古いSceneオブジェクトを廃棄し、新しいSceneオブジェクトを作成することです。新しいSceneオブジェクトを作成するときには、図8の右側のGUIにユーザーが入力した変換パラメータ値に従って、オブジェクトが作成されます。
リスト5は、Sceneクラスのコンストラクタの開始を示しています。
Scene(){//constructor
//Create a temporary TransformGroup object.
System.out.println("\nDefault xform matrix.");
TransformGroup tempXformGroup =
new TransformGroup();
Transform3D tempXform = new Transform3D();
tempXformGroup.getTransform(tempXform);
displayMatrix(tempXform);
//Construct the universe.
createACanvas();
createTheUniverse();
一時的なTransformGroupオブジェクト
リスト5では、最初に、一時的なTransformGroupオブジェクトを作成しています。これは、新しいTransformGroupオブジェクトに含まれる既定の変換行列を表示することだけが目的です。既定の変換行列は、図10の左上に示されているように恒等行列です。
ビッグバン
リスト5のコードは、次の2つのメソッドを呼び出してユニバースを作成します。
- createACanvas
- createTheUniverse
この2つのメソッドのコードは、Java 3Dに関する以前のレッスンで説明したコードに似ているか、または同一であるため、このレッスンでその説明を繰り返すことはしません。
2つのColorCubeオブジェクトを作成および準備する
リスト6では、図8に示されている2種類のColorCubeオブジェクトを作成します。そのうちの1つは、青色の面がz軸に対して垂直になるように、垂直軸を中心に回転されます。このオブジェクトは、blueCubeGroupという名前のTransformGroupに子として追加されます。
//The following ColorCube displays its red face // without being rotated. ColorCube redCube = new ColorCube(0.125f); //Create a cube and rotate it to cause it to display // its blue face. TransformGroup blueCubeGroup = tiltTheAxes(new ColorCube(0.125f), 0.0d,//x-axis 3*Math.PI/2.0d,//y-axis 0.0d);//z-axis
blueCubeGroupに可視軸を追加する
リスト7では、getAxesGroupメソッドを呼び出して、1組の可視軸(細長いColorCubeオブジェクトで構成)を取得します。これらはblueCubeGroupに子として追加され、図8に示されているように、青色の立方体から軸が突き出したような状態になります。
TransformGroup blueCubeAxes = getAxesGroup(); blueCubeGroup.addChild(blueCubeAxes);
変換階層を構成する
コース料理で言えば、前菜が終わり、いよいよメイン料理です。この後のコードでは、LeafオブジェクトとTransformGroupオブジェクトの階層を構成します。
階層内の変換は、図8のGUIにユーザーが入力するパラメータ値を使用して構成されます。このコードは、Leafからルートに向かう階層を構成することに注意してください。これは、GUIにリストされている変換とは逆の順序です。
拡大縮小変換を作成および表示する
リスト8では、blueCubeGroupに適用される拡大縮小変換を作成します。図7の階層によると、blueCubeGroupは青色の立方体(前面が青色の匿名ColorCube)とblueCubeAxesを含みます。
TransformGroup scaledGroup = scale(
blueCubeGroup,
new Vector3d(sx,sy,sz));
//Display the scaling transform matrix.
System.out.println("Scaling xform matrix");
scaledGroup.getTransform(tempXform);
displayMatrix(tempXform);
リスト8は次に、拡大縮小変換行列を表示します。
平行移動変換を作成および表示する
リスト9では、平行移動変換を作成および表示します(これは、図8のGUIの下部近くにリストされている平行移動変換です)。この変換は、scaledGroupに適用されます。図7の階層によると、scaledGroupはblueCubeGroupを含み、さらに後者は青色の立方体とblueCubeAxesを含みます。この変換の影響を受けるのは、青色の立方体とblueCubeAxesだけです。
TransformGroup secondTransGroup = translate(
scaledGroup,
new Vector3f(tx2,ty2,tz2));
//Display the secondTransGroup transform matrix.
System.out.println("secondTransGroup xform matrix");
secondTransGroup.getTransform(tempXform);
displayMatrix(tempXform);
青色の立方体は、blueCubeGroupの対応する軸で示される方向に平行移動されます。blueCubeGroupの軸が回転している場合も同様です。
回転変換を作成および表示する
リスト10では、secondTransGroupに適用される回転変換を作成します。図7の階層によると、secondTransGroupはscaledGroupを含み、さらに後者はblueCubeGroupを含みます。
TransformGroup rotatedGroup =
tiltTheAxes(secondTransGroup,
xAngle,//x-axis
yAngle,//y-axis
zAngle);//z-axis
//Display the rotation transform matrix.
System.out.println("Rotation xform matrix");
rotatedGroup.getTransform(tempXform);
displayMatrix(tempXform);
新しい3D軸にも回転を適用する
リスト11に示されているように、plainAxesGroupという名前の新しい3Dシミュレート軸にも回転変換が適用されます。この時点でplainAxesGroupを追加する目的は、最後の変換を実行する直前に青色の立方体の位置と方向を示すことです(図8を参照)。青色の立方体、blueCubeAxes、plainAxesGroupのすべてが回転されます。立方体が平行移動によって原点から離れていても、回転は、ユニバースに属する軸ではなく、ローカル軸に対して行われます。
別の3D軸を作成および追加する
リスト11では、上記の目的で、plainAxesGroupを作成し、それをrotatedGroupに追加します。
//Create and add the plainAxesGroup to the // rotatedGroup. TransformGroup plainAxesGroup = getAxesGroup(); rotatedGroup.addChild(plainAxesGroup);
もう1つの平行移動変換を作成および表示する
リスト12では、図8のGUIの一番上に示されている平行移動変換を作成および表示します。この平行移動は、rotatedGroupに適用されます。図7の階層によると、rotatedGroupはplainAxesGroupとsecondTransGroupを含み、さらに後者はscaledGroupを含みます。scaledGroupは、blueCubeGroupを含みます。したがって、plainAxesGroup、青色の立方体、blueCubeAxesのすべてがこの変換によって平行移動されます。
TransformGroup firstTransGroup = translate(
rotatedGroup,
new Vector3f(tx1,ty1,tz1));
//Display the firstTransGroup transform matrix.
System.out.println("firstTransGroup xform matrix");
firstTransGroup.getTransform(tempXform);
displayMatrix(tempXform);
階層の完了
リスト13では、firstTransGroupをmainBranchGroupに追加することによって、階層を完了します。
//Construct the main group. mainBranchGroup.addChild(firstTransGroup); //Add the redCube to mark the origin. None of the // transforms are applied to the redCube. mainBranchGroup.addChild(redCube);
最後に、リスト13のコードでは、赤色の面を見せた状態のColorCubeオブジェクトをBranchGroupオブジェクトの子として追加します。この立方体は、どの変換の対象でもありません。したがって、ユニバースのレンダリング時にユニバースの原点を中心として配置され、原点の位置を示します。
コンストラクタとクラスの完了
リスト14では、Sceneクラスのコンストラクタを完了します。SceneクラスとJava3D010クラスの終了も通知します。したがって、リスト14はプログラムの最後です。
//Populate the universe by adding the branch group
// that contains the objects.
simpleUniverse.addBranchGraph(mainBranchGroup);
//Do the normal GUI stuff.
setTitle("Copyright 2007, R.G.Baldwin");
setBounds(0,0,235,235);
setVisible(true);
//This listener is used to terminate the program
// when the user clicks the X-button on the Frame.
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}//end windowClosing
}//end new WindowAdapter
);//end addWindowListener
}//end constructor
//--------------------------------------------------//
}//end inner class Scene
}//end class Java3D010
プログラムの実行
リスト15のコードをコンパイルおよび実行することをお勧めします。変更を加え、その変更の結果を確認するなどして、実際にコードを操作してみてください。
このプログラムをコンパイルおよび実行するには、Java 3D APIに加えて、Microsoft DirectXまたはOpenGLをダウンロードし、インストールする必要があります。これらをダウンロードできるWebサイトのリンクについては、下記の「ダウンロード」の項を参照してください。
まとめ
このレッスンでは、Java 3Dでの変換について理解し、その理解に基づいて、Java 3Dコードを作成する方法について学習しました。
次の課題
今後のレッスンでは、対話型のJava 3Dプログラム、高度なアニメーション、およびサーフェスを扱います。
ダウンロード
- Getting Started with the Java 3D API(Dennis J Bouvierによる初心者用チュートリアル)
- 上記のBouvierチュートリアルで使用されているサンプルプログラムのソースコード
- Java 3D APIバージョン1.5.0
- Java 3D APIバージョン1.5.0の実装ドキュメント
- Microsoft DirectX10
- OpenGL
参考資料
- Dick BaldwinのチュートリアルWebサイト
- Java 3D APのメインページ
- Java 3D FAQ
- Java 3Dバージョン1.3のオンラインドキュメント(v1.5.0ドキュメントについては、上記の「ダウンロード」を参照)
- Getting Started with the Java 3D? API(Dennis J Bouvierによる初心者用チュートリアル)
- Introduction to the Java 3D API(他のチュートリアル情報へのリンクを掲載)
- 各種のJava 3Dリソース
- 他のJava 3Dチュートリアル
- Planar transformations
- Spatial transformations
- A little algebra
- Cartesian coordinate system(Wikipedia)
- Orthogonality(Wikipedia)
- Trigonometry(Wikipedia)
- Vector(Wikipedia)
- System.out.printf() - J2SE5.0
- Learn to Program using Alice
- 306 Java 2D Graphics, Simple Affine Transforms
- 1468 Plotting Engineering and Scientific Data using Java
- 1516 Introduction to Alice Programming
- 1540 Understanding Lighting in the Java 3D API
- 1541 Back to Basics in the Java 3D API
- 1542 Digging a Little Deeper into the Java 3D API
- 1544 Simple Animation with the Java 3D API
- 1546 Understanding the Alpha Time-Base Class in Java 3D
- 1548 Combining Rotation and Translation in Java 3d
- 1550 Understanding Transforms in Java 2D
完全なプログラムリスト
このレッスンで説明したプログラムの完全なリストを、以下のリスト15に示します。
/*File Java3D010.java
Copyright 2007, R.G.Baldwin
This program is very similar to the Java2D program named
Java2D001.
The purpose of this program is to make it easy to
experiment with the following four transforms executed
in sequence:
translate
rotate
another translate
scale
The program creates a user input GUI that can be used to
vary the parameters used for the sequence of transforms
Two ColorCube objects and two sets of three long skinny
ColorCube objects arranged to simulate a visible set of
3D axes are added as children at different levels of the
branch group hierarchy. The different objects are
subjected to different transforms depending on their
position in the hierarchy. Only the cube with the blue
face showing and its associated visible axes are subjected
to all four transforms in the above list.
A Replot button allows the user to modify input
parameters, recompute the transforms, and produce a new
output by clicking the button. Clicking the Replot button
when one of the input fields contains String data that
can't be converted to a numeric type will cause the
program to abort with a NumberFormatException. For
example, a blank field falls in this category.
Tested using Java SE 6, and Java 3D 1.5.0 running under
Windows XP.
*********************************************************/ import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.media.j3d.Node; import javax.vecmath.Vector3f; import javax.vecmath.Vector3d; import java.awt.Frame; import java.awt.Panel; import java.awt.Label; import java.awt.TextField; import java.awt.Button; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; //This is the top-level driver class for this program. public class Java3D010 extends Frame{ Scene scene = new Scene(); TextField sxTxt = new TextField("1.0"); TextField syTxt = new TextField("1.0"); TextField szTxt = new TextField("1.0"); TextField tx2Txt = new TextField("0.0"); TextField ty2Txt = new TextField("0.0"); TextField tz2Txt = new TextField("0.0"); TextField xAngleTxt = new TextField("0.0"); TextField yAngleTxt = new TextField("0.0"); TextField zAngleTxt = new TextField("0.0"); TextField tx1Txt = new TextField("0.0"); TextField ty1Txt = new TextField("0.0"); TextField tz1Txt = new TextField("0.0"); //These instance variables are accessed by the // constructor for a Scene object when it is // instantiated. They are defined in this enclosing // class rather than in the Scene class because they // need to be set before the constructor for the Scene // object is called. //Scaling parameters. double sx = 1.5; //scale X double sy = 1.0; //scale Y double sz = 1.0; //scale Z //Translation parameters for first translation. float tx1 = 0.7f; //translate X float ty1 = 0.0f; //translate Y float tz1 = 0.0f; //translate Z //Rotation parameters. double xAngle = 0.0;//rotate around X double yAngle = 0.0;//rotate around Y double zAngle = Math.PI/4.0d;//rotate around z //Translation parameters for second translation. float tx2 = 0.3f;//translate X again float ty2 = 0.0f;//translate Y again float tz2 = 0.0f;//translate Z again //----------------------------------------------------// public static void main(String[] args){ Java3D010 thisObj = new Java3D010(); }//end main //----------------------------------------------------// public Java3D010(){//top-level constructor setTitle("Copyright 2007, R.G.Baldwin"); setBounds(236,0,235,235); //Construct the user input panel and add it to the // CENTER of the Frame. Arrange the fields from top to // bottom in the order that the transforms are // actually executed. Panel inputPanel = new Panel(); inputPanel.setLayout(new GridLayout(0,4)); inputPanel.add(new Label("Xform",Label.CENTER)); inputPanel.add(new Label("X",Label.CENTER)); inputPanel.add(new Label("Y",Label.CENTER)); inputPanel.add(new Label("Z",Label.CENTER)); //Input data for the first translation. inputPanel.add(new TextField("Trans")); inputPanel.add(tx1Txt); inputPanel.add(ty1Txt); inputPanel.add(tz1Txt); //Input data for the rotation. inputPanel.add(new TextField("Rot (deg)")); inputPanel.add(xAngleTxt); inputPanel.add(yAngleTxt); inputPanel.add(zAngleTxt); //Input data for the second translation. inputPanel.add(new TextField("Trans")); inputPanel.add(tx2Txt); inputPanel.add(ty2Txt); inputPanel.add(tz2Txt); //Input scaling data. inputPanel.add(new TextField("Scale")); inputPanel.add(sxTxt); inputPanel.add(syTxt); inputPanel.add(szTxt); add(inputPanel,BorderLayout.CENTER); //Add a button that allows the user to change the // input parameter values, recompute the transforms, // and replot the cube. Button button = new Button("Replot"); button.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ //Get user input values from the text fields, // convert them to numeric types, and store them // in instance variables that are accessible to // the constructor for the Scene object. Note // that the parse methods will cause the program // to abort with a NumberFormatException if a // field contains a string that cannot be // converted to the appropriate numeric type // (including an empty string caused by a blank // field). //Data for the first translation. tx1 = Float.parseFloat(tx1Txt.getText()); ty1 = Float.parseFloat(ty1Txt.getText()); tz1 = Float.parseFloat(tz1Txt.getText()); //Data for the rotation. Convert the rotation // angles from degrees to radians. xAngle = (Double.parseDouble( xAngleTxt.getText()) * Math.PI/180.0); yAngle = (Double.parseDouble( yAngleTxt.getText()) * Math.PI/180.0); zAngle = (Double.parseDouble( zAngleTxt.getText()) * Math.PI/180.0); //Data for the second translation. tx2 = Float.parseFloat(tx2Txt.getText()); ty2 = Float.parseFloat(ty2Txt.getText()); tz2 = Float.parseFloat(tz2Txt.getText()); //Scaling data sx = Double.parseDouble(sxTxt.getText()); sy = Double.parseDouble(syTxt.getText()); sz = Double.parseDouble(szTxt.getText()); //Instantiate a new Scene object. Dispose of // the old object to conserve resources. // Otherwise the program aborts after clicking // the Replot button 32 times with a message // regarding a limit on the number of allowable // Canvas objects that can be rendered. scene.dispose(); scene = new Scene(); }//end actionPerformed }//end new ActionListener );//end addActionListener //Finish constructing the GUI. add(button,BorderLayout.SOUTH); setVisible(true); //This window listener is used to terminate the // program when the user clicks the X button. addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); }//end windowClosing }//end new WindowAdapter );//end addWindowListener }//end constructor //----------------------------------------------------// //This is an inner class, from which the universe will // be instantiated. class Scene extends Frame{ //Declare instance variables that are used later by // the program. Canvas3D canvas3D; SimpleUniverse simpleUniverse; BranchGroup mainBranchGroup = new BranchGroup(); //--------------------------------------------------// Scene(){//constructor //Create a temporary TransformGroup object for the // sole purpose of displaying the default transform // matrix that is contained in a new TransformGroup // object. System.out.println("\nDefault xform matrix."); TransformGroup tempXformGroup = new TransformGroup(); Transform3D tempXform = new Transform3D(); tempXformGroup.getTransform(tempXform); displayMatrix(tempXform); //Construct the universe. createACanvas(); createTheUniverse(); //Create two different ColorCube objects. Rotate // one of them around its vertical axes so that it // will display its blue face. The names given to // the cubes are based on the color of the face that // is displayed on the front following this // rotation transform. //The following ColorCube displays its red face // without being rotated. ColorCube redCube = new ColorCube(0.125f); //Create a cube and rotate it to cause it to display // its blue face. TransformGroup blueCubeGroup = tiltTheAxes(new ColorCube(0.125f), 0.0d,//x-axis 3*Math.PI/2.0d,//y-axis 0.0d);//z-axis //Add a set of axes to the blueCubeGroup . TransformGroup blueCubeAxes = getAxesGroup(); blueCubeGroup.addChild(blueCubeAxes); //Now perform a series of transforms based on the // user input data. Note that this code constructs // the branch group hierarchy from the leaves toward // the root. //Create a scaling transform, which will be applied // to the blueCubeGroup. The blueCubeGroup includes // the blue cube and the blueCubeAxes. TransformGroup scaledGroup = scale( blueCubeGroup, new Vector3d(sx,sy,sz)); //Display the scaling transform matrix. System.out.println("Scaling xform matrix"); scaledGroup.getTransform(tempXform); displayMatrix(tempXform); //Create a translation transform, which will be // applied to the scaledGroup. The scaledGroup // contains the blueCubeGroup, which in turn // contains the blue cube and the blueCubeAxes. // Only the blue cube and blueCubeAxes will be // affected by this transform. //Note that the blue cube is translated in a // direction indicated by the corresponding axes // belonging to the blueCubeGroup, even if the axes // belonging to the blueCubeGroup have been rotated. TransformGroup secondTransGroup = translate( scaledGroup, new Vector3f(tx2,ty2,tz2)); //Display the secondTransGroup transform matrix. System.out.println("secondTransGroup xform matrix"); secondTransGroup.getTransform(tempXform); displayMatrix(tempXform); //Create a rotation transform, which will be applied // to the secondTransGroup. The secondTransGroup // contains the scaledGroup, which in turn contains // the blueCubeGroup. The transform // will also be applied to a new set of axes named // plainAxesGroup. //The purpose of adding plainAxesGroup at this point // is to show the location and orientation of the // blue cube immediately before the final // translation is executed. //The blue cube, blueCubeAxes, and plainAxesGroup // will all be rotated. Rotation takes place around // the local axis (rather than the 3D-space axes), // even if the cube has been translated away from // the origin. TransformGroup rotatedGroup = tiltTheAxes(secondTransGroup, xAngle,//x-axis yAngle,//y-axis zAngle);//z-axis //Display the rotation transform matrix. System.out.println("Rotation xform matrix"); rotatedGroup.getTransform(tempXform); displayMatrix(tempXform); //Create and add the plainAxesGroup to the // rotatedGroup. TransformGroup plainAxesGroup = getAxesGroup(); rotatedGroup.addChild(plainAxesGroup); //Create the first translation transform, which will // be applied the rotatedGroup. The rotatedGroup // contains the plainAxesGroup and the // secondTransGroup, which in turn contains the // scaledGroup. The scaledGroup contains the // blueCubeGroup. Thus, the // plainAxesGroup, the blue cube, and blueCubeAxes // will all be translated by this transform. TransformGroup firstTransGroup = translate( rotatedGroup, new Vector3f(tx1,ty1,tz1)); //Display the firstTransGroup transform matrix. System.out.println("firstTransGroup xform matrix"); firstTransGroup.getTransform(tempXform); displayMatrix(tempXform); //Construct the main group. mainBranchGroup.addChild(firstTransGroup); //Add the redCube to mark the origin. None of the // transforms are applied to the redCube. mainBranchGroup.addChild(redCube); //Populate the universe by adding the branch group // that contains the objects. simpleUniverse.addBranchGraph(mainBranchGroup); //Do the normal GUI stuff. setTitle("Copyright 2007, R.G.Baldwin"); setBounds(0,0,235,235); setVisible(true); //This listener is used to terminate the program // when the user clicks the X-button on the Frame. addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); }//end windowClosing }//end new WindowAdapter );//end addWindowListener }//end constructor //--------------------------------------------------// //Create a Canvas3D object to be used for rendering // the Java 3D universe. Place it in the CENTER of // the Frame. void createACanvas(){ canvas3D = new Canvas3D( SimpleUniverse.getPreferredConfiguration()); add(BorderLayout.CENTER,canvas3D); }//end createACanvas //--------------------------------------------------// //Create an empty Java 3D universe and associate it // with the Canvas3D object in the CENTER of the // frame. Also specify the apparent location of the // viewer's eye. void createTheUniverse(){ simpleUniverse = new SimpleUniverse(canvas3D); simpleUniverse.getViewingPlatform(). setNominalViewingTransform(); }//end createTheUniverse //--------------------------------------------------// //Given an incoming node object and a vector object, // this method will return a transform group designed // to translate that node according to that vector. TransformGroup translate(Node node,Vector3f vector){ Transform3D transform3D = new Transform3D(); transform3D.setTranslation(vector); TransformGroup transformGroup = new TransformGroup(); transformGroup.setTransform(transform3D); transformGroup.addChild(node); return transformGroup; }//end translate //--------------------------------------------------// //Given an incoming node object and a vector object, // this method will return a transform group designed // to scale that node according to that vector. TransformGroup scale(Node node,Vector3d vector){ Transform3D transform3D = new Transform3D(); transform3D.setScale(vector); TransformGroup transformGroup = new TransformGroup(); transformGroup.setTransform(transform3D); transformGroup.addChild(node); return transformGroup; }//end scale //--------------------------------------------------// //The purpose of this method is to create and return // a transform group designed to perform a counter- // clockwise rotation about the x, y, and z axes // belonging to an incoming node. The three incoming // angle values must be specified in radians. Don't // confuse this with a RotationInterpolator. This is // not an interpolation operation. Rather, it is a // one-time transform. TransformGroup tiltTheAxes(Node node, double xAngle, double yAngle, double zAngle){ Transform3D tiltAxisXform = new Transform3D(); Transform3D tempTiltAxisXform = new Transform3D(); //Construct and then multiply two rotation transform // matrices. tiltAxisXform.rotX(xAngle); tempTiltAxisXform.rotY(yAngle); tiltAxisXform.mul(tempTiltAxisXform); //Construct the third rotation transform matrix and // multiply it by the result of previously // multiplying the two earlier matrices. tempTiltAxisXform.rotZ(zAngle); tiltAxisXform.mul(tempTiltAxisXform); TransformGroup rotatedGroup = new TransformGroup( tiltAxisXform); rotatedGroup.addChild(node); return rotatedGroup; }//end tiltTheAxes //--------------------------------------------------// //This method displays the contents of the 4x4 matrix // contained in a Transform3D object. void displayMatrix(Transform3D transform){ //Retrieve the contents of the matrix into an array. // The first four elements of the array contain the // first row of the matrix, etc. double[] matrixData = new double[16]; transform.get(matrixData); for(int outCnt = 0;outCnt < 16;outCnt += 4){ for(int cnt = 0;cnt < 4;cnt++){ System.out.printf( "%6.2f ",matrixData[cnt + outCnt]); }//end inner loop System.out.println(); }//end outer loop }//end displayMatrix //--------------------------------------------------// //This method constructs and returns a TransformGroup // object containing a set of what look like three // orthogonal axes. Each of the three individual axes // is constructed from a long skinny ColorCube // object. TransformGroup getAxesGroup(){ ColorCube xAxis = new ColorCube(); TransformGroup xGroup = scale( xAxis, new Vector3d(0.25,0.01,0.01)); ColorCube yAxis = new ColorCube(); TransformGroup yGroup = scale( yAxis, new Vector3d(0.01,0.25,0.01)); ColorCube zAxis = new ColorCube(); TransformGroup zGroup = scale( zAxis, new Vector3d(0.01,0.01,0.25)); TransformGroup axesGroup = new TransformGroup(); axesGroup.addChild(xGroup); axesGroup.addChild(yGroup); axesGroup.addChild(zGroup); return axesGroup; }//end getAxesGroup //--------------------------------------------------// }//end inner class Scene }//end class Java3D010
著作権情報
Copyright 2007, Richard G. Baldwin.
Richard Baldwinにより書面で明確に許可された場合を除き、本稿の一部またはすべてを複製することは、手段や媒体にかかわらず一切禁じられています。
