Brice Rebsamen said:
> I would like to work with points in space:
> Point2D : (x,y)
> Point3D : (x,y,z)
> Pos2D : (x,y,yaw)
> Pos6D : (x,y,z,roll,pitch,yaw)
> what would be nice is that I can pass a Pos6D to a function that takes
> a Point3D as argument. What would be the best way of doing that?
> Possibilities I can see are:
> 1) Point2D is base class of Pos2D which is base class of Pos6D.
One problem with this is that a 6D position is not really a special kind of
2D point, is it? Nor do you add much value to an (x, y, z) co-ordinate by
rolling, pitching, or yawing it, because points are infinitesimally small
in all directions, so you wouldn't be able to tell what you'd done anyway.
Solid objects are made up of surfaces (and sometimes holes in those
surfaces), with the surfaces (and, by omission, the holes!) being defined
by faces, which are either described by edges (delimited by vertices) or
by parametric equations. It is only solid objects (or "solid" objects,
e.g. clouds!) that you can meaningfully yaw, pitch, or roll.
So I think your whole design needs a re-think while there's still time.
If you're after a 3D graphics engine, I would forget 2D completely, and use
an hierarchy that looks something like this:
typedef struct Point_ Point;
That's about it, really.
Leaving parametric equations aside for the moment, I would then continue
something like this:
typedef struct Edge_ Edge;
typedef struct Face_ Face;
....and so on, building primitive objects out of faces, and composites out
of primitives - and keeping track of which edge, if any, two faces have in
common. At no stage are these "is-a" relationships. They are all "has-a"
relationships, so there's no obvious reason for an hierarchical structure.
At the primitive object stage, record the current scale, orientation
(pitch, yaw, roll), position ***relative to the composite object of which
it is a part***.
At the composite object stage, record the current scale, orientation
(pitch, yaw, roll), position relative to the origin of the virtual world.
Then all you need to know is where your camera is pointing, and you're
laughing - Shrek IV in 10,000,000,000 astoundingly complicated stages.
Just to reiterate the point: you will have noticed the complete absence of
a class hierarchy in this design. That's for two reasons - 1) I really
don't think a class hierarchy is going to be a winner for you here (see
above), and 2) whilst it's *possible* to do OOP in C, it's really, really
icky and you almost certainly don't want to go there. Not if you want to
*finish* this project at some point, anyway.
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999