简体   繁体   English

JavaFx中3d框的位置

[英]Positioning of 3d boxes in JavaFx

I'm a beginner in JavaFx 3d modelling. 我是JavaFx 3d建模的初学者。 I'm trying to create a 3d-model of boxes in a room. 我正在尝试在房间中创建盒子的3D模型。 I have the dimensions of the boxes and the coords from the front-left-bottom corner of every box. 我有盒子的尺寸和每个盒子的左下角的坐标。 I've tried to set the coords with setTranslateX(), but the result isn't correct. 我试图用setTranslateX()设置坐标,但是结果不正确。 Here is the pice of my code where I try to set the coords: 这是我的代码中尝试设置坐标的地方:

for (int i = 0; i < Main.load.size(); i++) {
        Load l=Main.load.get(i);
        Box sphere = new Box(l.getLength()*10, l.getWidth()*10, l.getHeight()*10);
        sphere.setTranslateX(l.getX()*10);
        sphere.setTranslateY(l.getY()*10);
        sphere.setTranslateZ(l.getZ()*10);
        PhongMaterial m = new PhongMaterial();
        m.setDiffuseColor(new Color(Math.random(),Math.random(),Math.random(),1));
        m.setSpecularColor(Color.BLACK);
        sphere.setMaterial(m);
        root.getChildren().add(sphere);
    }

I hope someone can help me. 我希望有一个人可以帮助我。

Here is an example: 这是一个例子:

Sizes: blue (30,50,50) pink (10,10,20) 尺寸:蓝色(30,50,50)粉色(10,10,20)

Position: blue (0,0,0) pink (30,0,0) 位置:蓝色(0,0,0)粉色(30,0,0)

And this is what I get 这就是我得到的

When you do a translation of a JavaFX 3D object like a Box you need to account half the width of the object along any axis. 在翻译JavaFX 3D对象(如Box)时,您需要考虑对象沿任何轴的一半宽度。 The default placement for a Box is to be centered at the origin meaning the center of the Box object is at 0,0,0. Box的默认放置位置将以原点为中心,这意味着Box对象的中心为0,0,0。 Your width is 30 * 10 but your translateX converts to 0*10=0. 宽度为30 * 10,但您的translateX转换为0 * 10 = 0。 So the right most edge of your blue box will be X=150 (300 / 2.0 = 150). 因此,蓝色框的最右边将为X = 150(300 / 2.0 = 150)。 Your Pink Box has a translateX of 10*30=300. 您的粉红色盒子的translationX为10 * 30 = 300。 The center of the pink box will be translated to 300 which means the left most edge will be at 300 - (width/2.0) = 300 - (50) = 250. 粉色框的中心将转换为300,这意味着最左边的边缘将为300-(width / 2.0)= 300-(50)= 250。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM