-
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.
-
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.
-
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 :rolleyes: is not designed to work with three varying values at once! :mad: Maybe I'll try in it 2D first and then expand it.
-
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)
-
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.
-
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.
-
hehe
-
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. :mad:
-
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.
-
But how would I get all the x, y and z coordinates of the surface of the plane?
-
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.
-
:confused: I am lost! Could you give an example?