这是代码的一部分,它应该绘制两个彼此相邻的边0.3的立方体 当我得到的是这样的:http://imageshack.us/photo/my-images/189/89254345.png/ (他们彼此进入了一半)我尝试打印变换,他们看起来没问题:
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
好像第二个盒子只移动了0.15但是如果我将dx乘以2,当不同尺寸的更多长方体被添加到y或z轴上的变换时,它就会中断
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);
}
}
长方体类来自这里:http://www.java2s.com/Code/Java/3D/Java3DBoxandacustomCuboidimplementation.htm
答案 0 :(得分:0)
看起来你正在创建一个0.6的大小的立方体,因此第一个框的+0.3和-0.3 X,Y,Z值,因为长方体的中心点是0,0,0。
第二个框相同但在一个轴上偏移0.3,在其中一个轴上给出0.3-0.3 = 0.0和+ 0.3 + 0.3 = 0.6值。
这将给出两个在一个轴上重叠的盒子,它们似乎与你的照片匹配。
也许你的意思是创建一个宽度/高度/深度为0.3 / 2的盒子并将其平移0.3 / 2,使盒子的中心位于0.15,0.15并使用比例因子0.15而不是0.3?