translating mouse/screen coordinates to world coordinates on a custom plane

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

translating mouse/screen coordinates to world coordinates on a custom plane

Post by MRx »

I'm trying to translate the current coordinate of the mouse to world coordinates on a defined plane

Update:
I think I figured it out.

Code: Select all

plane=coin.SbPlane(coin.SbVec3f(0,0,1), 30.0)
planeproj=coin.SbPlaneProjector(plane)
vpr=Gui.ActiveDocument.ActiveView.getViewer().getSoRenderManager().getViewportRegion()
matrix=coin.SoGetMatrixAction(vpr)
matrix.apply(Gui.ActiveDocument.ActiveView.getSceneGraph())
planeproj.setWorkingSpace(matrix.getMatrix())
fRatio=vpr.getViewportAspectRatio()
sp=vpr.getViewportSizePixels()
vvolume=Gui.ActiveDocument.ActiveView.getViewer().getSoRenderManager().getCamera().getViewVolume(fRatio)
c=Gui.ActiveDocument.ActiveView.getCursorPos()
currentpos=(vpr.getViewportSize().getValue()[0]*c[0]/sp.getValue()[0], vpr.getViewportSize().getValue()[1]*c[1]/sp.getValue()[1])
planeproj.setViewVolume(vvolume) 
p=planeproj.project(coin.SbVec2f(currentpos))
print(p.getValue())
freedman
Veteran
Posts: 3440
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: translating mouse/screen coordinates to world coordinates on a custom plane

Post by freedman »

Thanks for posting, I will try to do some testing.
Post Reply