Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411520 Posts in 69380 Topics- by 58436 Members - Latest Member: GlitchyPSI

May 01, 2024, 02:24:06 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)3d projection
Pages: [1]
Print
Author Topic: 3d projection  (Read 1838 times)
Dan Cardin
Level 0
**


Man Flardin?


View Profile
« on: April 22, 2010, 05:18:55 AM »

I wonder if any of you knows of a good place to learn about 3d projection. The only semi good "tutorial" I've found is "building a 3d portal engine" on flipcode.com. In my opinion he doesn't fully explain many of the concepts and I would really like to understand everything rather than using something that I don't understand blindly.
Logged
muku
Level 10
*****


View Profile
« Reply #1 on: April 22, 2010, 07:14:22 AM »

It's actually surprisingly simple. Let me steal this image from the Wikipedia page on 3D projection:



For simplicity, this is the case of projecting a 2D scene onto a 1D viewing plane, but it's trivial to just apply this twice for both the x and the y coordinate.

So let's say your eye point is at (0,0), and the point you are looking at is at (Ax,Az). The viewing plane that we want to project onto lies at a distance of Bz from the eye. If you have heard about similar triangles before, you will know that the following ratios are equal:

Ax / Az = Bx / Bz

We want to find the projected x coordinate of our point (Ax,Az), which is just Bx. So we rearrange a bit:

Bx = Ax / Az * Bz

And there you have it: projecting a point onto the viewing plane is basically nothing else but dividing it by its z coordinate, and then multiplying it by the distance to the viewing plane.

So what to do if your camera is not at (0,0) and is not looking into positive z direction? Easy: just translate and rotate your entire world until the camera is in this standard position again. That's exactly what OpenGL does, by the way.

Does this help?
Logged
Dan Cardin
Level 0
**


Man Flardin?


View Profile
« Reply #2 on: April 22, 2010, 01:25:18 PM »

So that basically means that the amount of projection is arbitrary. How wide and whatnot things are along with how much perspective is just randomly chosen?

Have you anything to input about 3d rotation and matrix concatenation, etc?
Logged
Krux
Level 2
**



View Profile
« Reply #3 on: April 22, 2010, 01:45:12 PM »

try to search for linear algebra. That should teach you anything you want to know.
Logged
muku
Level 10
*****


View Profile
« Reply #4 on: April 22, 2010, 02:43:19 PM »

So that basically means that the amount of projection is arbitrary. How wide and whatnot things are along with how much perspective is just randomly chosen?

There's nothing random about it. In the model I showed you, you had one parameter to play with, namely the distance to the projection plane. Another way to look at it is that changing this distance also changes the field of view of your projection.

Let's say you render the interval [-1, 1] of the projection plane into your video window. In the sketch above, this interval corresponds to the black horizontal line between the two red lines. Everything that falls outside of this interval lies outside your field of view. Let's abbreviate the field of view angle, that is, the angle between the two red lines, by fov. Then, by the definition of the tangent, we have

tan(fov / 2) = 1 / Bz,

where Bz is again the distance to the projection plane. You can now use this equation to either express Bz,

Bz = 1 / tan(fov / 2),

or fov,

fov = 2 * atan(1 / Bz).

So, in any case it's just one parameter that you can freely choose, either Bz or fov, but this gives you an easy way to convert between the two. As you move the projection plane closer, that is, make Bz smaller, the field of view angle increases, and vice versa.

(I just sort of winged it with the formulae, so sorry if I messed any of them up.)

For 3D rotation and matrix algebra, I feel this would be too long-winded to explain in a post here, but there should be lots of tutorials out there which explain this kind of stuff. Here's a random one I just googled: http://chortle.ccsu.edu/VectorLessons/vectorIndex.html

If you have any particular questions, though, feel free to ask.
Logged
Dan Cardin
Level 0
**


Man Flardin?


View Profile
« Reply #5 on: April 22, 2010, 06:18:59 PM »

when i said random i meant in general. Like you could make it anything. unless there is a generally accepted value that most people put it on, in games the value is randomly chosen?
Logged
muku
Level 10
*****


View Profile
« Reply #6 on: April 23, 2010, 12:02:15 AM »

when i said random i meant in general. Like you could make it anything. unless there is a generally accepted value that most people put it on, in games the value is randomly chosen?

No, it's not. I just tried to explain this above: by changing Bz, you automatically also change the field of view, which has a very distinct effect on the final rendered image. Take a look at this page (left column):

http://strlen.com/gfxengine/fisheyequake/compare.html

That's what happens when you play with the projection distance/field of view angle. So adjusting this parameter is often a conscious design choice.
Logged
mattfox12
Level 0
**



View Profile WWW
« Reply #7 on: April 23, 2010, 11:23:17 AM »

I learned about it in the book Foundation ActionScript Animation: http://amzn.com/1590595181 (I'm not trying to promote the buying of it through amazon, it was just easy to find there)

Teaches the concept to you in Flash, but the code and concepts apply to any programming. It's a fantastic resource.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic