-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
We're using the ably live cursors (via spaces) for a collaboration feature in our product. When clients are using different sized screens the cursors are not being interpolated correctly hence they show up in the wrong position on clients. I've attempted to solve this by converting the (x,y) position from pixels to a percentage of the canvas but it is still wrong for the horizontal X axis.
percentage = (position / canvasLen) * 100
Thew above formula is applied to the X and Y axis. I've also tried to scale the pixel positions like below (which also doesn't work):
function transformCoordinates(
client1_x: number,
client1_y: number,
client1_width: number,
client1_height: number,
client2_width: number,
client2_height: number
): [number, number] {
// Calculate the scaling factors for width and height dynamically based on the x-coordinate
const scale_x: number = client2_width / client1_width;
const scale_y: number = client2_height / client1_height;
// Adjust the scaling factor based on the x-coordinate (you can customize this adjustment as needed)
const adjusted_scale_x: number = scale_x * (client1_x / client1_width);
// Apply the adjusted scaling factor to the x-coordinate
const client2_x: number = Math.floor(client1_x * adjusted_scale_x);
const client2_y: number = Math.floor(client1_y * scale_y);
return [client2_x, client2_y];
}
Please share any examples or cases of how to do this using Ably.
Metadata
Metadata
Assignees
Labels
No labels