gpt4 book ai didi

java - 在 Java3D 中将较小的盒子加载到较大的盒子中

转载 作者:行者123 更新时间:2023-12-02 09:39:13 25 4
gpt4 key购买 nike

所以我很难将较小的盒子放入较大的盒子(容器)中。我尝试从盒子中获取一个顶点的坐标,并将另一个顶点放在该位置。这是我尝试过的代码:

 Shape3D backShape = ((Box) buildShape(x, y, z)).getShape(Box.RIGHT);

GeometryArray geo=(GeometryArray)backShape.getGeometry();
float[] position=new float[3];
geo.getCoordinate(0, position);
System.out.println(position[0]+" "+position[1]+" "+position[2]);
Vector3f pp = new Vector3f (position[0],position[1], position[2]);

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));

for (int i=0; i<boxes.size(); i++) {

Transform3D transform = new Transform3D();
transform.setTranslation(pp);
Box ProductBox = addProductBox(boxes.get(i).dimension.get("length"),boxes.get(i).dimension.get("breadth")
,boxes.get(i).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);
Shape3D shape = ProductBox.getShape(Box.FRONT);
GeometryArray g=(GeometryArray)shape.getGeometry();
position[0]-= boxes.get(i).dimension.get("length")+0.15f;
System.out.println(position[0]+" "+position[1]+" "+position[2]);

Vector3f pp2 = new Vector3f (position[0],position[1],position[2]);
pp=pp2;
c[i]=c[i+1];
}

通过在每次迭代中从位置[0]减去长度,我成功地定位了容器中的所有盒子。但盒子并没有排成一行。我附上了一张图片,显示了我到目前为止所做的事情: here

最佳答案

我有这个简单的程序。假设您有一个 Shape3D 形状:

GeometryArray ge=(GeometryArray)shape.getGeometry();
double[] cc1=new double[3];
ge.getCoordinate(0, cc1);
System.out.println(cc1[0]+" "+cc1[1]+" "+cc1[2]);
ge.getCoordinate(1, cc1);
System.out.println(cc1[0]+" "+cc1[1]+" "+cc1[2]);

这样我就可以获得形状的坐标。您必须处于 3D 空间的良好位置才能理解。您必须通过放置对象来进行实验(一开始只有一个)。

关于java - 在 Java3D 中将较小的盒子加载到较大的盒子中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35656328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com