Advertisement

3d back to 2d conversion

Started by January 19, 2002 11:04 AM
4 comments, last by danielk 23 years, 1 month ago
Hello. I know this is not strictly OpenGL related, but it is realated to a project I''m doing. I''m working on a routine which automatically generates texture co-ordinates for world structures. I''m half way there - I can correctly calculate the ST coords given a triangle which faces toward the screen. I want this to work on triangles with differing angles (obviously). I think, if I can convert a given XYZ coordinate into XY (essentially converting the 3d representation into 2d), my routine should work fine. I can then reconvert the triangle into 3d... But how would I do this??? I have absolutely no idea! I thought of multiplying the xy coords by z. But have discovered this will not work, as I am not dealing with perspective calulations regarding plotting pixels.... The only information I can find regarding xyz - xy conversion, is dealing with perspective and plotting pixels. Nothing regarding converting a 3d object in 3d space into a 2d object in 3d space...Essentially rotating the triangles vertices untill each vertex lies on the same z plane, increasing or decreasing the xy positions to give the correct 2d representation. Someone please help.....If you can understand what I''m talking about... I''m not too clear in my descriptions usually ^_^ Transformers Rulez!!
Transformers Rulez!!
If you want to transform 3D coordinates to 2D coordinates, you can use the feedback buffer in OpenGL to get texture coordinates where the automatic texture coordinate generation plan is aligned to the viewpoint, if the view is orthographic.

That method allows to get the 2D coordinates of a 3D point (or 3D line or 3D polygon) while it is projected on a plane. Is it what you want ?

Edited by - vincoof on January 20, 2002 7:34:10 PM
Advertisement
Thankyou so much for your reply. It is very kind of you. I'm not sure if the information can help me much though.

I'll try and make my query clearer: What I really want to do is to transform an XYZ coordinate in 3D space into a XY coordinate in 3D space.

For my routine to work correctly, I need to rotate/translate eaxh vertex so that all the point lie on the same Z place, giving a 2d triangle, which has been scaled on both the X&Y axis to account for the change in Z.

If I were to display this triangle on screen, it should look like I am looking straight down the surface normal of the 3d representation: For eample, look at the following. It is supposed to resemble a quad which is being viewed from the front with perscpective

*****************************
[-1,0,-1] *-------* [1,0,-1]
*******-----------*************
[-1,0,1]*-----------* [1,0,1]
*****************************


I want to convert the above coordinates into this using translation/rotation/ a general math algorithm (preffered):


[-1,1,0] [1,1,0]
*---------*
*---------*
*---------*
*---------*
*---------*
[-1,0,0] [1,0,0]

I would like a routine to do this, but with triangles....
I hope I have made myself clearer. Thankyou for replying, and I hope someone can help me.

All the best, Dan

Transformers Rulez!!

Can't draw!!! Trying to get image right ^_^



Edited by - danielk on January 20, 2002 8:07:38 PM

Edited by - danielk on January 20, 2002 8:08:36 PM

Edited by - danielk on January 20, 2002 8:09:29 PM
Transformers Rulez!!
Here are the general equations for 3D-2D perspective transformation:

x2 = x1/z
y2 = y1/z

So Z would equal
z = x1/x2, right ?

But all you have is x2.
To get z, you need the starting x1.

Just running off of (x2,y2), you cannot calculate accuratly the Z value.

You need to have the orginal data, or you must assign arbitrarily the Z.

Here`s a page I found thats helpful:

http://easyweb.easynet.co.uk/~mrmeanie/algos.htm

There''s a article there about 3D alrorithims thats very good.

Hope this helps.

~V''lion



the bugle4D engine;
a new dimension in graphics...
[link]http://members.tripod.com/thefivelions/bugle4d/[/link]
~V'lionBugle4d
VILION:

Sorry about the crappy drawing ^_^ Thanks for replying.

I already have the original Z data. I''m trying to implement a generic texture mapping routine for any type of prefabricated raw vertex object for use in my 3d world editor. I have all the vertex data in the 3d models, but texture mapping uses 2d textures, not 3d. So to map any kind of model made from triangles, I need to convert them into XY WORLD coordinates, not screen coordinates... With me???? I know, I''m hard to understand ^_^

I''m not trying to do anything with perspective or any screen drawing with these coordinates, I just want a math routine which will essentially translate & rotate the vertices untill I get 2D coordinates which would essentially, IF plotted on screen, give an image of looking directly down the surface normal.

With these 2D coords, I can calculate texture coordinates regardless of Z orientation....
Transformers Rulez!!
If I understand well, you have 3D coordinates for your polygons, and for each polygon you would like to align it like it was facing the screen. Am I right ?

If so, the only thing you can compute is the normal of the face, using a cross product.

This topic is closed to new replies.

Advertisement