Hi,
I’m trying to pick objects using a Picker class that I copied and modified from somewhere on the Panda3d site.
It has a function getObjectHits() to do the picking. It looks like this:
def getObjectHit(self, targetmdl):
self.pickedObj=None #be sure to reset this
#self.pickerRay.setFromLens(base.camNode, mpos.getX(),mpos.getY())
#I think the problem has something to do with these 2 lines
self.pickerRay.setOrigin(camera.getPos())
self.pickerRay.setDirection(Vec3(targetmdl.getPos() - camera.getPos()))
self.picker.traverse(render)
#the function never proceeds further than this
if self.queue.getNumEntries() > 0:
self.queue.sortEntries()
self.pickedObj=self.queue.getEntry(0).getIntoNodePath()
#print "num entries > 0"
parent=self.pickedObj.getParent()
self.pickedObj=None
while parent != render:
if parent.getTag('pickable')=='true':
self.pickedObj=parent
return parent
else:
parent=parent.getParent()
return None
This function was originally designed to pick objects with the pickerRay set from the camera and mouse coordinates as can be seen from the commented out line with self.pickerRay.setFromLens(). I would like to have the function pick along a ray I have specified. I’m trying to set the pickerRay with setOrigin() and setDirection(). I wonder if the vector calculation I’m passing into setDirection() is wrong? I just found it from somewhere and I think it calculates a direction vector from the camera position to the position of targetmdl. Correct me if I’m wrong. I’ve also tried normalizing the result but it didn’t help. It seems that “if self.queue.getNumEntries() > 0:” is never greater than 0.