This is part of code that's supposed to draw 2 cubes of side 0.3 next to each other When I get instead is this: http://imageshack.us/photo/my-images/189/89254345.png/ (they are halfway into each other) I tried printing the transforms and they look alright:
1
1.0, 0.0, 0.0, 0.0
0.0, 1.0, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
0.0, 0.0, 0.0, 1.0
2
1.0, 0.0, 0.0, 0.3
0.0, 1.0, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
0.0, 0.0, 0.0, 1.0
It's as if the second box was only moved by 0.15 but if I multiply dx by 2 things break when more cuboids of different dimensions get added with transforms across the y or z axis
private BranchGroup rootGroup;
public void addBox(float dx){
Cuboid Cuboid1 = new Cuboid(0.3f ,0.3f, 0.3f, appearence);
TransformGroup tg = new TransformGroup();
Transform3D transform = new Transform3D();
Vector3f vector = new Vector3f(dx, 0f, 0f);
transform.setTranslation(vector);
tg.setTransform(transform);
tg.addChild(Cuboid1);
rootGroup.addChild(tg);
}
public void addBoxes(){
for(int i=0;i<2;i++){
addBox(i*0.3f);
}
}
The cuboid class is from here: http://www.java2s.com/Code/Java/3D/Java3DBoxandacustomCuboidimplementation.htm
It looks like you're creating a cuboid which is 0.6 in size so it will have +0.3 and -0.3 X,Y,Z values for the first box as the center point of the cuboid is 0,0,0.
The second box is the same but offset by 0.3 in one axis which gives 0.3-0.3=0.0 and +0.3+0.3 = 0.6 values in one of the axes.
This will give two boxes that overlap half way on one axis which seems to match your picture.
Perhaps you mean to create a box with width/height/depth of 0.3/2 and translate it by 0.3/2 so that the center of the box is at 0.15,0.15 and use a scale factor of 0.15 instead of 0.3?