home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------
- Maths Library
- -------------
-
- Header for C++ interface to basic geometry related maths
- functions
-
- (C) Silicon Dream Ltd 1994
-
- ------------------------------------------------------------------
-
- Changes: Date:
- * Created file 19/08/94
- */
-
- #ifndef CPPMATHS
- #define CPPMATHS
-
- extern "C"
- {
- #include "maths.h"
- }
-
- /*
- Four new classes are defined by this header:
-
- Vec A three element cartesian vector
- Polar A three element polar vector
- LVec A four element cartesian vector
- Mat A 4x4 matrix
-
- The following operations are permitted on these types:
-
- Vector operations: Description:
- ------------------ ------------
- Vec vec(x, y, z) Initialise a vector up to three values
- Vec vecA(vecB) Initialise a vector with another vector
- Vec vec(lvec) Initialise a vector with a long vector (loses last component)
- ((Vec) lvec) Convert a long vector to a vector (loses last component)
- Vec vec(pol) Initialise a vector with a polar vector (conversion performed)
- ((Vec) pol) Convert a polar vector to a vector (conversion performed)
- vecA+vecB Add two vectors
- vecA-vecB Subtract a vector from another
- vec*f Multiply a vector by a scalar
- vec*mat Multiply a vector by a matrix
- vec/f Divide a vector by a scalar
- vecA+=vecB Add two vectors (overwrite original)
- vecA-=vecB Subtract a vector from another (overwrite original)
- vec*=f Multiply a vector by a scalar (overwrite original)
- vec*=mat Multiply a vector by a matrix (overwrite original)
- vec/=f Divide a vector by a scalar (overwrite original)
- -vec Returns the vector inverted
- vecA==vecB Are two vectors equal?
- vecA!=vecB Are two vectors not equal?
- vec.Set(x, y, z) Set a vector's components
- vec.X() Get x component
- vec.Y() Get y component
- vec.Z() Get z component
- vec.Len() Get length of vector
- vecA.Dot(vecB) Get dot product of two vectors
- vecA.Cross(vecB) Get cross product of two vectors
- vec.AddrVec() Gets address of Vector member (WARNING: Use only to interface to non C++ code)
-
- Long vector operations: Description:
- ----------------------- ------------
- LVec lvec(x, y, z, w) Initialise a long vector with up to four values
- LVec lvecA(lvecB) Initialise a long vector with another long vector
- LVec lvec(vec) Initialise a long vector with a vector (last component becomes 1.0)
- ((LVec) vec) Convert a long vector to a vector (last component becomes 1.0)
- lvec*mat Multiply a long vector with a matrix
- lvec*=mat Multiply a long vector with a matrix (overwrite original)
- lvecA==lvecB Are two long vectors equal?
- lvecA!=lvecB Are two long vectors not equal?
- lvec.Set(x, y, z, w) Set a long vector's components
- lvec.X() Get x component
- lvec.Y() Get y component
- lvec.Z() Get z component
- lvec.W() Get w component (homogeneous coordinate)
- lvec.AddrLVec() Gets address of LongVec member (WARNING: Use only to interface to non C++ code)
-
- Polar operations: Description:
- ----------------- ------------
- Polar pol(t, p, r) Initialise a polar with up to three values
- Polar polA(polB) Initialise a polar with another polar
- Polar pol(vec) Initialise a polar with a vector (conversion performed)
- ((Polar) vec) Convert a vector to a polar (conversion performed)
- polA==polB Are two polars equal?
- polA!=polB Are two polars not equal?
- pol.Set(t, p, r) Set a polar's components
- pol.Theta() Get theta component
- pol.Phi() Get phi component
- pol.Rho() Get rho component
- pol.AddrVec() Gets address of Vector member (WARNING: Use only to interface to non C++ code)
-
- Matrix operations: Description:
- ------------------ ------------
- Mat mat Initialise a matrix with the identity matrix
- Mat matA(matB) Initialise a matrix with another matrix
- Mat mat(XROT, a) Initialise a matrix with a rotation or scale value (or leave it unset)
- Mat mat(TRANSL, vec) Initialise a matrix with a translation value (or leave it unset)
- Mat mat(vecPos, vecDir, vecUp) Initialise a matrix by defining a new coordinate system
- matA*matB Multiply two matricies
- matA*=matB Multiply two matricies (overwrite original)
- matA==matB Are two matricies equal?
- matA!=matB Are two matricies not equal?
- -mat Compute inverse of matrix (ie. when multiplied by this gives identity)
- mat.Set(f1,..f16) Sets elements of a matrix
- mat.MoveParent(vec) Moves coor sys defined by matrix relative to its parent
- mat.MoveChild(vec) Moves coor sys defined by matrix relative to itself
- mat.ScaleParent(x, y, z) Scale coor sys defined by matrix relative to its parent
- mat.ScaleChild(x, y, z) Scale coor sys defined by matrix relative to its own origin
- mat.XRotParent(a) Rotates coor sys defined by matrix about parents x axis
- mat.XRotChild(a) Rotates coor sys defined by matrix about its own x axis
- mat.YRotParent(a) Rotates coor sys defined by matrix about parents y axis
- mat.YRotChild(a) Rotates coor sys defined by matrix about its own y axis
- mat.ZRotParent(a) Rotates coor sys defined by matrix about parents z axis
- mat.ZRotChild(a) Rotates coor sys defined by matrix about its own z axis
- mat.ReverseX() Reverses direction of x axis of coor sys defined by matrix
- mat.ReverseY() Reverses direction of y axis of coor sys defined by matrix
- mat.ReverseZ() Reverses direction of z axis of coor sys defined by matrix
- mat.AddrMat() Gets address of Matrix member (WARNING: Use only to interface to non C++ code)
- */
-
- class Vec // vec
- {
- friend class LVec;
- friend class Polar;
- friend class Mat;
- public:
- _cppdyn Vec (float fX=0.0, float fY=0.0, float fZ=0.0);
- _cppdyn Vec (Vec &vecOther);
- _cppdyn Vec (LVec &lvec);
- _cppdyn Vec (Polar &pol);
- Vec _cppdyn operator+ (Vec &vecOther);
- Vec _cppdyn operator- (Vec &vecOther);
- Vec _cppdyn operator* (float f);
- Vec _cppdyn operator* (Mat &mat);
- Vec _cppdyn operator/ (float f);
- Vec &_cppdyn operator+= (Vec &vecOther);
- Vec &_cppdyn operator-= (Vec &vecOther);
- Vec &_cppdyn operator*= (float f);
- Vec &_cppdyn operator*= (Mat &mat);
- Vec &_cppdyn operator/= (float f);
- Vec _cppdyn operator- ();
- bool _cppdyn operator== (Vec &vecOther);
- bool _cppdyn operator!= (Vec &vecOther);
- Vec &_cppdyn Set (float fX, float fY, float fZ);
- float _cppdyn X ();
- float _cppdyn Y ();
- float _cppdyn Z ();
- float _cppdyn Len ();
- float _cppdyn Dot (Vec &vecOther);
- Vec _cppdyn Cross (Vec &vecOther);
- Vector *_cppdyn AddrVec ();
- private:
- Vector vec;
- };
-
- class LVec // lvec
- {
- friend class Vec;
- public:
- _cppdyn LVec (float fX=0.0, float fY=0.0, float fZ=0.0, float fW=1.0);
- _cppdyn LVec (LVec &lvecOther);
- _cppdyn LVec (Vec &vec);
- LVec _cppdyn operator* (Mat &mat);
- LVec &_cppdyn operator*= (Mat &mat);
- bool _cppdyn operator== (LVec &lvecOther);
- bool _cppdyn operator!= (LVec &lvecOther);
- LVec &_cppdyn Set (float fX, float fY, float fZ, float fW);
- float _cppdyn X ();
- float _cppdyn Y ();
- float _cppdyn Z ();
- float _cppdyn W ();
- LongVec *_cppdyn AddrLVec ();
- private:
- LongVec lvec;
- };
-
- class Polar // pol
- {
- friend class Vec;
- public:
- _cppdyn Polar (float fX=0.0, float fY=0.0, float fZ=0.0);
- _cppdyn Polar (Polar &polOther);
- _cppdyn Polar (Vec &vecOther);
- bool _cppdyn operator== (Polar &polOther);
- bool _cppdyn operator!= (Polar &polOther);
- Polar &_cppdyn Set (float fTheta, float fPhi, float fRho);
- float _cppdyn Theta ();
- float _cppdyn Phi ();
- float _cppdyn Rho ();
- Vector *_cppdyn AddrVec ();
- private:
- Vector vec;
- };
-
- enum MatType {XROT, YROT, ZROT, SCALE, TRANSL, UNSET};
-
- class Mat // mat
- {
- friend class Vec;
- friend class LVec;
- public:
- _cppdyn Mat ();
- _cppdyn Mat (Mat &matOther);
- _cppdyn Mat (MatType mt, float f1=1.0, float f2=1.0, float f3=1.0);
- _cppdyn Mat (MatType mt, Vec vec);
- _cppdyn Mat (Vec &vecOrg, Vec &vecAxZ, Vec &vecAxY);
- Mat _cppdyn operator* (Mat &matOther);
- Mat &_cppdyn operator*= (Mat &matOther);
- bool _cppdyn operator== (Mat &matOther);
- bool _cppdyn operator!= (Mat &matOther);
- Mat _cppdyn operator- ();
- Mat &_cppdyn Set (float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15, float f16);
- Mat &_cppdyn MoveParent (Vec &vec);
- Mat &_cppdyn MoveChild (Vec &vec);
- Mat &_cppdyn ScaleParent (float fX, float fY, float fZ);
- Mat &_cppdyn ScaleChild (float fX, float fY, float fZ);
- Mat &_cppdyn XRotParent (float fAng);
- Mat &_cppdyn XRotChild (float fAng);
- Mat &_cppdyn YRotParent (float fAng);
- Mat &_cppdyn YRotChild (float fAng);
- Mat &_cppdyn ZRotParent (float fAng);
- Mat &_cppdyn ZRotChild (float fAng);
- Mat &_cppdyn ReverseX ();
- Mat &_cppdyn ReverseY ();
- Mat &_cppdyn ReverseZ ();
- Matrix *_cppdyn AddrMat ();
- private:
- Matrix mat;
- };
-
- #endif // Do not include this file twice
-