how to get mouse coordinates (x,y) in pixel instead of 3d vector?

31 views
Skip to first unread message

Horst JENS

unread,
Aug 22, 2024, 4:18:28 PM8/22/24
to VPython-users
vpython mouse question: Is there a simple way to get the mouse coordinates in screen pixel (like (0,0) for topleft corner, (800,600) for bottom right corner?

I try to make a projection of the mouse using scene.forward as vector but i am not very sucessfull.

Bruce Sherwood

unread,
Aug 23, 2024, 1:38:05 AM8/23/24
to VPython-users
Not sure whether this is what you're looking for, but when you run this program you see the x and y pixel values relative to the center of the canvas:

box()
width = scene.width = 500
height = scene.height = 500
pos = label()
while True:
    rate(60)
    p = scene.mouse.pos
    xx = int(p.x*0.5*width/0.87)
    yy = int(p.y*0.5*height/0.87)
    pos.text = vec(xx,yy,0)

Bruce

Horst JENS

unread,
Aug 27, 2024, 1:30:43 AM8/27/24
to vpytho...@googlegroups.com
thank you Bruce!!
> --
> You received this message because you are subscribed to a topic in the Google Groups "VPython-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vpython-users/9Rhv01K1ohM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to vpython-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vpython-users/c695e126-6ae4-4248-b043-1d86cb339cden%40googlegroups.com.



--
First name: Horst tel:+43 660 46 64 611
Last name: JENS
Email: hors...@gmail.com
horst...@spielend-programmieren.at
Web: https://spielend-programmieren.at
Reply all
Reply to author
Forward
0 new messages