我是3d引擎的新手,当我试图碰撞一个几何和一个NullPointerException物体时,我得到了这个3D引擎。
以下是我如何声明我的目标(对不起,目前相当混乱)
public void simpleInitApp() {
Quad q= new Quad(100, 100);
Dome mesh = new Dome(Vector3f.ZERO, 2, 32, 1f,false);
geom = new Geometry("Cylinder", mesh); //declared elsewhere
g3 = new Geometry("lel", q);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
geom.setMaterial(mat);
g3.setMaterial(mat2);
rootNode.attachChild(geom);
rootNode.attachChild(g3);这是我的更新循环
public void simpleUpdate(float tpf) {
// System.out.println("hi");
BoundingVolume b = g3.getWorldBound(); //should give boundingvolume of the quad
System.out.println(b.getVolume()); //just to test if this works
CollisionResults r2 = new CollisionResults(); //declare and initialize the collisionresults
geom.collideWith(b, r2); //collide
System.out.println(r2.size()); //this returns a value, usually between 0-2
for(CollisionResult x:r2){
System.out.println("x = "+ x.getContactPoint().getX());
/*and oddly enough, i get a NullPointerException here even though the collision appeared successful - this never prints anything either so it's not going out of bounds or anything*/
}
}当我试图从一个NullPointerException和一个几何的交集中打印出每个CollisionResult的坐标时,得到一个BoundingVolume。
JMonkey论坛和JMonkey文档似乎都没有任何帮助。你们谁能帮上忙?提前谢谢。
发布于 2014-10-29 20:18:31
你的模型不附属于JBullet物理。试着像这样:
BulletAppState buleltAppState;
public void simpleInitApp() {
Quad q= new Quad(100, 100);
Dome mesh = new Dome(Vector3f.ZERO, 2, 32, 1f,false);
geom = new Geometry("Cylinder", mesh); //declared elsewhere
g3 = new Geometry("lel", q);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
geom.setMaterial(mat);
g3.setMaterial(mat2);
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.getPhysicsSpace().attachChild(geom);
bulletAppState.getPhysicsSpace().attachChild(g3);
rootNode.attachChild(geom);
rootNode.attachChild(g3);
}在那之后,你可以检查碰撞!
发布于 2014-10-01 15:48:05
我做了一些研究,我相信问题是,在二维/三维物体之间没有单一的碰撞点,而是有一个2D/3D碰撞区域。因此,如果没有单点可用,则返回null。这是由开发人员的评论备份的。我相信JMonkey碰撞检测实际上并不计算相交区域,因为它在数学上非常复杂(虽然它确实给出了碰撞中涉及的三角形)
如果你的两种形状都是凸的,你可能会对计算三维多边形交叉口的文章感兴趣:求两个三维多边形的相交。
https://stackoverflow.com/questions/26111291
复制相似问题