# Discrepancy when projecting model points to screen coords

Hi,

I’m having trouble converting from model coordinates to screen coordinates. Its working in one view, but when I rotate the camera, there is a discrepancy that shows up.

So I use a ray picker (CollisionRay) to compute model coordinates from the screen coordinates of the mouse. To compute the inverse I do:

``````# set v, w to screen width, height respectively

projected=Point2(0,0)
lens=cam.node().getLens()
mat=cam.getMat()
v4=Vec4(pos[0],pos[1],pos[2],1)
v4_xfrm=mat.xform(v4)
p3_prjct=Point3(v4_xfrm.x,v4_xfrm.y,v4_xfrm.z)
posP=Point3(pos[0],pos[1],pos[2])
lens.project(posP,projected)``````

My model space is Zup coordinate system, right handed. When I do

``lens.getCoordinateSystem()``

I get 0.

I’ve looked at this: panda3d.org/forums/viewtopi … +intrinsic

But my issue isn’t a constant offset like his is (and which seems to have fixed jeremy’s problem)

Anyhow, after playing around, I found that if I plot a dot at the following screen coordinates (which should hopefully be the mouse’s screen coordinates) I can get some functionality:

``````xs=(1+projected.x)*v/2
ys=-(1-projected.y)*w/2``````

Assuming the model-coords to screen-coords works fine, the plotted dot should exactly match the mouse position on screen, but its not working.

The camera is set up to point towards central object from the outside. When in one view, set as follows:

``````cam.setHpr(0,0,0)
cam.setPos(0,0,0)
cam.setPos(cam,0,-c,0)``````

…where c is positive, the plotted point matches the mouse position precisely for all positions.

However, when I flip to Hpr of (180,0,0), i.e.:

``````cam.setHpr(180,0,0)
cam.setPos(0,0,0)
cam.setPos(cam,0,-c,0)``````

then the plotted point exhibits the same y-value on the screen as the mouse, but the x-value travels the opposite direction as the mouse’s x-value but meets in the middle. In other words, if I put the mouse in the middle of the screen, the plotted point is with the mouse. Move mouse up, point moves up. Move mouse to the right, point moves to the left, and visa versa.

I’d greatly appreciate if someone can point out where the problem could be or where to look further.

Thank you so much