我在 Java3D 中创建了一个房间,并添加了用户使用键盘移动选定对象的功能。我只是想知道是否有可能检测到我的两个对象之间的碰撞。我只想让用户在某个方向上移动一个对象,直到它与另一个任意对象发生碰撞。
如果有帮助,这是我的两个对象:
地毯:
public class Carpet3D extends Group{
public Carpet3D() {
this.createSceneGraph();
}
public void createSceneGraph() {
Appearance appearance = getCarpetAppearance();
//Carpet
int primitiveflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS;
Box floorShape = new Box(1.7f, .015f, 2.3f,primitiveflags,appearance);
this.addChild(floorShape);
}
}
餐桌:
public class DinnerTable3D extends Group{
public DinnerTable3D() {
this.createSceneGraph();
}
public void createSceneGraph() {
Appearance appearance = getWoodenAppearance();
//Table TOP
int primitiveflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS;
Box tableTop = new Box(1.2f, .035f, .8f,primitiveflags,appearance);
TransformGroup tableTopGroup = new TransformGroup();
tableTopGroup.addChild(tableTop);
this.addChild(tableTopGroup);
//Dinner Table Legs
Box tableLeg = new Box(0.06f,.72f,0.06f, primitiveflags,appearance);
SharedGroup dinnerTableLegs = new SharedGroup();
dinnerTableLegs.addChild(tableLeg);
//Leg 1
this.addChild(Main.setPositionOfObject(new Vector3f(-1.14f,-0.755f,-.74f), dinnerTableLegs));
//Leg 2
this.addChild(Main.setPositionOfObject(new Vector3f(1.14f,-0.755f,.74f), dinnerTableLegs));
//Leg 3
this.addChild(Main.setPositionOfObject(new Vector3f(1.14f,-0.755f,-.74f), dinnerTableLegs));
//Leg 4
this.addChild(Main.setPositionOfObject(new Vector3f(-1.14f,-0.755f,.74f), dinnerTableLegs));
}