Home Ask Login Register

Developers Planet

Your answer is one click away!

holzfeli February 2016

Positioning of 3d boxes in JavaFx

I'm a beginner in JavaFx 3d modelling. I'm trying to create a 3d-model of boxes in a room. 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. 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);
        PhongMaterial m = new PhongMaterial();
        m.setDiffuseColor(new Color(Math.random(),Math.random(),Math.random(),1));

I hope someone can help me.

Here is an example:

Sizes: blue (30,50,50) pink (10,10,20)

Position: blue (0,0,0) pink (30,0,0)

And this is what I get


Birdasaur February 2016

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. 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. Your width is 30 * 10 but your translateX converts to 0*10=0. So the right most edge of your blue box will be X=150 (300 / 2.0 = 150). Your Pink Box has a translateX of 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.

Post Status

Asked in February 2016
Viewed 1,332 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life