Archived

This topic is now archived and is closed to further replies.

Drawing a 3d line!

This topic is 5484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So I decided to write a software renderer after much advice from this forum(and so far I''m learning a lot) but I''ve run in to a brick wall already. I can draw a 2d line(after a lot of sweat work) but I can''t figure out how to draw a 3d line. This is my function so far.. void DrawLine(x0,x1,y0,y1) { // Draw line code here } So I figured to make it be a 3d line all i would have to do is transfer the 3d endpoints to 2d endpoints and then call the 2d draw line function void Draw3DLine(x0,x1,z0, y0,y1,z1) { x0 /= z0; y0 /= z0; x1 /= z1; y1 /= z1; DrawLine(x0,y0,x1,y1); } This gives me some wierd effects, any help is appreciated!

Share on other sites
You really shouldn''t project like that.
Also, usually we don''t draw "lines" in 3d.
Having defined two points in 3d space is one thing & drawing a line between thoose are another.

If you translate & then project you could use you standard bresenham (or what have you) 2d line algo.

Share on other sites
Drawing a line in 3d help much in a software rasterizer for the fact that it helps to debug other functions , anyway , pay attention to clipping plane, z0,z1 might go to 0 thus sending to ''infinity'' your projection, ekas78 is right, xform ( transform using viewing matrix ) your coordinates , and draw a 2d line using them in your frame buffer,
Sorry for my english.
bye.

Share on other sites
if you want to make a software rasteriser, you really need a book like Computer Graphics: Principles and Practice or 3D Computer Graphics (3rd Ed.)
, or even Michael Abrash's Graphics Programming Black Book (Special Edition) anyway, a good book on the fundamentals of computer graphics.

Anything on the intricacies of matrices, vectors, transformation, clipping, lighting, shading, rasterising, texture mapping, filtering, ....

[edited by - oliii on November 15, 2003 6:10:53 AM]

Share on other sites
quote:
Original post by Ekas78
You really shouldn''t project like that.
Also, usually we don''t draw "lines" in 3d.
Having defined two points in 3d space is one thing & drawing a line between thoose are another.

If you translate & then project you could use you standard bresenham (or what have you) 2d line algo.

But I''m skipping all the transformations by just putting the model already in view space. I''m not moving the camera and I''m only having one object so if i define the model coordinates to be the actual view coordinates I don''t have to go through the transformations. So say my model coordinates = (4,4,1),(5,5,1),(1,1,1) that would be the model coordinates transformed to view coordinates already.

So then all that is left to do is do the projection transformation which is x/z and y/z correct? When I do that though I get wierd effects.

Share on other sites
Make sure you project your object to viewspace the correct way, with a projection matrix.

Once there, you may want to clip your line, if one endpoint of the line is behind the camera it'll project the wrong way. Clip away everything behind the plane z=0.0001 (not 0 to avoid division by 0), and then clip it in 2D so that you won't be drawing ouside the screen.

Oh, and if you really can't get it to work, try to practice with projecting dots first. A starfield.

EDIT = typos

[edited by - Boops on November 15, 2003 2:27:26 PM]

Share on other sites
I''m not writing a fully function 3d enviroment so I don''t need all the transformations.

I''m assuming
- No translations
- No rotation
- No scaling
- Fixed point of view

That means I can skip those transformations and the only transformation left is the projection transformation onto the clip plane.

As far as I know to transform 3d coordinates to 2d you just divide x/z and y/z. Though I must be missing something here because the results look funny.

Share on other sites
I still can''t figure this out

Share on other sites
That''s a pretty odd order of your parameters there... you sure it''s not that that''s playing a prank on you?

Share on other sites
Also, can you explain what your "wierd" effects are? (I presume you mean "weird?"

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• Forum Statistics

• Total Topics
633430
• Total Posts
3011831
• Who's Online (See full list)

There are no registered users currently online

×