CVector.h
上传用户:arsena_zhu
上传日期:2022-07-12
资源大小:399k
文件大小:5k
源码类别:

OpenGL

开发平台:

Visual C++

  1. /*
  2.    Class Name:
  3.       CVector3.
  4.    Created by:
  5.       Allen Sherrod (Programming Ace of www.UltimateGameProgramming.com).
  6.    Description:
  7.       This class represents a 3D point for a vertex's x, y, z.
  8. */
  9. #ifndef CVECTOR_H
  10. #define CVECTOR_H
  11. #include "main.h"
  12. /*******************************************************************************
  13. * VECTOR
  14. *******************************************************************************/
  15. class CVector
  16. {
  17.    public:
  18.       CVector();                                        // Constructor.
  19.       CVector(float X, float Y, float Z);               // Overloaded constructor.
  20.       CVector(const CVector &v);                       // Another overloaded constructor.
  21.       void operator=(CVector v);                        // Overloaded = sign.
  22.       void operator=(float f);                           // Overloaded = sign.
  23.       CVector operator-(CVector v);                    // Overloaded - sign.
  24.       CVector operator+(CVector v);                    // Overloaded + sign.
  25.       CVector operator*(CVector v);                    // Overloaded * sign.
  26.       CVector operator/(CVector v);                    // Overloaded / sign.
  27.       CVector operator+(float f);                       // Overloaded + sign.
  28.       CVector operator-(float f);                       // Overloaded - sign.
  29.       CVector operator*(float f);                       // Overloaded * sign.
  30.       CVector operator/(float f);                       // Overloaded / sign.
  31.       void operator +=(CVector v);                      // Overloaded += sign.
  32.       void operator -=(CVector v);                      // Overloaded -= sign.
  33.       void operator *=(CVector v);                      // Overloaded *= sign.
  34.       void operator /=(CVector v);                      // Overloaded /= sign.
  35.       void operator +=(float f);                         // Overloaded += sign.
  36.       void operator -=(float f);                         // Overloaded -= sign.
  37.       void operator *=(float f);                         // Overloaded *= sign.
  38.       void operator /=(float f);                         // Overloaded /= sign.
  39.       bool operator >(CVector v);                      // Overloaded > sign.
  40.       bool operator <(CVector v);                      // Overloaded < sign.
  41.       bool operator >(float f);                      // Overloaded > sign.
  42.       bool operator <(float f);                      // Overloaded < sign.
  43.       bool operator ==(CVector v);                      // Overloaded == sign.
  44.       bool operator !=(CVector v);                      // Overloaded != sign.
  45.       void CrossProduct(CVector v1, CVector v2);       // Stores cross product of v1, v2.
  46.       void CrossProduct3(CVector v1, CVector v2,
  47.                          CVector v3);                   // Stores cross product of v1, v2, v3.
  48.       float DotProduct3(CVector v1);                    // Dot 3 on v1 and this.
  49.       float GetLength();                                 // Return this objects length.
  50.       void Normal();                                     // Normalize this vector.
  51.       CVector Normalized();                                     // Normalize this vector.
  52.       void Normalize(CVector Triangle[]);               // Find the normal of a triangle.
  53.       /*
  54.       void CalculateTangentVector(CVector Point1,
  55.                                   CVector Point2,
  56.                                   CVector Point3,
  57.                                   CVector NormalOfA,
  58.                                   CTexCoord P1Tex,
  59.                                   CTexCoord P2Tex,
  60.                                   CTexCoord P3Tex);      // Cacluate a tagent vector & store here.
  61.       */
  62.       void ExtendVertexPos(CVector lightPos,            // Extend point based on light position
  63.                            float Extend);                // and currend point, saves here.
  64.       void ExtendVertexPos(CVector currentVertex,       // Takes current point and source and
  65.                            CVector lightPos,            // extend and saves here.
  66.                            float Extend);
  67.       CVector GetRotatedX(double angle);                // Rotate along x.
  68.       CVector GetRotatedY(double angle);                // Rotate alone y.
  69.       CVector GetRotatedZ(double angle);                // Rotate along z.
  70.       CVector GetRotatedAxis(double angle, CVector axis);// Rotate along an axis.
  71.       void CalculateBinormalVector(CVector tangent,
  72.                                    CVector normal);     // Calcluate a binormal.
  73.       void ClampTo01();                                  // Clamp this vector between 0 and 1.
  74.       void Set(CVector v)
  75.       { x = v.x; y = v.y; z = v.z; }
  76.       void Set(float X, float Y, float Z)
  77. { x=X; y=Y; z=Z; }
  78. void NoiseAngle()
  79. {
  80. x += ((float)(rand()%50)-25)/50;
  81. y += ((float)(rand()%50)-25)/50;
  82. z += ((float)(rand()%50)-25)/50;
  83. }
  84.       float x, y, z;                                  // vertex's x, y, and z info.
  85. };
  86. #endif
  87. // Copyright September 2003
  88. // All Rights Reserved!
  89. // Allen Sherrod
  90. // ProgrammingAce@UltimateGameProgramming.com
  91. // www.UltimateGameProgramming.com