Java3Dで,線をいっぱい引いて3Dの格子を表現するメモ.
座標系をうまくイメージできていないためか,無駄に手間取りました.
下記のようなメソッドをつくり,インスタンス生成してaddChildすれば6*6*6の格子が描かれます.
マジックナンバー使いまくり.
private BranchGroup createGrid() {
BranchGroup bg = new BranchGroup();
Point3d[] line = new Point3d[216];
int p = 0;
for(double i = -0.5; i <= 0.5; i+=0.2){
for(double j = -0.5; j <= 0.5; j+=0.2){
line[p] = new Point3d(0.5, i, j);
p++;
line[p] = new Point3d(-0.5, i, j);
p++;
line[p] = new Point3d(i, 0.5, j);
p++;
line[p] = new Point3d(i, -0.5, j);
p++;
line[p] = new Point3d(j, i, 0.5);
p++;
line[p] = new Point3d(j, i, -0.5);
p++;
}
}
LineArray la = new LineArray(line.length, GeometryArray.COORDINATES);
la.setCoordinates(0, line);
Shape3D shape = new Shape3D(la);
bg.addChild(shape);
return bg;
}
座標系をうまくイメージできていないためか,無駄に手間取りました.
下記のようなメソッドをつくり,インスタンス生成してaddChildすれば6*6*6の格子が描かれます.
マジックナンバー使いまくり.
private BranchGroup createGrid() {
BranchGroup bg = new BranchGroup();
Point3d[] line = new Point3d[216];
int p = 0;
for(double i = -0.5; i <= 0.5; i+=0.2){
for(double j = -0.5; j <= 0.5; j+=0.2){
line[p] = new Point3d(0.5, i, j);
p++;
line[p] = new Point3d(-0.5, i, j);
p++;
line[p] = new Point3d(i, 0.5, j);
p++;
line[p] = new Point3d(i, -0.5, j);
p++;
line[p] = new Point3d(j, i, 0.5);
p++;
line[p] = new Point3d(j, i, -0.5);
p++;
}
}
LineArray la = new LineArray(line.length, GeometryArray.COORDINATES);
la.setCoordinates(0, line);
Shape3D shape = new Shape3D(la);
bg.addChild(shape);
return bg;
}