Tag: box2d

box2d联系人监听器命令

我试图了解它是如何工作的。 在我的游戏中我使用box2d物理,处理我使用联系人监听器的联系人,例如: ContactListener contactListener = new ContactListener() { @Override public void beginContact(Contact contact) { final Fixture x1 = contact.getFixtureA(); final Fixture x2 = contact.getFixtureB(); if (x1.getBody().getUserData() != null && x2.getBody().getUserData() != null) { if (x1.getBody().getUserData().equals(“player”)) { player.increaseFootContacts(); } } } 这里的问题是,那些灯具中有任何订单吗? (x1或x2)经过2次测试,我发现在这种情况下,我的播放器将是x1,而其他对象是x2,我是否也应该检查相反的顺序? (如果x2是玩家等等)?

为什么在Java float比较中使用Float.floatToIntBits()?

在JBox2d中, Vec2.equals()存在以下代码: @Override public boolean equals(Object obj) { //automatically generated by Eclipse if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec2 other = (Vec2) obj; if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) return false; if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) return false; return true; } 我想知道float int位转换函数的用途是什么,这里。 这是否提供了解决Java浮点数比较不准确问题的方法(如果可能的话)? 还是完全不同的东西? 我想知道它是否是epsilon方法的替代方案: […]