# transfering x,y coordinates from one machine to another

This topic is 2159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have two gl widgets inside two programs running on different machines. When user clicks a coordinate in the first machine, x and y coordinates should be sent to the other with the same accuracy. Also take into account that the 1st machine send image shots of the same program to my machine, and then using gl function I read raw image data and create the texture. My point is that, as long as we are dealing with images and are able to scale the image, the resolution and screen sizes of two different machine will not matter. whatever the x,y coordinate in the 1st machine is at any instant, if I get the image and scale it, I can get the exact xy coordinates in the other machine.

##### Share on other sites

multiply the coordinates by the screen resolutions ratio?

##### Share on other sites

multiply the coordinates by the screen resolutions ratio?

that would give us percentage rates, which is not accurate.

##### Share on other sites
Do you want the retain the absolute coordinates (i.e. x:60,y:10 on machine1 is x:60,y:10 on machine2) or relative coordinates (i.w. x:25%,y50% on machine1 is x:25%,y50% on machine 2)? I'm assuming the latter so I'm not sure what the issue is with the thrust of 3TATUK2's suggestion. Working with coordinates in normalized form (i.e. [0,1] or [-1,+1]) would be the obvious solution as you can map these values to whatever size/resolution you want with more than enough accuracy but I guess I must be missing something?

##### Share on other sites

Do you want the retain the absolute coordinates (i.e. x:60,y:10 on machine1 is x:60,y:10 on machine2) or relative coordinates (i.w. x:25%,y50% on machine1 is x:25%,y50% on machine 2)? I'm assuming the latter so I'm not sure what the issue is with the thrust of 3TATUK2's suggestion. Working with coordinates in normalized form (i.e. [0,1] or [-1,+1]) would be the obvious solution as you can map these values to whatever size/resolution you want with more than enough accuracy but I guess I must be missing something?

I don't think so, what I was afraid of, and what the fellows told me was if the resolution and monitor sizes differ, relative or percentage values could not be accurate.

for example, x:60 y:10 on a machine one with resolution: 1024:768 19 inch may not absolutely refer to the same point on machine 2 with resolution: 1360:768 same size.

By the way, we came to an agreement to use the same widget size and resolution for two machines. However, I still like to know if the relative case can also direct me towards accurate results.

Edited by saman_artorious

##### Share on other sites

it'll be accurate. monitor size doesn't matter.

(60,10) on 1024x768 will be (80,10) on 1360x768

At most you'll have a pixel offset of inaccuracy due to fractional component... but that shouldn't matter in practice, unless you could cook up some amazingly superb reason which would just happen to not based on practical experience :)

##### Share on other sites

it'll be accurate. monitor size doesn't matter.

(60,10) on 1024x768 will be (80,10) on 1360x768

At most you'll have a pixel offset of inaccuracy due to fractional component... but that shouldn't matter in practice, unless you could cook up some amazingly superb reason which would just happen to not based on practical experience

How do you calculate it?

I am looking for a general conversion function, is the below correct?

QPoint point = event->globalPos();
QSize size = qApp->desktop()->screen()->size();
point.setX(100 * point.x() / size.width());
point.setY(100 * point.y() / size.height());

reverse:

QPoint point;

QSize size = qApp->desktop()->screen()->size();
point.setX(size.width() * point.x() / 100);
point.setY(size.height() * point.y() / 100);

//use the point

##### Share on other sites
Nearly. This puts your point into [0,1] range:

// Assumes all values are floats so cast appropriately if not...
float relativeX = mouseX / screenWidth;
float relativeY = mouseY / screenHeight;
And now to expand from [0,1] range back into absolute positioning:

float absoluteX = relativeX * screenWidth;
float absoluteY = relativeY * screenHeight;

• 9
• 17
• 10
• 11
• 18