Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Zoom to Point with SFML  (Read 1897 times)

0 Members and 1 Guest are viewing this topic.

CodeCriminal

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Zoom to Point with SFML
« on: August 22, 2011, 07:32:00 pm »
Hello, I have managed to succesfuly implement a zoom to point mechanism using matrix transforms scale and translate. While this all works very well I would like to implement it using SFML methods, because my current technique works from outside of SFML itself and then copies the transformed points back into the shapes that im rendering. The problem with this is that it doesnt integrate well with SFML and can cause some confusing and mostly unneccesary data processing down the line of development.

How it is done:
I create a matrix, translate it to the chosen point of zoom ( in this case the mouse cursor ) so then the cursor becomes the origin, scale from this point and then translate again back to the original position creating desired view matrix, I then extract the points from each shape individually and apply the transformation outside of the class, once the transform has been applied I then reintegrate the points backinto the shape class.

Pseudo/C# code:
Matrix viewMatrix = Identity;
viewMatrix.Translate( mouse.x, mouse.y )
viewMatrix.Scale( zoomFactor, zoomFactor )
viewMatrix.Translate( -mouse.x, -mouse.y )

foreach ( shape in i )
   Transform( i, viewMatrix )


Doing it this way stops me from using the positioning/scaling/rotating properties of the shape class (and I would imagine, though untested the image class (can you even access the points of the texture quad from the image class?? this would be problematic ) )

I noticed that SFML from a client point of view has no notion of matrix/transform multiplication order, (this is irritating haha) otherwise I may have been able to solve the problem a long time ago ( SFML has been getting in the way for a while, it is only recently that I discovered the transform order let down, which is when I was finally able to half solve my problem )...

Question:
Ok this explaination has gone on long enough and is beginning to spiral out of control.. Basically, how can I perform a zoom to point mechanism using SFML? any Ideas? I want to be able to zoom only certain things in the view as I will be rendering a tiled image to clear the screen instead of a colour.

Thank you

EDIT: I tried manually applying the desired translation transform to the shape.origin, while the transform works in and of itself, SFML internals are getting in the way (when i try to scale) so if I could figure out a way to cancel out the change the that scale makes to the origin, I should be set.

 

anything