#8555 - DracoX5 - Mon Jul 14, 2003 6:55 am
I'm making a program that has to make 2D images of 3D scenes. How would I go about calculating where 3D vertices of a polygon would go on a 2D image of it, given a certain angle?
For example: a triangle with points (0,0,0), (0,-5,0), (3,2,2) looks somthing like this if the z axis is pointed straight out:
[Images not permitted - Click here to view it]
Calculating this is easy; just drop the z coords. But if I had a different viewing angle, how would I get the points?
#8558 - Touchstone - Mon Jul 14, 2003 5:30 pm
I think you're a bit off asking that question here.
I don't say people here can't help but this is a place where people discuss gba programming and related stuff. It's like asking about airplanes in a car discussion forum. "Hey guys, I'm creating a flying machine. How can I make it fly? I figure it has something to do with the wings and aerodynamics and stuff."
It's not necessarily wrong to ask that question here but you are more likely to get help if you ask this question where people primary discuss 3D math.
_________________
You can't beat our meat
#8559 - peebrain - Mon Jul 14, 2003 6:37 pm
Actually, you're supposed to divide by the z coordinate if you want it to be perspective. You can drop the z coord if you want it to be like a CAD program. For example, if you make a box, using the perspective divide by z method, viewing the box head on you get what looks like a square inside another square with lines connecting the corners. Using the drop-z-coord method you just get a square. Let's see if I can ascii it.... (this should be interesting)
Code: |
screen.x = point.x / point.z
screen.y = point.y / point.z
+-----+
|\ /|
| +-+ |
| +-+ |
|/ \|
+-----+
screen.x = point.x
screen.y = point.y
+-----+
| |
| |
| |
| |
+-----+
|
I suggest reading the book The Black Art of 3d Game Programming by Andre LaMothe. It explains a lot of the basics behind 3d graphics in a real clear and easy to understand way.
Basically what I'm saying is: If you just drop the z coordinate, things far away will be the same size as things close. If you divide by the z coordinate, things close will be bigger, and things far away will be smaller.
~Sean
_________________
http://www.pbwhere.com
#8562 - DekuTree64 - Mon Jul 14, 2003 7:00 pm
Sounds like what you need is matrix math, particularly a rotation matrix. http://www.gamedev.net/reference/articles/article1691.asp is a good FAQ on it. Doesn't really explain things, but it does tell you what to do. The gamedev.net math section (http://www.gamedev.net/reference/list.asp?categoryid=28) is the best place I know to find matrix tutorials.
#8568 - DracoX5 - Mon Jul 14, 2003 9:56 pm
Okay, I think I understand it now!
In order to get a different perspective I would have to rotate all the polys in the image around based on what perspective I have, then divide then divide the x and y coords by the z to get the 2D x and y.
But one question remains: If the z coord is 0, what do I do? Would I just use 1 to divide by instead?
#8569 - DracoX5 - Mon Jul 14, 2003 11:16 pm
I took a look at the formulas at the websites DekuTree64 gave me and they work great, but when I tried using the divide-by-z method, the whole thing gets screwy.
I then realized (can't believe that I actually forgot it) that 0 is the same as 360 in any trig function. So everything works now!
Thanks everyone!