I'm trying to draw rectangles with a certain distance in x-axis to each other.
The distance on each rectangle should be
(screen width - rectangle width)
so that only one rectangle can be fully displayed on the screen at a time. And if I drag the first rectangle to left, the portion of that rectangle not displayed (or cut) on the screen would be the amount displayed on second rectangle .
The problem is that I could not figure out how to calculate the ratio of my rectangle's width to screen width.
My rectangle vertices are
final float[] rectangleVerticesData = {
// X, Y, Z
-1.0f, 2.0f, 0.0f,
-1.0f, -2.0f, 0.0f,
1.0f, 2.0f, 0.0f,
-1.0f, -2.0f, 0.0f,
1.0f, -2.0f, 0.0f,
1.0f, 2.0f, 0.0f
};
Based above, my rectangle width is 2. I am using a tablet with 1280 pixels width.
Using the formula above, I got
1280 - 2 = 1278
When I ran the program, the expected output is not as what I am trying to achieve. When I drag the first rectangle, the next rectangle is not displayed even if the first rectangle is fully dragged to left off the screen.
When I tried hard-coding distance to 10, the rectangles are displayed with that distance. I guess 1278 is so long to be the distance between them. How can I calculate the correct distance between the triangles based on screen width so that only one rectangle can be fully displayed at a time on the screen?
Any help would be greatly appreciated. Thank you.