Advertisement

3dimentional wireframe 3d - 2d conversion

Started by March 01, 2003 01:51 AM
3 comments, last by Reiken 22 years ago
Hey, I am working on a 3dimentional wireframe engine, and I was looking to get some code for the conversion of a 3dimentional environment into a 2dimentional screen (linear). here''s what I imagine the function would look like; void disp2dcords (x1,y1,z1,x2,y2,z2) { 2dX1 = (this is where the 3d-2d X axis point 1 conversion goes); 2dY1 = (this is where the 3d-2d Y axis point 1 conversion goes); 2dX2 = (this is where the 3d-2d X axis point 2 conversion goes); 2dY2 = (this is where the 3d-2d Y axis point 2 conversion goes); cout >> "2D cords.; (" >> 2dX1 >>", " >> 2dY1 >> ")-(" >> 2dX2 >> ", " >> 2dY2 >> ")"; } I''d appreciate any help, thanks. >> Reiken
http://freespace.virgin.net/hugo.elias/
this page has alot of good stuff about lines and 3d
and alot more
Advertisement
screen.x = world.x / world.z;
screen.y = world.y / world.z;

You might want to multiply the world.x and world.y values by a number proportional to the screen size or else you get an extreme fish-eye effect,... you''d have to experiment to get the right effect..

ex.
screen.x = (world.x*320) / world.z;
screen.y = (world.y*320) / world.z;

In your function:-

  void disp2dcords (x1,y1,z1,x2,y2,z2){2dX1 = x1 / z1;2dY1 = y1 / z1;2dX2 = x2 / z2;2dY2 = y2 / z2;cout >> "2D cords.; (" >> 2dX1 >>", " >> 2dY1 >> ")-(" >> 2dX2 >> ", " >> 2dY2 >> ")";}  


-Crawl
--------<a href="http://www.icarusindie.com/rpc>Reverse Pop Culture
x2d = screenwidth/2 + zoom*x3d/z3d
y2d = screenheight/2 - zoom*y3d/z3d

a good value for zoom is screenwidth/2 for a 90degree FOV
ya what they said. you want to have perspective, not parallel projection. the farther away the object, the closer to 0 it would be if you''re dividing by Z. make sense?

then just add by half your screen height and width to put the image in the center of the screen. otherwise it''ll be in the upper left corner. you''ll just wanna play around with multiplying the Z and screen coords by set values to get the proper perspective and size and all. because one engine might represent ~1 meter as 0.1 but another might be 0.0

project the points and then do the drawing of lines and whatnot.

This topic is closed to new replies.

Advertisement