afVec4.h
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:4k
源码类别:
其他游戏
开发平台:
Visual C++
- #ifndef AF_VEC4
- #define AF_VEC4
- /// 4D vector class
- class afVec4
- {
- public:
- float x, y, z, w;
- typedef float float4[4];
- afVec4() { x=y=z=w=0.0f; }
- afVec4( float nX, float nY, float nZ , float nW ) { x=nX; y=nY; z=nZ;w = nW; }
- afVec4(const float4& xyzw) { x = xyzw[0]; y = xyzw[1]; z = xyzw[2]; w = xyzw[3]; }
- afVec4& operator/=(float div) { x /= div; y /= div; z /= div; w /= div; return *this; }
- afVec4& operator*=(float scale) { x *= scale; y *= scale; z *= scale; w *= scale; return *this; }
- const float& getX() const { return x; }
- const float& getR() const { return x; }
- const float& getY() const { return y; }
- const float& getG() const { return y; }
- const float& getZ() const { return z; }
- const float& getB() const { return z; }
- const float& getW() const { return w; }
- const float& getA() const { return w; }
- float length();
- float sqrLength() { return x*x + y*y + z*z + w*w; }
- friend afVec4 operator*(const afVec4& vec, float scale);
- friend afVec4 operator*(float scale, const afVec4& vec);
- static float afVec4::distance(const afVec4& left, const afVec4& right);
- void makeHomogen();
- const float&
- operator[](unsigned index) const { return (&x)[index]; }
- float&
- operator[](unsigned index) { return (&x)[index]; }
- inline afVec4&
- operator=( const afVec4& );
- inline afVec4&
- operator+=( const afVec4& );
- inline afVec4&
- operator-=( const afVec4& );
- inline afVec4&
- operator*=( const afVec4& );
- friend inline bool
- operator==(const afVec4& left, const afVec4& right);
- friend inline const afVec4
- operator+(const afVec4& left, const afVec4& right);
- friend inline const afVec4
- operator-(const afVec4& left, const afVec4& right);
- friend inline const afVec4
- operator*(const afVec4& left, const afVec4& right);
- friend inline const afVec4
- operator/(const afVec4& left, const afVec4& right);
- friend inline const afVec4
- operator+(const afVec4& right);
- friend inline const afVec4
- operator-(const afVec4& right);
- };
- /// Color defined by quadruple of [0.0-1.0] float values
- typedef afVec4 afColor;
- typedef afVec4 *afVec4Ptr;
- inline
- afVec4 operator*(const afVec4& vec, float scale)
- {
- return afVec4(vec.x*scale, vec.y*scale, vec.z*scale, vec.w*scale);
- }
- inline
- afVec4 operator*(float scale, const afVec4& vec)
- {
- return afVec4(scale*vec.x, scale*vec.y, scale*vec.z, scale*vec.w);
- }
- inline afVec4&
- afVec4::operator+=( const afVec4& other)
- {
- x += other.x;
- y += other.y;
- z += other.z;
- w += other.w;
- return *this;
- }
- inline afVec4&
- afVec4::operator-=( const afVec4& other)
- {
- x -= other.x;
- y -= other.y;
- z -= other.z;
- w -= other.w;
- return *this;
- }
- inline afVec4&
- afVec4::operator*=( const afVec4& other)
- {
- x *= other.x;
- y *= other.y;
- z *= other.z;
- w *= other.w;
- return *this;
- }
- inline bool
- operator==(const afVec4& left, const afVec4& right)
- {
- return ( left.x == right.x
- && left.y == right.y
- && left.z == right.z
- && left.w == right.w );
- }
- inline const afVec4
- operator+(const afVec4& left, const afVec4& right)
- {
- return afVec4(left.x+right.x,left.y+right.y,left.z+right.z,left.w+right.w);
- }
- inline const afVec4
- operator-(const afVec4& left, const afVec4& right)
- {
- return afVec4(left.x-right.x,left.y-right.y,left.z-right.z,left.w-right.w);
- }
- inline const afVec4
- operator*(const afVec4& left, const afVec4& right)
- {
- return afVec4(left.x*right.x,left.y*right.y,left.z*right.z,left.w*right.w);
- }
- inline const afVec4
- operator/(const afVec4& left, const afVec4& right)
- {
- return afVec4(left.x/right.x,left.y/right.y,left.z/right.z,left.w/right.w);
- }
- inline const afVec4
- operator+(const afVec4& right)
- {
- return afVec4(right.x,right.y,right.z,right.w);
- }
- inline const afVec4
- operator-(const afVec4& right)
- {
- return afVec4(-right.x,-right.y,-right.z,-right.w);
- }
- inline afVec4&
- afVec4::operator=(const afVec4& vec)
- {
- x = vec.x;
- y = vec.y;
- z = vec.z;
- w = vec.w;
- return *this;
- }
- #endif