Jump to content
  • Advertisement
Sign in to follow this  
FoxHunter2

stuck on extremely simple equation

This topic is 5175 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

Ok, this is really embarassing, shame on me. I have a float in the range of 0.0f to 1.0f, so e.g. the point in the middle of the screen is 0.5f, on the left 0.0f and on the right 1.0f. I need to convert this value to match up with the directx perspective range which goes from -1.0f to 1.0f. So basically 0.5f would become 0.0f, 0.0f would become -1.0f and 1.0f would become 1.0f 0.0f -> -1.0f 0.5f -> 0.0f 1.0f -> 1.0f I know, this is really easy, but I can't figure out how to do this :( regards

Share this post


Link to post
Share on other sites
Advertisement
I was taught math for 13 years, just to forget even the simpliest things, thanks :)

Could you explain me how you derived the formula from the values given?

Share this post


Link to post
Share on other sites
wasn't me but here comes the answer...

0.0f - 1.0f >> -1.0f - 1.0f

0.0f * 2 = 0.0f
1.0f * 2 = 2.0f

0.0f - 1 = -1.0f
2.0f - 1 = 1.0f

>> x * 2 - 1

Share this post


Link to post
Share on other sites
Or, for a common sense answer:

You have a set of values whose range is 1 (0 to 1). You those values to be in a range of 2, so you multiply those values by 2. The range is now 0 to 2, but you want it to be -1 to 1, to you subract 1.

[Edited by - thedevdan on August 20, 2004 7:54:24 PM]

Share this post


Link to post
Share on other sites
Try thinking of it pictorially in your head, failing that draw a picture of what you want. That may work for you, different people think in different ways. Investigating how your brain works and then working on developing your method of thought and learning with that in mind can work wonders.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I find that using "y = mx + c" makes these kind of linear mappings very simple. Treat y as your output and x as your input, then you only need 2 actual cases of your mapping to solve for m and c. Hobserve:

mapping:
(x) -> (y)
0.0f -> -1.0f (1st case)
1.0f -> 1.0f (2nd case)

In the 1st case, we have:

(-1.0f) = m(0.0f) + c

hence c = -1.0f

Subs c into the second case to solve for m:

(1.0f) = m(1.0f) - 1.0f,
m = 2.0f;

so, the mapping is "y = 2x - 1"

The cool thing about this method is that it works for *any* linear mapping.


Share this post


Link to post
Share on other sites
The useless thing about that method is that it doesn't work for anything else. Fortunately many things are linear, so if you can't do it another way then your method isn't that bad. However if you find a situation where it isn't linear you then have to understand the method for solving that system as well. If you can just visualise the system then you'll always have a good shot at solving it, without any prior knowledge of the type of system involved. I'm not explaining it very well.

Let's have an example, you need an orthogonal transformation that takes given vectors to others. Try to do it using simultaneous equations and you're in for a difficult time. But understand the system and you'll be able to find some nice shortcuts.

Not a great example, oh well. Just choose whatever method you find the easiest.

Share this post


Link to post
Share on other sites
AP: the cool thing about it is that it works for any polynomial.

higherspeed: for each problem there are slow and fast answers. Of course, when problems involve more than one dimension, linear algebra will come in handy. However, for problems as simple as this one, simply considering the desired equation and substituting two known values is faster.

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!