Skip to content

graphic

laishikai edited this page Sep 23, 2019 · 2 revisions

struct Vector2 {

float x, y;

public:

Vector2  &operator = (const Vector2 &other);
void  Set(float x, float y);
float Length();
bool  IsSimilar( const Vector2 &v, float fD = 0.00001f );
void  Normalize();
void  Zero();
void  One();
Vector2  &operator += ( const Vector2 &v);
Vector2  &operator -= ( const Vector2 &v);
Vector2  &operator *= ( float fScale );
Vector2  &operator /= ( float fScale );
friend Vector2 operator + (Vector2 left, Vector2 right);
friend Vector2 operator - (Vector2 left, Vector2 right);
Vector2 operator * (Vector2 left, float right);
Vector2 operator / (Vector2 left, float right);
float operator * (Vector2 left, Vector2 right);
friend float Length(Vector2 v1, Vector2 v2);
friend float GetDistSQ(Vector2 v1, Vector2 v2);
friend bool  Equals( const Vector2 &v1, const Vector2 &v2 );
friend float Dot(const Vector2 &v1, const Vector2 &v2 );
friend Vector2 Lerp(const Vector2 &v1, const Vector2 &v2, float fSlerp);

};

struct Vector3 {

float x, y, z;

public:

Vector3  &operator = (const Vector3 &other);
void Set(float x, float y, float z);
float Length();
bool IsSimilar( const Vector3 &v, float fD = 0.00001f );
void Normalize();
void Zero();
void One();
Vector3  &operator += ( const Vector3 &v);
Vector3  &operator -= ( const Vector3 &v);
Vector3  &operator *= ( float fScale );
Vector3  &operator /= ( float fScale );
friend Vector3 operator + (Vector3 left, Vector3 right);
friend Vector3 operator - (Vector3 left, Vector3 right);
friend Vector3 operator * (Vector3 left, float fScale);
friend Vector3 operator / (Vector3 left, float fScale);
friend float operator * (Vector3 left, Vector3 right);  // 点乘

friend float Length(Vector3 v1, Vector3 v2);
friend float GetDistSQ(Vector3 v1, Vector3 v2);
friend bool  Equals( const Vector3 &v1, const Vector3 &v );
friend float Dot(const Vector3 &v1, const Vector3 &v2 );
friend Vector3 Lerp(const Vector3 &v1, const Vector3 &v2, float fSlerp);
friend Vector3 Cross(const Vector3 &v1, const Vector3 &v2);

void  RotationY(float fYaw);
void  RotationX(float fPitch);
void  RotationZ(float fRoll);
void  TransformCoord( const Vector3 &vIn, const Matrix& mat );
void  TransformNormal( const Vector3 &vIn, const Matrix& mat );
Vector2  ToScreen( const Matrix &matWorldViewProj, float fScreenW, float fScreenH ) const

};

struct Vector4 {

float  x, y, z, w;

Vector4  &operator = (const Vector4 &other);
void Set(float x, float y, float z, float w);
float Length() const;
void Normalize();

friend  Vector4 operator + ( const Vector4 &v0, const Vector4 &v1 );
friend  Vector4 operator - ( const Vector4 &v0, const Vector4 &v1 );
friend  float operator * ( const Vector4 &v0, const Vector3 &v1 );
friend  float operator * ( const Vector3 &v0, const Vector4 &v1 );
friend  float operator * ( const Vector4 &v0, const Vector4 &v1 );
friend Vector4  operator *( const Vector4 &v, float fScale);

void  operator *=(float fScale)
void  operator *= ( const Matrix& mat )
void  operator += ( const Vector4 &v )

};

struct Panel {

float  a, b, c, d;

Panel  &operator = (const Panel &other);
void Set(float a, float b, float c, float d);
void Normalize()
Vector3  GetNormal() const;
void  InitFromPoints( const Vector3 &v1, const Vector3 &v2, const Vector3 &v3 )
void  InitFromPointNormal( const Vector3 &vPoint, const Vector3 &vNormal )
bool  IsFront( const Vector3 &vPos ) const
bool  IntersectLine(Vector3  *pPos, const Vector3 *pBegin, const Vector3 *pRayDir) const

};

