Results 1 to 12 of 12

Thread: 3D rendering?

  1. #1

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464

    3D rendering?

    I have written some code to draw 3D shapes, you can rotate them and they have perspective etc. Currently the moment the points are only joined by lines. How can I color in the sides of, say, a cube. At the moment I am using the Polygon API but obviously this doesn't work. Can any one help?

    TIA
    -TiPeRa

    Oh yeah, don't suggest using DirectX.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  2. #2
    Zaei
    Guest
    Not only will you have to take a look into the FloodFill() API call, but you will have to enjoy the world of depth sorting your polygons. If any of your polygons cover the edges of another, the hidden edge section must be removed, or only half of your poly will be filled. To make matters worse, you wont be able to do lighting, because it would take about a second (run time) to interpolate vertex colors using SetPixelV(). I am sure you are in this for the learning, and congratulations, but I think that you will find that you really have your work cut out for you.

    For more information, check out the book Visual Basic Graphics Programming, if you already havent, as this book covers this topic quite nicely.

    Z.

  3. #3

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    I am currently using the Polygon API to color in the planes. But the same plane always appears at the front, even though at times it should be at the back.
    I thought of maybe having a 3D array and everytime I add a plane, calculate the 'pixels' within the 3D array which should be set. Drawing the 3D array to screen would then be easy. The hard part is adding the planes to the array; my head is not designed to work with three varying values at once! Maybe I'll try in it 2D first and then expand it.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Just thinkin'
    How about using 6 Memory DC's at same time and have the zorder take care of the hiding for you using points globally and assigning needed one's to memdc's as warrented? Someday I'd like to try it when I'm really due for a huge headache but it seems to me this would work pretty simple (This is where someone has to copy, quote and bash me back into my senses so I don't try this)

  5. #5

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    I see where you going...1 dc per side right?
    The cube was just an example, there could be something with a few hundred sides so having a seperate dc for both wouldn't really work.

    Oh, does anyone happen to know the formula for a straight line in 3D. In 2D it is y=mx+c right.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  6. #6
    Zaei
    Guest
    I believe that a ray in 3d space is:
    Code:
    <Px, Py, Pz> = <Sx, Sy, Sz> + t<Dx, Dy, Dz>
    where t is distance along the line
    As I said before, you have to depth sort your polygons. Render the ones in the back first, the ones in front last.

    Z.

  7. #7
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    hehe

    Have fun
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  8. #8

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    Yeah, I was thinking to go back from the front of the array and when a colored 'pixel' was found I would draw it and start the next row along. I still can't manage to set the array elements to represent the planes though.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  9. #9
    Zaei
    Guest
    Dont use a 3d array. When you project the point into 2d space, you have to preserve the z coordinate (depth). This should be a value between 0.0 and 1.0. You then find the points at the back, and draw those first, all the way up to the front.

    Z.

  10. #10

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    But how would I get all the x, y and z coordinates of the surface of the plane?
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  11. #11
    Zaei
    Guest
    You cant really render a plane, since a plane is infinite. You can render a polygon by projecting each vertex from 3d into 2d space. If you do this correctly, you then have to find a z value from 0.0 to 1.0, using a near clip plane and a far clip plane. Simply find the distance from the point to the camera, and divide that value by the distance from the near clip plane to the far clip plane. If the value is less then 0, dont use the point (youll have to do manual clipping), and the same for if it is greater then 1.0.
    Now that you know what is behind what, you then draw the polygons from the ones in the back to the ones in the front, using the polygon api.

    Z.

  12. #12

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    I am lost! Could you give an example?
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width