Need help with ODE mouse picking

Hi, i need help with a mouse picking class that im writing.
In the panda collision detection, to use mouse pick you use this, right?

pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY()) 

but in ODE, how do you do to get the right vector???, i always get it wrong

self.raygeom.set(Vec3(base.camera.getPos()), #This is the origin of the ray#
Vec3(1,self.mouseX,self.mouseY)) #And this is the vector that is supposed to point to my cursor# 

Maybe i need to calculate exta vectors to point in the right direction, but always points weird instead of forward

for the exact vector you also need your fov:

->

import math
hscale=math.tan(math.radians(camLens.getHFov()/2.0))
vscale=math.tan(math.radians(camLens.getVFov()/2.0))
aimvec=base.camera.getQuat().xform(Vec3(1,hscale*self.mouseX,vscale*self.mouseY)))

now aimvec points from the camera to where you see your cursor

propably not the most elegant way but…

edit: forgot /2.0
edit2: forgot xform

Well, I do it like this:

self.aimRay = OdeRayGeom(self.space)

quat = base.cam.getQuat(render)
dir = quat.xform(Vec3(0, 1, 0))
pos = base.cam.getPos(render)

self.aimRay.set(pos, dir)

Quat.xform() rotates the vector so that you get a vector relative to the camera’s rotation aiming front right from the camera.

I don’t know if that’s the best way to deal with that, but I use it in my code for picking, shooting etc. and it works well.

Obviously, you need to call set every time you want to pick something up to update the position of the ray. Or every time you shoot if you want that mechanics for this as well. There’s no point in updating it in every world step though.

EDIT:
I have just found this:

dir = render.getRelativeVector(base.cam, Vec3(0, 1.0, 0))

And it seems to do the job… The interesting thing is that I’ve found it in my own code, just in another place xD