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

Author Topic: View Conversion Question.  (Read 3189 times)

0 Members and 1 Guest are viewing this topic.

Reevesy

  • Newbie
  • *
  • Posts: 5
    • View Profile
View Conversion Question.
« on: September 06, 2013, 02:39:23 am »
Say I wanted the y distance in pixels between two points but the view is zoomed out. For example if the distance was 100 originally it would be less now that the view has changed.

How would I calculate this new distance?

Thanks.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: View Conversion Question.
« Reply #1 on: September 06, 2013, 02:55:32 am »
Say I wanted the y distance in pixels between two points but the view is zoomed out. For example if the distance was 100 originally it would be less now that the view has changed.

How would I calculate this new distance?

First I would like to know why you need the exact pixels it would be depending on your view. You should be able to do everything without knowing the actual pixel distance based on the view.

Anyways, first you need to calculate the distance between the two points using the pythagorean theorem (this is how you calculate distance between two points all the time). You can then take that value and assuming that the view is scaled evenly and not rotated multiple the scale factor to the distance and you should get very close to the distance between the two points in screen pixels.
« Last Edit: September 06, 2013, 02:57:12 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Reevesy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: View Conversion Question.
« Reply #2 on: September 06, 2013, 02:59:47 am »
It's a rare case involving winforms controls alignment.

The solution was super obvious I should have known that, thanks.

 

anything