Jump to content
  • Advertisement
Sign in to follow this  

OpenGL OpenGL 2D Selection Scaling Multiple Times

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to scale into a base image multiple times. So I should be able to from a base image which has no scale factor (or scale factor of 1) scale into it and then from that scaled image generated from the base image I should be able to scale into it again and again and again. My problem is that I do not know how to calculate what the x and y coordinate of the mouse should be when trying to select a region from a scaled image. Here are some images that will describe my situation.


*Note that all the red coordinates are what the x and y coordinates should be but the mouse x and y coordinates are always from 0,0 to 640,480 ( the display dimensions )


This is my base image. Note the stating x and y coordinates.




This is the selection of the portion that will be scaled from the original x and y coordinates




This is the result of that first selection scaled




I want to be able to do another selection scale from this image but as I stated I don't know how to calculate what the x and y coordinates should translate to.


This is an example of what I should be able to do




Note that I am also translating the image to the center of the selection so that the scaled in image will be centered in the display.


This is what I am currently doing to scale from the base image to a scaled image. *note that this does not work when trying to scale and already scaled image as I said because I need to calculate what the actual x and y coordinates of the mouse should be. The first 4 lines is where I presume the calculations of the actual x and y coordinates should be.

				// modify mouse coordinates to fit scaled image
				_mouseStart.x = _mouseStart.x;
				_mouseStart.y = _mouseStart.y;
				_mouseEnd.x = _mouseEnd.x;
				_mouseEnd.y = _mouseEnd.y;

				// get width and height of selection
				float ratio = (float) SCREEN_WIDTH / (float) SCREEN_HEIGHT;
				float newFracWidth = fabs(_mouseEnd.x - _mouseStart.x);
				float newFracHeight = newFracWidth / ratio;

				if (newFracWidth > 0 && newFracHeight > 0)
					Vertex starts;
					Vertex ends;

					if (_mouseStart.x > _mouseEnd.x)
						starts.x = _mouseStart.x - newFracWidth;
						starts.y = _mouseStart.y - newFracHeight;

						ends.x = _mouseStart.x;
						ends.y = _mouseStart.y;

						_fracNormalCenter.x = _mouseStart.x - (newFracWidth / 2);
						_fracNormalCenter.y = _mouseStart.y - (newFracHeight / 2);
						starts.x = _mouseStart.x;
						starts.y = _mouseStart.y;

						ends.x = _mouseStart.x + newFracWidth;
						ends.y = _mouseStart.y + newFracHeight;

						_fracNormalCenter.x = _mouseStart.x + (newFracWidth / 2);
						_fracNormalCenter.y = _mouseStart.y + (newFracHeight / 2);
					_portionStart.x = starts.x;
					_portionStart.y = starts.y;
					_portionEnd.x = ends.x;
					_portionEnd.y = ends.y;

					cout << "glOrtho Dimension: : " << _portionStart.x << " , " << _portionStart.y << " -- " << _portionEnd.x << " , " << _portionEnd.y << endl;

					starts = NormalToComplex(starts);
					ends = NormalToComplex(ends);

					_scaleFactor = (SCREEN_WIDTH / newFracWidth);

					// set new complex display dimensions
					_fracStart.x = starts.x;
					_fracStart.y = starts.y;
					_fracEnd.x = ends.x;
					_fracEnd.y = ends.y;

					_pointOffSet.x = (SCREEN_WIDTH / 2) - _fracNormalCenter.x;
					_pointOffSet.y = (SCREEN_HEIGHT / 2) - _fracNormalCenter.y;




This is how I set the new scaled image


	glOrtho(_portionStart.x, _portionEnd.x, _portionEnd.y, _portionStart.y, 1, -1);
Edited by Jevi

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!