Jump to content

  • Log In with Google      Sign In   
  • Create Account

OpenGL 2D Selection Scaling Multiple Times


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Jevi   Members   -  Reputation: 127

Like
0Likes
Like

Posted 23 December 2012 - 05:58 PM

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.

 

original.png

 

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

 

originalzooming.png

 

This is the result of that first selection scaled

 

zoomedin.png

 

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

 

zommedinzooming.png

 

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);
					}
					else
					{
						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

 

        glLoadIdentity();
	glOrtho(_portionStart.x, _portionEnd.x, _portionEnd.y, _portionStart.y, 1, -1);

Edited by Jevi, 24 December 2012 - 02:31 PM.


Sponsor:

#2 Jevi   Members   -  Reputation: 127

Like
0Likes
Like

Posted 24 December 2012 - 06:17 PM

This question has been answered here: http://stackoverflow.com/questions/14025740/convert-sdl-window-position-to-opengl-world-position


Edited by Jevi, 24 December 2012 - 06:18 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS