Java3D 座標の値を入力し点を表示させるには
Java3D 座標の値を入力することにより点を表示させたいです。そのために下記のように主な部分のソースコードを作成しました。どこをどうすればよいでしょう教えてください!
public class Test extends Applet{
boolean isStandalone=false;
Canvas3D canvas=null;
SimpleUniverse universe=new SimpleUniverse(canvas);
BranchGroup scene=createSceneGraph();
BranchGroup root3=new BranchGroup();
TransformGroup trans3=new TransformGroup();
float x;
float y;
float z;
Vector3f pointposition = new Vector3f(0.0f, 0.0f, 0.0f);
TuplePanel bgpanel=new TuplePanel(pointposition)
public Test(){
this(false);
}
public Test(final boolean isStandalone){
this.isStandalone = isStandalone;
this.setLayout(new BorderLayout());
Panel panel=new Panel();
this.add(panel,BorderLayout.NORTH);
bgpanel.addTupleEventListener(new TupleEventListener(){ public void tupleStateChanged(TupleEvent e){
pointposition=e.getVector3f();
Transform3D t3d = new Transform3D();
t3d.setTranslation(pointposition);
trans3=new TransformGroup(t3d);
Point3f[] po3=new Point3f[1];
po3[0]=new Point3f(pointposition);
PointArray ge3=new PointArray(po3.length, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
ge3.setCoordinate(0,po3[0]);
Appearance appp3=new Appearance();
Shape3D gggrid3=new Shape3D(ge3,appp3);
gggrid3.setGeometry(ge3);
trans3.addChild(gggrid3); }
});
panel.add(bgpanel);
Button addbutton = new Button("Add");
addbutton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e) {
universe.getLocale().removeBranchGraph(scene);
scene.addChild(trans3);
universe.addBranchGraph(scene);
}
});
panel.add(addbutton);
}
@Override
public void init() {
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
・・・
BranchGroup scene=createSceneGraph();
universe.addBranchGraph(scene);
}
private BranchGroup createSceneGraph(){
root3.setCapability(BranchGroup.ALLOW_DETACH);
root3.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
trans3.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
trans3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
BoundingSphere bounds3 = new BoundingSphere(new Point3d(),100.0);
・・・
double[] vertices3= {0.65,0.00,0.05,//X軸
・・・ };
float[] colorP3={0.0f,0.0f,0.0f
・・・};
LineArray eom3=new LineArray(vertices3.length, GeometryArray.COORDINATES|GeometryArray.COLOR_3);
eom3.setCoordinates(0,vertices3);
eom3.setColors(0,colorP3);
LineAttributes attr3=new LineAttributes();
attr3.setLineWidth(3.0f);
Appearance p3=new Appearance();
p3.setLineAttributes(attr3);
Shape3D rid3=new Shape3D(eom3,p3);
rid3.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
trans3.addChild(rid3);
Point3f[] po3=new Point3f[1];
po3[0]=new Point3f(x,y,z);
float[] colorPo3={1.0f,0.0f,0.0f};
final PointArray ge3=new PointArray(po3.length, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
ge3.setCoordinate(0,po3[0]);
ge3.setColors(0,colorPo3);
Appearance appp3=new Appearance();
appp3.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_READ);
appp3.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE);
PointAttributes ppo3=new PointAttributes();
ppo3.setPointSize(25.0f);
appp3.setPointAttributes(ppo3);
Shape3D gggrid3=new Shape3D(ge3,appp3);
gggrid3.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
gggrid3.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
trans3.addChild(gggrid3);
return root3;
}
お礼
ありがとうございました(>_<)!! HP、参考にさせていただきます☆