// BasicTypes.h // // (C) COPYRIGHT John Henckel, mailto:henckel@iname.com Aug 1998 // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies. // // Visit my website! http://www.GeoCities.com/Paris/6502 #if !defined(BasicTypes_h_INCLUDED_) #define BasicTypes_h_INCLUDED_ #include #include #define EPSILON (1e-13) // double has 16 significant digits #define M_PI (3.14159265359) //--------------------------------------------------------------------------- inline double random(double range = 1.0) { return range * rand() / RAND_MAX; } class Vect; //--------------------------------------------------------------------------- // QUATERNION class Quat { public: Quat(): w(1.0), x(0.0), y(0.0), z(0.0) {} Quat(const Quat& p, const Quat& q); Quat(double theta, double ax, double ay, double az); GLdouble* AsMatrix() const; double Dot(const Quat& p) const { return w*p.w + x*p.x + y*p.y + z*p.z; } void Slerp(const Quat& p, double alpha, int spins = 0); int IsZero() const { return w>0 && fabs(x)0) operator *= (1/r); } void Negate() { x=-x; y=-y; z=-z; } Vect Cross(const Vect& v) const { return Vect(y*v.z-v.y*z,z*v.x-v.z*x,x*v.y-v.x*y); } Vect Cross2(const Vect& v) const { return Vect(v.y*z-v.z*y,v.z*x-v.x*z,v.x*y-v.y*x); } void Random() { x=random(); y=random(); z=random(); } int IsZero() const { return fabs(x)