Regarding the transformation itself, it's not a problem. However, where I continually run into trouble is when i need to preserve the aspect ratio if the screen size changes. In other words, if I have a 640x480 screen, whatever I render there needs to look the same in terms of ratios no matter what the screen size changes to.
I understand that I do not need to mess with how I change my y-coordinates for this preservation (because math), but I can't quite figure out how to do it with the x-coordinates.
Here's the function.
Width is currently 640, height is 480.Code:float world_to_pixel_x(float height, float width, float x){ //x *= width/height; float d = (width-1)/2; float c = d; //return (c*x+d)*(width/height); return c*x+d; //adjust for scaling }
As of now, it will translate properly, adjusting the origin to the center of the screen, but if I were to change the numbers on width and height around, the rendered image would be stretched and look terrible.
The two pieces of commented code are two things I've tried, both to no avail. The first one (x *= width/height works in the sense that it preserves aspect ratio, but it varies from size to size, since the stretch is determined by the ratio (about 1.333 in this case). The second one works in that the size of the object's shape is constant through any change in the window size, but it is displaced from the origin. Both segfault if there is a significant difference between the width and height (i.e. width = 640, height = 200).
Any help would be appreciated