[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Java3Djp:00525] タートルグラフィック・ライブラリー(3/3)
------------------------------------
メーリングリストはDNS
http://www.dns-ml.co.jp
初心者でも簡単開設・運用が可能です!
------------------------------------
テスト用のAppletです。
矢印キーを押して視点を移動/回転できます。
[Shift]+ [Ctrl]+
上 テ
平 ィ
行 ル
前 移 ト
進 動 Up
↑ ↑ ↑
左回転 ←↓→ 右回転 左平行移動 ←↓→ 右平行移動 左旋回 ←↓→ 右旋回
後 下 テ
退 平 ィ
行 ル
移 ト
動 Down
TurtleTest.java
===========================================
// Turtle graphics library
// TurtleTest.java
// copyright(c)1999 ENDO Yasuyuki
package org.javaopen.j3d;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.applet.MainFrame;
public class TurtleTest extends Applet {
private SimpleUniverse univ = null;
private Turtle turtle = null;
public Turtle getTurtle() { return turtle; }
public TurtleTest() {
Canvas3D canvas = new Canvas3D(null);
canvas.addKeyListener(new MyKeyAdapter(this));
this.setLayout(new BorderLayout());
this.add("Center", canvas);
this.univ = new SimpleUniverse(canvas);
this.univ.getViewer().getView().setBackClipDistance(2000.0);
System.out.println("backclip=" + univ.getViewer().getView().getBackClipDistance());
//this.univ.getViewingPlatform().setNominalViewingTransform();
this.univ.addBranchGraph(createSceneGraph());
}
public BranchGroup createSceneGraph() {
BranchGroup sceneRoot = new BranchGroup();
sceneRoot.addChild(new ColorCube(100.0));
this.turtle = new Turtle();
this.turtle.addViewTransform(univ.getViewingPlatform().getViewPlatformTransform());
this.turtle.moveUp(800.0);
this.turtle.up( -(Math.PI / 2.0));
Point3d tp = turtle.getPoint();
System.out.println("x=" + tp.x + ", y=" + tp.y + ", z=" + tp.z);
Vector3d v3d = new Vector3d();
Matrix4d m4d = new Matrix4d();
Transform3D t3d = new Transform3D();
this.univ.getViewingPlatform().getViewPlatformTransform().getTransform(t3d);
t3d.get(v3d);
System.out.println("x=" + v3d.x + ", y=" + v3d.y + ", z=" + v3d.z);
t3d.get(m4d);
System.out.println("m00=" + m4d.m00 + ", m01=" + m4d.m01 + ", m02=" + m4d.m02 + ", m03=" + m4d.m03);
System.out.println("m10=" + m4d.m10 + ", m11=" + m4d.m11 + ", m12=" + m4d.m12 + ", m13=" + m4d.m13);
System.out.println("m20=" + m4d.m20 + ", m21=" + m4d.m21 + ", m22=" + m4d.m22 + ", m23=" + m4d.m23);
System.out.println("m30=" + m4d.m30 + ", m31=" + m4d.m31 + ", m32=" + m4d.m32 + ", m33=" + m4d.m33);
return sceneRoot;
}
public static void main(String[] args) {
TurtleTest applet = new TurtleTest();
Frame frame = new MainFrame(applet, 500, 500);
}
}
class MyKeyAdapter implements KeyListener {
private TurtleTest applet = null;
public MyKeyAdapter(TurtleTest applet) { this.applet = applet; }
public void keyPressed( KeyEvent e ){
int key = e.getKeyCode();
if (e.isControlDown()) {
switch (key) {
case KeyEvent.VK_UP:
applet.getTurtle().up(Math.PI/60.0);
break;
case KeyEvent.VK_DOWN:
applet.getTurtle().up(-(Math.PI/60.0));
break;
case KeyEvent.VK_RIGHT:
applet.getTurtle().rolleRight(Math.PI/60.0);
break;
case KeyEvent.VK_LEFT:
applet.getTurtle().rolleRight(-(Math.PI/60.0));
break;
}
} else if (e.isShiftDown()) {
switch (key) {
case KeyEvent.VK_UP:
applet.getTurtle().moveUp(20.0);
break;
case KeyEvent.VK_DOWN:
applet.getTurtle().moveUp(-20.0);
break;
case KeyEvent.VK_RIGHT:
applet.getTurtle().moveRight(20.0);
break;
case KeyEvent.VK_LEFT:
applet.getTurtle().moveRight(-20.0);
break;
}
} else {
switch (key) {
case KeyEvent.VK_UP:
applet.getTurtle().forward(20.0);
break;
case KeyEvent.VK_DOWN:
applet.getTurtle().forward(-20.0);
break;
case KeyEvent.VK_RIGHT:
applet.getTurtle().turnRight(Math.PI/60.0);
break;
case KeyEvent.VK_LEFT:
applet.getTurtle().turnRight(-(Math.PI/60.0));
break;
}
}
}
public void keyReleased( KeyEvent e ){}
public void keyTyped( KeyEvent e ){}
}
===========================================
--
えんどう やすゆき <yasuyuki@xxxxxxxxxx>
http://www.javaopen.org/jfriends/ (Java互助会ホームページ)