Original Post
🔒 Locked
2d bounding rectangle
Advertisement
Here's some code to gen min/max points on a 2D polyon. If you want a bounding cube just add the z.
Edited by - neocron on September 25, 2000 6:14:25 PM
|
Edited by - neocron on September 25, 2000 6:14:25 PM
Here''s some code: fOffX and fOffY are ususlly half-screen-width and half-screen-height respectively. fproj is the Projection Ratio = (dist from view plane)/(view plane width).
...or something like this. Hope it helps!
|
...or something like this. Hope it helps!
Projection is a little different than just setting z=0, except for a special case that I''ll mention later.
You know how when you look down a long street, the distant parts are narrower than the nearby parts? Imagine if your view of the street was on a monitor (a 2D plane). The width of the street (x-direction) is constant in 3D, but gets smaller in 2D due to perspective. So when you project into 2D, you have to consider this ''perspective division''.
The perspective effect can be large or small depending on your field of view. A wide field of view will give a large perspective effect (like a wide-angle lens on a camera). A narrow field of view is like a telescope, and gives a small perspective effect.
The special case I mentioned above is an extremely narrow field of view where the perspective effect becomes zero. This is called on orthographic projection. (Don''t try to set it up using a zero fov, it won''t work. There are special functions in Direct3D and OpenGL for setting up orthographic projections).
BTW, you can use gluProject() and gluUnProject() in OpenGL to transform coordinates between monitor (2D) and world (3D) coordinates. There may be similar functions in Direct3DX or the Direct3D utility library.
Hope this helps.
You know how when you look down a long street, the distant parts are narrower than the nearby parts? Imagine if your view of the street was on a monitor (a 2D plane). The width of the street (x-direction) is constant in 3D, but gets smaller in 2D due to perspective. So when you project into 2D, you have to consider this ''perspective division''.
The perspective effect can be large or small depending on your field of view. A wide field of view will give a large perspective effect (like a wide-angle lens on a camera). A narrow field of view is like a telescope, and gives a small perspective effect.
The special case I mentioned above is an extremely narrow field of view where the perspective effect becomes zero. This is called on orthographic projection. (Don''t try to set it up using a zero fov, it won''t work. There are special functions in Direct3D and OpenGL for setting up orthographic projections).
BTW, you can use gluProject() and gluUnProject() in OpenGL to transform coordinates between monitor (2D) and world (3D) coordinates. There may be similar functions in Direct3DX or the Direct3D utility library.
Hope this helps.
I forgot something.
Even in an orthographic projection, setting z=0 will only project from 3D to 2D under a narrow set of circumstances:
1. Camera is looking directly down z-axis
2. Orthographic extents of your viewport match screen coordinates (if your window is 800x600 pixels your world space must be 800 units wide and 600 units high)
3. The camera is not rotated off the ''usual'' position (up vector is +y)
These circumstances are so restrictive that you may as well be in 2D rather than 3D.
The moral is: Don''t try to project from 3D to 2D using z=0.
Even in an orthographic projection, setting z=0 will only project from 3D to 2D under a narrow set of circumstances:
1. Camera is looking directly down z-axis
2. Orthographic extents of your viewport match screen coordinates (if your window is 800x600 pixels your world space must be 800 units wide and 600 units high)
3. The camera is not rotated off the ''usual'' position (up vector is +y)
These circumstances are so restrictive that you may as well be in 2D rather than 3D.
The moral is: Don''t try to project from 3D to 2D using z=0.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement