C3DObject
---------
SPoint *Vertices // pointer to the beginning of an array of SVertex elements
int number_of_vertices // number of vertices in the array
SPolygon *Polygons // pointer to the beginning of an array of SPolygon elements
int number_of_polygons // number of polygons in the array
SPoint
-------
x, y, z // position of vertex
SVector
-------
x, y, z // vector values
SPolygon
--------
int *VertexIndices // pointer to the beginning of an array of integers, describing the vertices making up this polygon, in anticlockwise order
int number_of_vertices // number of vertices referenced in the array above
SPoint Centre // the centre of this polygon; used in z-sorting
SVector Normal // normal of the polygon
int colour
All I'm trying to do atm is to draw some simple flat shaded shapes. I know how to project onto a plane, and view it with a camera, and to begin with I'll use gdi's Polygon. I just need a reliable scalable way to describe, transform and render 3d objects and their polygons etc.
I've probably done everything very stupidly. What is the best way to store things ?
r.
"The mere thought hadn't even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."
Edited by - Fresh on August 11, 2001 6:40:12 PM
3d data structures
Theres a lot of info about how to do various 3d processes, but I haven't found any about how to store information in memory. Given that I know next to not very much about 3d graphics, and am using only directdraw, how does the following look? :
If it works, use it. What I can see in your post probably isn''t too different from how most programs store data. However, I have one suggestion: Instaed of accompanying each pointer with an integer specifying how large the associated array is, it would probably make more sense to just terminate all arrays with NULL.
I''m assuming verteces aren''t added and subtracted from objects. If so, then the array-based approach you are using makes sense. However, linked lists make more sense if you''re going to be doing a lot of insertions and deletions.
And one more thing: Many programmers define a point not as a struct with x y and z members, but as an array. It''s up to you how you store your points; it''s more a matter of preference than anything else, but it''s another way of doing things, in case you want to try it out.
Now I know I''ve probably told you nothing you didn''t already know, but if you do pick something from my post, all the better.
Good luck in whatever you''re coding.
I''m assuming verteces aren''t added and subtracted from objects. If so, then the array-based approach you are using makes sense. However, linked lists make more sense if you''re going to be doing a lot of insertions and deletions.
And one more thing: Many programmers define a point not as a struct with x y and z members, but as an array. It''s up to you how you store your points; it''s more a matter of preference than anything else, but it''s another way of doing things, in case you want to try it out.
Now I know I''ve probably told you nothing you didn''t already know, but if you do pick something from my post, all the better.
Good luck in whatever you''re coding.
Thanks for the info. What advantages, disadvantages are there in using arrays or elements of a structure. Won''t arrays be (marginally) slower as a memory offset has to be calculated ?
As for what I''m coding - it''s actually quite a tacky little thing. Check out ''http://www.r.k.v.btinternet.co.uk/tnl.zip''. It''s an 0ld5k007 demo tunnel thingy, with a (very poorly rendered) spacecraft/paper aeroplane flying down it, all in software. The tunnel is looking sweet, but I want to have a scalable way of drawing simple flatshaded objects like the craft. The lower scrollbar controls speed, the upper field of view. The sound is pretty neat too methinks
Still wondering what next I could do to improve it. I was thinking maybe two such craft, albeit smaller and racing ahead of the camera. Perhaps a turny, twisty tunnel. I dunno yet
r.
As for what I''m coding - it''s actually quite a tacky little thing. Check out ''http://www.r.k.v.btinternet.co.uk/tnl.zip''. It''s an 0ld5k007 demo tunnel thingy, with a (very poorly rendered) spacecraft/paper aeroplane flying down it, all in software. The tunnel is looking sweet, but I want to have a scalable way of drawing simple flatshaded objects like the craft. The lower scrollbar controls speed, the upper field of view. The sound is pretty neat too methinks
Still wondering what next I could do to improve it. I was thinking maybe two such craft, albeit smaller and racing ahead of the camera. Perhaps a turny, twisty tunnel. I dunno yet
r.
I downloaded your demo. That''s pretty cool!! You''ve got some sorting problems with your spacecraft polygons though, but, if you''re using the painter''s algorithm (that is what you''re doing, right?) there''s probably no way around it, and it''s not too noticeable. The sound speed up-slow down thing is cool - simple, but very cool. All in all, a hell of a lot better than I could do!!
As for structs vs. arrays, the only advantage to arrays that I am aware of is that you can use FOR loops for some things. But, with only 3 iterations, you''d probably be better off just unrolling it anyway. You might be right about structs being faster; I honestly don''t know. Either way, it probably doesn''t matter too much.
As for structs vs. arrays, the only advantage to arrays that I am aware of is that you can use FOR loops for some things. But, with only 3 iterations, you''d probably be better off just unrolling it anyway. You might be right about structs being faster; I honestly don''t know. Either way, it probably doesn''t matter too much.
Sorry, to bring all this up again - but what''s the painter''s algorithm :?) I probably know what is, but not heard it called that. As for what I was doing in the tunnel demo, the order of the polygon drawing was hardcoded into the drawspacecraft function, which is pretty lame, but I wanted something quick without actually building algorithms to sort it out.
r.
r.
The painter''s algorithm is simply the drawing of all polygons in back-to-front order. Polygons are sorted by distance from the viewer. Distance from viewer can be the distance of the center of the polygon, the nearest vertex, any arbitrary vertex, etc. Depending on how you perform this sorting, you''ll get different results. Some will be what you want. Others won''t.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement