Followers 0

# Why potatoeses

## 14 posts in this topic



0

##### Share on other sites

I don't understand how ints could be used instead of floats in DirectX. floats have a huge range and similar relative errors across the range. If you were to use ints, how would you encode the normalized vector (0.707107f, 0.707107f, 0)?
2

##### Share on other sites

Edited by RoundPotato
0

##### Share on other sites

About the "why" part, it's because it makes a lot of things substantially easier, not only conceptually but also the involved math. Plus, it is something that you kind of have to do anyway in order to bring everything on screen, but by normalizing (instead of projecting into, say, a 1024x768x1 coordinate system) you do not have to bother about the actual resolution any more.

As an example where it makes your life easier, take clipping. Finding out whether something is inside your viewing frustum is quite non-trivial work. Not like this can't be done, but it's 6 plane tests, which is considerable work compared to...

... having transformed everything to NDC, anything in [-1, +1] is inside, the rest is not.

Edited by samoth
1

##### Share on other sites
You can convert coordinate by coordinate. If you want something that maps [-1,1] to [0,Width] linearly,

pixel_x = (ndc_x + 1) * Width / 2

Similarly,

pixel_y = (ndc_y + 1) * Height / 2

[EDIT: You may have to put a -' in front of ndc_y', depending on the conventions you are using.]

If you don't know how to deduce the inverse formulas, you should probably stop what you are doing and learn some basic algebra. Edited by Álvaro
1

##### Share on other sites

Edited by RoundPotato
0

##### Share on other sites
I chose [-1,1] instead of [0,1] because that's the typical range of NDC. If I remember correctly, OpenGL uses [-1,1] for all three axes, and DirectX uses [-1,1] for x and y and [0,1] for z.
0

##### Share on other sites

As an example where it makes your life easier, take clipping. Finding out whether something is inside your viewing frustum is quite non-trivial work. Not like this can't be done, but it's 6 plane tests, which is considerable work compared to...
... having transformed everything to NDC, anything in [-1, +1] is inside, the rest is not.

Minor nitpick, but: you don't have to be in NDC to do simple clipping. After the projection transformation but before the perspective divide you can simply clip everything to [-w, w] (which, after the perspective divide, would be [-1, 1]). And doing clipping before going to NDC makes it so you can still linearly interpolate attributes to create the new verts.

Also, I feel a kinship with you because our (case insensitive) handles are only different by one character

0

##### Share on other sites

Edited by RoundPotato
0

##### Share on other sites

I chose [-1,1] instead of [0,1] because that's the typical range of NDC. If I remember correctly, OpenGL uses [-1,1] for all three axes, and DirectX uses [-1,1] for x and y and [0,1] for z.

Oh, so by adding 1 you make it positive and later divide by 2 to make up for adding 'that half of the screen' ???

Yes. One way to think about it is that (x + 1) / 2 maps the interval [-1,1] to [0,1], and multiplying by Width maps [0,1] to [0,Width].
1

##### Share on other sites

Edited by RoundPotato
0

##### Share on other sites


Edited by RoundPotato
0

##### Share on other sites
I grew up in an environment where I didn't know anyone that knew math or programming, and I was really interested in both. I didn't have access to many books and the Internet hadn't been invented yet. All in all, you are probably better off learning in today's environment, with easy online access to tons of resources and experts. But there is something to be said about learning to fight with a problem and having to learn to convince yourself that your answer is correct without external help, by trying a few examples or proving a few theorems. I think you should give it a try and find out for yourself if you are right or not.
0

##### Share on other sites


Edited by RoundPotato
0

##### Share on other sites
The counter to that is that debugging is an important skill for a programmer. The most important thing you might learn with your current efforts could very well be the ability to efficiently explore the workings of your program so you can understand those "quirks".

Your formulas are probably right, although the notation you used to describe what your are doing is imprecise or at least not standard.
0

## Create an account

Register a new account