struct Matrix {

union
{
    struct
    {
        float    _11,_12, _13, _14;
        float    _21,_22, _23, _24;
        float    _31,_32, _33, _34;
        float    _41,_42, _43, _44;
    };
    float m[4][4];
};

Matrix  &operator = (const Matrix &other);
float[] operator[](int nIndex){return _m[nIndex];}
//float operator[][](int nRow, nCol){return _m[nRow][nCol];}
void  Identity();
void  OrthoRH(float w, float h, float zn, float zf);
void  OrthoLH(float w, float h, float zn, float zf);
void  PerspectiveR(float fovy, float Aspect, float zn, float zf);
void  PerspectiveL(float fovy, float Aspect, float zn, float zf);
void  Translation( float fx, float fy, float fz );
void  RotationYawPitchRoll( float fYaw, float fPitch, float fRoll );

void   RotationYawPicthRollSacle( float fYaw, float fPitch, float fRoll, float fScaleX, float fScaleY, float fScaleZ );
void   MoveRotationYawPicthRoll( float fMoveX, float fMoveY, float fMoveZ, float fYaw, float fPitch, float fRoll );
void   RotationYawPicthRollMove( float fYaw, float fPitch, float fRoll, float fMoveX, float fMoveY, float fMoveZ );
void   Scaling( float fScaleX, float fScaleY, float fScaleZ );
void   RotationRoll( float fRoll ); void   RotationZ( float fRoll );
void   RotationPitch( float fPitch );  void   RotationY( float fPitch );
void   RotationYaw( float fYaw );  void   RotationX( float fYaw );
bool   Inverse( const Matrix &other );
bool   Inverse();
void   Transpose( const Matrix &other ); // 求转置距阵
void   Transpose();

Matrix   &operator += ( const Matrix &mat );
Matrix   &operator -= ( const Matrix &mat );
Matrix   &operator *= ( const Matrix &mat );
Matrix   &operator *= ( float f )
Matrix   &operator /= ( float f );
Matrix  &Mul( const Matrix &mat1, const Matrix &mat2 ); // a = b * c

void LookAtRH( const Vector3 *pEye, const Vector3 *pAt, const Vector3 *pUp )
void LookAtLH( const Vector3 *pEye, const Vector3 *pAt, const Vector3 *pUp );

};

struct Bounds {

Vector3  center;  // 中心点
Vector3  extents; // 大小
void Set(Vector3 vMin, Vector3 vMax);
float Width()
float Height();
float Length();
Vector3  GetCenter();
void   AddVector(const Vector3 &p);
void   AddBoudBox( const Bounds &sBox );

void   SetLineBox( const Vector3 &vBegin, const Vector3 &vEnd, float fLineSize )
bool   IsContain( const Bounds &sBox);
bool   IsContain( const Bounds &sBox, float fStep );
bool   IsContain( const Vector3 &sPoint );
bool   IsContain( const Vector3 &sPoint, float fStep );
bool   GetIntersectPoint( Vector3 &vPickPoint, const Vector3 &vRayOrg, const Vector3 &vRayDir );
bool   IsIntersectRay( const Vector3 &vRayOrg, const Vector3 &vRayDir, float fLineMax ) const;
void   Transform(const Matrix* pMat);

};

struct Ray {

Vector3 org; // 射线的起点
Vector3 dir; // 射线的方向
bool  GetIntersectPoint( Vector3 &vPickPt, const Vector3& v0, const Vector3& v1, const Vector3& v2 ) const;
bool  IntersectTriangle( const Vector3& v0, const Vector3& v1, const Vector3& v2, float* t, float* u, float* v ) const;

};

struct Color32 {

BYTE  r, g, b, a;
void  Set(BYTE _r, BYTE _g, BYTE _b, BYTE _a);
void  operator = (uint c); 
uint  ToInt32();

};

struct Color {

float  r, g, b, a;
void  Set(float _r, float _g, float _b, float _a);
void  operator = (uint c); 
uint  ToInt32();

};

struct Quaternion {

float  x, y, z, w;
void Identity();
void Set(float _x, float _y, float _z, float _w);
void SetAxisAngle(const Vector3 &axis, float angle);
void SetEulerAngles(const Vector3 &Euler);
void SetEulerAngles(float fYaw, float fPitch, float fRoll);
void SetFromToRotation( const Vector3& from, const Vector3& to );
void Lerp(Quaternion q1, Quaternion p2, float fLerp);
void Slerp(Quaternion q1, Quaternion p2, float fLerp);
void ToAngleAxis(Vector3& axis, float &angle);
Vector3 ToEuler();
friend Vector3 operator *(Quaternion q, Vector3 v);
friend Quaternion operator *(Quaternion q1, Quaternion p2);

};

struct Bezier2D {

Vector2   begin, end, p1, p2;
void Set(Vector2 begin, Vector2 end, Vector2 p1, Vector2 p2);
Vector2 Lerp(float fLerp);

};

struct Bezier3D {

Vector3   begin, end, p1, p2;
void Set(Vector3 begin, Vector3 end, Vector3 p1, Vector3 p2);
Vector3 Lerp(float fLerp);

};

struct IntRect {

int  left, top, right, bottom;
void Set(int _left, int _top, int _right, int _bottom);
void AddPoint(int x, int y);
int  width{get ;}
int  height(get;}
bool IsContain(int x, int y) const;
bool IsContain(const IntRect &r) const;
bool IsIntersect(const IntRect &r) const;

};

struct Rect {

float  left, top, right, bottom;
void Set(float _left, float _top, float _right, float _bottom);
void AddPoint(float x, float y);
float  width{get ;}
float  height{get;}
bool IsContain(float x, float y) const;
bool IsContain(const Rect &r) const;
bool IsIntersect(const Rect &r) const;

};

Clone this wiki locally