Retrieving Mouse Coordinates (relative to screen, not canvas)

49 views
Skip to first unread message

Josh Gates

unread,
Mar 29, 2017, 11:17:56 AM3/29/17
to Glowscript Users
Is there a way in GS to get the screen coordinates of the mouse? I know of libraries that I could import in Python to do it, but I'm trying to make a tool that's usable through the GS web interface that'll do it.

Thanks,
jg

Bruce Sherwood

unread,
Mar 29, 2017, 1:20:24 PM3/29/17
to Glowscript Users
By screen do you mean browser window? Or do you mean pixel x,y rather than "real-world" x,y within a canvas? What is this for?

I don't understand how there could be a Python library for true Python programs, because Python doesn't deal with graphics or mouses.

Josh Gates

unread,
Mar 29, 2017, 2:52:45 PM3/29/17
to Glowscript Users
The screen coordinates - pixel addresses (relative to bottom left, maybe?). PyMouse, Tkinter, etc. will do it in regular Python, but I can't import libraries in GS (or in Trinket), so I'm trying to do it within GS itself.

It was a request from another teacher whose kids were doing some sort of extrusion, and he wants them to be able to click in a bunch of places and then save a list of the coordinates.

jg

Bruce Sherwood

unread,
Mar 29, 2017, 3:20:14 PM3/29/17
to Glowscript Users
So it sounds like you want pixel positions within the canvas, not for the entire window?

What's wrong with using the coordinates currently available? Note that with scene.fov set to some small number (such as 0.01) you have a flat space. Presumably too it would be important to set scene.userzoom = False and scene.userspin = False. From what you've said so far I don't get the point of pixel info.

Maybe this is what you want, so that mouse coordinates will be pixel coordinates (with <0,0> at the center of the canvas):

w = 800
scene.width = scene.height = w
scene.range = w/2
scene.fov = 0.01
scene.userzoom = scene.userspin = False

Josh Gates

unread,
Mar 29, 2017, 4:16:34 PM3/29/17
to Glowscript Users
Not, definitely for the window. If the desktop resolution is 1024x768, then I want coordinates from 0,0 to 1024,768, because that's what the program that they're using will map onto, rather than the canvas coordinates from GS.  What I can do currently in GS is get the canvas coordinates, which aren't the right ones, and it only registers when I'm over the canvas - I need the entirety of the computer screen.

There might not be a way to do it, but I wanted to make sure before I looked for a third-party utility that'd have to be installed.

Thanks,
jg

Bruce Sherwood

unread,
Mar 29, 2017, 4:36:22 PM3/29/17
to Glowscript Users
So you don't want x,y from the "window", you want x,y from the physical screen, independent of the size and placement of windows and/or canvases. No, there's nothing in the GlowScript world for that. Even if you find a JavaScript library to import, there's surely a big problem meshing with the mouse and event handling of GlowScript.

I'm still puzzzled, though. Different screens have different numbers of pixels, not necessarily 1024 by 768, so why can't you simply make a canvas that is, say, 800 by 600 (to fit onto all computer screens and have the same 3:4 ratio as 768:1024) and work within that canvas? There's certainly no difficulty in transforming -400 to +400 to 0 to 1024, and no difficulty in transforming -300 to +300 to 0 to 768. What am I missing?

Josh Gates

unread,
Mar 30, 2017, 8:44:33 AM3/30/17
to Glowscript Users
Looks like the original description of the teacher left out some important details. He wants to be able to click points on an image and save them, so Logger Pro is a better way to go. Ah, well - good to learn more about the capabilities of GS!

Thanks,
jg

Bruce Sherwood

unread,
Mar 30, 2017, 9:49:10 AM3/30/17
to Glowscript Users
It does sound like a task that needs an application that is designed for the purpose. I will nevertheless point out that one could use the image as a texture on a thin box and get coordinates with the mouse. There is however the problem that the image would have to be available on a CORS-enabled site like i.mgur.com.
Reply all
Reply to author
Forward
0 new messages