PDA

View Full Version : 3d Struct tutorial



Zy
05-09-2001, 03:54 PM
Anyone know where I can find a tutorial on creating/using the struct command to create classes for 3d object information?

ffish
05-09-2001, 05:01 PM
A struct in C++ is the same as a class except that all members are public by default (whereas a class has private members by default). struct and class are almost synonyms in C++. A struct can have constructors, destructors, operators, private members, everything that a class has. If you don't write them yourself, the compiler does it for you anyway (same as a class).

If your question is how do I design a class for holding 3D objects, then I'd suggest using encapsulation: start with a vertex class with three floats and necessary operations. Next a triangle class with three vertices either in a container or three separate vertices and the necessary operations for triangles. Lastly you could have an object class that encapsulates a container of triangles, plus the necessary operations. If you want, you can add information to the triangle like normals, etc depending on what you want to do.

If you don't know anything about classes in C++ (or structs in C or C++) I'd suggest before thinking about OpenGL you spend some time with a good C/C++ book learning about them - you'll need it.

Hope that helps

[This message has been edited by ffish (edited 05-09-2001).]