所以我要做的是将不同尺寸的盒子装入一个大容器中。我正在使用LAFF算法来执行此操作,并且我想使用Java3D可视化容器的完整加载计划。 我的问题是,当我尝试为每个杠杆定位包装盒时,它们超过了容器的尺寸,而第二个水平的盒子没有出现在第一个盒子的顶部。我附上了一张新图片
这是我为Java3D中的打包过程编写的代码:
VirtualUniverse myUniverse = new VirtualUniverse();
Locale myLocale = new Locale(myUniverse);
float p2 = 0;
BranchGroup nodeRoot = new BranchGroup();
nodeRoot=buildContentBranch(buildShape(x, y, z));
//----------------------------------------
Shape3D backShape = ((Box) buildShape(x, y, z)).getShape(Box.RIGHT);
int rr = 2;
System.out.println();
float[] position = new float[3];
geo.getCoordinates(rr, position);
Vector3f pp = new Vector3f (position[0],position[1], position[2]);
//--------------------------------------------------------
GeometryArray geo=(GeometryArray)backShape.getGeometry();
float[] position=new float[3];
geo.getCoordinate(0, position);
//geo.getCoordinate(1,position);
//System.out.println(position[0]+" "+position[1]+" "+position[2]);
Vector3f pp = new Vector3f (position[0]-0.2f,position[1]+0.3f, position[2]-0.1f);
Color3f c1=new Color3f(0.7f, .15f, .15f);
Color3f c2=new Color3f(0.7f, .15f, .15f);
Color3f[] c=(Color3f[]) new Color3f[20] ;
c[0] =new Color3f(Color.getHSBColor(20.f, 30f, 2.f));
c[1] =new Color3f(Color.BLUE);
c[2] =new Color3f(Color.YELLOW);
c[3] =new Color3f(Color.GREEN);
c[4] =new Color3f(Color.WHITE);
c[5] =new Color3f(Color.CYAN);
c[6] =new Color3f(Color.LIGHT_GRAY);
c[7] =new Color3f(Color.PINK);
c[8] =new Color3f(Color.RED);
c[9] =new Color3f(Color.DARK_GRAY);
c[10] =new Color3f(Color.MAGENTA);
c[11] =new Color3f(Color.getHSBColor(0.2f, 0.15f, 2.f));
c[11] =new Color3f(Color.getHSBColor(0.8f, 0.1f, 15.f));
c[13] =new Color3f(Color.ORANGE);
c[11] =new Color3f(Color.getHSBColor(1.f, 0.8f, 2.f));
//---------------------------------------------------------------------
int i=0;
for (Level level : levels2) {
for (Items b : level.packedBoxes) {
Transform3D transform = new Transform3D();
transform.setTranslation(pp);
Box ProductBox = addProductBox(b.dimension.get("length"),b.dimension.get("breadth")
,b.dimension.get("height"),c1, c2,c[i],c[i]);
Transform3D rotateCube = new Transform3D();
rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
TransformGroup rotationGroup = new TransformGroup(rotateCube);
TransformGroup TranslateGroup = new TransformGroup(transform);
TranslateGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
rotationGroup.addChild(ProductBox);
TranslateGroup.addChild(rotationGroup);
nodeRoot.addChild(TranslateGroup);
//get the coordinates of the new box
Shape3D shape = ProductBox.getShape(Box.FRONT);
position[0]-= b.dimension.get("length");
p2=boxBig.dimension.get("height");
if (position[0]-x>0) {
position[1]+= b.dimension.get("breadth");
}
if (y-position[1]<0)
{
position[2]+=p2;
}
i++;
Vector3f pp2 = new Vector3f (position[0],position[1], position[2]);
pp=pp2;
System.out.println("pppppppp " +pp);
}
}
myLocale.addBranchGraph(nodeRoot);
setTitle("Container Loading");
setSize(1000,1000);
setLayout(new BorderLayout());
add("Center", canvas);
setVisible(true);
myLocale.addBranchGraph(buildViewBranch(canvas));
我有8个盒子。 我试图知道我的代码有什么问题,但我无法弄清楚问题出在哪里。谁能帮我这个? 谢谢。
答案 0 :(得分:0)
我看到的第一个错误是
position[0]+= b.dimension.get("length");
p2=boxBig.dimension.get("height");
System.out.println("position 0 " +position[0]);
//g.getCoordinate(1,position);
g.getCoordinate(2,position);
你推进了位置,但是你重新读了它将覆盖。
然后pp(如果你用它来定位第二个对象等)似乎没有在内循环内进行。
现在就是这样。
-
更新后:我看到lightGray项目被隐藏,所以它必须很小;白色突出两个盒子。也许你用来推进这个位置的长度可能是&#34;广度&#34;。