// Added the following so that the changes necessary on different // platforms can be expressed in one place, rather than in 100+ demo // files. #ifdef MAC #include #include #include #else #include #include #include #endif // ================================================================ // Errors. This function is defined in src/tw.cc // The following function checks whether OpenGL has ignored an error, and // prints it. Call it regularly. void twErrorCheck(char* file, int line); // The following macro makes it easier to figure out what line noticed the // error. Remember that the error could have been caused by any OpenGL // call since the previous error check. #define twError() twErrorCheck(__FILE__,__LINE__) // ================================================================ // tw-utils.cc /* The following function tries to convert a simple filename such as "al.obj" into something that can be opened. It searches down the TWLOADPATH environment variable, which defaults to: .:$TWHOMEDIR/textures:$TWHOMEDIR/objects until it finds a file that exists. It's often a good idea to set TWLOADPATH to .:$TWHOMEDIR/textures:$TWHOMEDIR/objects:$TWHOMEDIR/f05:$TWHOMEDIR/f06 If verbose is true, the function reports each load directory it searches. */ char* twPathname(const char* filename, bool verbose); // ================================================================ // tw-messages.cc const int TW_ALL_MESSAGES = -1; const int TW_NO_MESSAGES = 0; const int TW_GEOMETRY = 0x1; const int TW_BOUNDING_BOX = 0x2; const int TW_WINDOW = 0x4; const int TW_CAMERA = 0x8; const int TW_COLOR = 0x10; const int TW_MATERIAL = 0x20; const int TW_LIGHTING = 0x40; const int TW_FONTS = 0x80; // The same syntax and function as printf, only it can be turned on/off // using twSetMessages. void twMessage(int messageKind, char* format, ...); // To turn messages on and off, call this function with some bitwise // combination of the constants above. void twSetMessages(int); // ================================================================ /* The following color names are defined in TW. You can switch to one of these colors using the twColorName function, giving one of the symbols below as the argument. The actual colors are defined in tw-color.cc */ enum twColorName {TW_BLACK, TW_WHITE, TW_YELLOW, TW_ORANGE, TW_MAGENTA, TW_RED, TW_SILVER, TW_GRAY, TW_OLIVE, TW_PURPLE, TW_MAROON, TW_CYAN, TW_TEAL, TW_GREEN, TW_BLUE, TW_DARK_BLUE, TW_LIGHT_BLUE, TW_PINK, TW_BROWN, TW_NUM_COLORS}; // reshaping stuff typedef enum {LETTERBOX, DISTORT, CLIP} frustumMode_t; const GLdouble DEFAULT_FOVY = 90.0; // ================================================================ // Vertices, Points and Vectors // defined in tw-geometry.cc // This datatype is just a three place array of floats, so we decided to // call them triples. They can be used for points, vectors, colors and // other things, depending on context. typedef GLfloat twTriple[3]; void twTripleInit(twTriple v, GLfloat x, GLfloat y, GLfloat z) ; // prints a vertex to stdout. The first argument can be used to label the // vertex. void twTriplePrint(char* name, twTriple v) ; // copies a vertex components to another vertex. V is copied to W void twTripleCopy(twTriple w, twTriple v) ; // returns the dot product of vector v and vector w. GLfloat twDot(twTriple v, twTriple w) ; // returns the cosine of the angle between vector v and vector w. // does not assume that they are normalized GLfloat twCosAngle(twTriple v, twTriple w) ; // returns the length of the vector v GLfloat twVectorLength(twTriple v) ; // creates vector v as a scalar multiple of w, multiplying each component // by k. It's safe to have v be the same object as w. GLfloat twVectorScale(twTriple v, twTriple w, GLfloat k) ; // modifies the vector to be of unit length. Returns with v unmodified if // v is the zero vector. void twVectorNormalize(twTriple v) ; // computes u=v x w, the cross product of vectors v and w, in that order void twCrossProduct(twTriple u, twTriple v, twTriple w) ; // computes v=A-B, the vector from point B to point A void twVector(twTriple v, twTriple A, twTriple B) ; // Computes B=A+v, the point that is the sum of point A and vector v void twPoint(twTriple B, twTriple A, twTriple v) ; // Computes Q=P+Vt, a point on the line defined by P and V void twPointOnLine(twTriple Q, twTriple P, twTriple V, GLfloat t); // computes the squared distance between points A and B GLfloat twPointDistance2(twTriple A, twTriple B) ; // computes the distance between points A and B GLfloat twPointDistance(twTriple A, twTriple B) ; // Find the plane normal, N, given three points on the plane, C, D, and // E. The vectors are v=D-C and w=E-C and the normal is computed as v x w. // If you give C,D,E in counterclockwise order, the normal will point out // from the front of the plane. GLfloat twPlaneNormal(twTriple N, twTriple C, twTriple D, twTriple E); // Returns true if a normal intersection, false otherwise. See the // documentation in doc.tex. P and V define the line; Q and N define the // plane. Computed values are IP (the intersection point) and t, the // parameter of the intersection point bool twLinePlaneIntersection( twTriple P, twTriple V, twTriple Q, twTriple N, GLfloat& t, twTriple IP); // Computes the parameters, s and t, of point I lying in the plane defined // by point P and vectors U and V. The caller has to interpret the // parameters to determine if I is contained in the triangle (0