I was trying with the ray casting stuff in Panda3d. So I went on defining a bullet world by,
world = BulletWorld()
world.setGravity(Vec3(0, 0, -9.81))
then I defined a ground plane with the following lines of codes,
shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
node = BulletRigidBodyNode('Ground')
node.addShape(shape)
np = render.attachNewNode(node)
np.setPos(0, 0, -2)
world.attachRigidBody(node)
and placed couple of simple boxes at the origin,
model = loader.loadModel("boxes.dae", noCache=True)
model.setPos(-0.5, -0.5, -0.5)
model.setHpr(0, 90, 0)
model.flattenLight()
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
node = BulletRigidBodyNode('Box')
node.setMass(1.0)
node.addShape(shape)
np = render.attachNewNode(node)
np.setPos(0, 0, 0)
world.attachRigidBody(node)
model.copyTo(np)
After this, I defined a ray with
RayOrigin = Point3(0.4, -10, 0.2)
RayEnd = Point3(0.4, 10, 0.2)
and rendered a line segment to check if the ray casting is indeed working or not, with
segs = LineSegs('lines')
segs.setColor(1, 1, 1, 1)
segs.moveTo(RayOrigin)
segs.drawTo(RayEnd)
segsnode = segs.create()
render.attachNewNode(segsnode)
Finally I called the rayTestClosest() function to check if the ray is in collision with the boxes, with
result = world.rayTestClosest(RayOrigin,RayEnd)
print(result.hasHit())
print(result.getHitPos())
To my surprise, the rayTestClosest is returing True even if the ray is not intersecting the boxes. Here is a screenshot of that
What am I missing here?
Thanks in advance.