Archived

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

Beginner 3D Engine structure

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey. I''m a beginner to 3D (as i mention in EVERY 3d related post of mine ) Anyway, I finally got my fiurst flat shaded cube to rotate yesterday, it was very nice indeed. But I scrapped that cause it wasn''t structured at all, and now I''m gonna try to structure this out a bit to make things easier for me in the long run. Here''s what I have going for now, can someone please look over it and tell me if I''m going in the right direction before I go any further?? Thanks 3D Gurus. Instead of posting it in here, I have it up on my site This is just for a 3d Object Header file: http://pages.nyu.edu/~rba203/Object3D.h Source file: http://pages.nyu.edu/~rba203/Object3D.cpp This code isn''t long at all, so dont hesistate taking a quick look at it. And I wrote this up in about half an hour and it''s not even close to complete, I just want to know if the structuring is right so I dont realize I''m doing it wrong a few weeks later. ByteMe95::~ByteMe95()

Share this post


Link to post
Share on other sites
I looked at your header file and it looks pretty good.

But I would reduce your faces to 3 vertices only. I also would let Objects have parents and linked lists of children. Each Object''s matrix transforms to it''s parent''s object space and so on to the top level objects which transform to world space.

This way, we can define a front left tire relative to it''s parent object, the car body.

The rendering calls go like this:

Identity (); // specify identity
Lookat (); / specify eye space

for each top level object:
Object->transform (); // specify transform to world
render top level object ();
if (object has children)
render child objects (); // see below


render child object (Object)
{
Pushmatrix ();
Object->transform (); // specify transform to parent object
render object ();
if (object has children) {
render child objects (); // recurse
}
PopMatrix ();
} // end of function




Share this post


Link to post
Share on other sites
DAMN, that''s a lot more complicated than I had in mind.

I understand what you''re saying but I''m in no position to do that much at this point, i only started 3d a couple of weeks ago and only got my first flat colored 3d cube rotating yesterday :o)

Is there a way to add the functionality you mentioned at a later time or do you think it would be too hard at that point and I definately should implement it now?

All I really want is to set up this object class so that I could load in asc files and view them using my own code, I''m sure it''ll be a great feeling.

I still dont know anything (pretty much anytihng) about cameras and camera matrices. That whole parent child thing makes sense to me, but only on a very high level. If it came down to it I''m sure i wouldn''t understand it enough to actualkly program it so I dont think I could do that at this time.



ByteMe95::~ByteMe95()

Share this post


Link to post
Share on other sites
Hey, I just realized something else. You suggested I make all my polys 3 vertices, but then what would i do for clipping?

I was disussing this in another post of mine. We figured you could either have clipping by having your pollyfiller handle multiple vertices and then if your triangle is clipped, just set the polygon accordingly, giving it 4, 5, 6... vertices to match the clip OR triangulate the clipped polygon. So the only way i could have it so the polys are 3 vertices would be if i triangulize the polys, is that what you recommend??

And if so, could u point me to any good tuts on triangulizing polys?

Thanks



ByteMe95::~ByteMe95()

Share this post


Link to post
Share on other sites
Don''t worry about the child stuff at first. Just make top level objects that are static. You can''t have any articulated structures but just do the simple thing first.

Adding children later is just a matter of providing a link in your object structs to point to children.

As for clipping triangles, D3D or Opengl will clip them for you at render time. If you need to clip them before then, the worst that can happen is you get a convex quadrilateral which can be converted on the fly into two triangles. In other words, no need to build a structure to hold the 4 vertices.

Triangulating a convex polygon is simply a matter of picking any vertex and creating a ''fan'' out to all the other vertices.

Triangulating a concave polygon possibly with holes is not trivial and will require some research on your part.

Share this post


Link to post
Share on other sites