#### Archived

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

# 3d data structures

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

## Recommended Posts

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? :
  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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002284
×