VECTOR.h
资源名称:g.rar [点击查看]
上传用户:laitongbao
上传日期:2021-02-20
资源大小:8176k
文件大小:2k
源码类别:
射击游戏
开发平台:
Visual C++
- // VECTOR.h: interface for the VECTOR class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_VECTOR_H__2F4A6770_82E4_417E_BA2C_E19DBFD2993F__INCLUDED_)
- #define AFX_VECTOR_H__2F4A6770_82E4_417E_BA2C_E19DBFD2993F__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- struct VECTOR
- {
- float x,y,z;
- };
- class VECTOR3:public VECTOR
- {
- public:
- VECTOR3()
- {
- x = 0;
- y = 0;
- z = 0;
- }
- VECTOR3(D3DXVECTOR3 source)
- {
- x = source.x;
- y = source.y;
- z = source.z;
- }
- VECTOR3(VECTOR3& source)
- {
- x = source.x;
- y = source.y;
- z = source.z;
- }
- VECTOR3(float x,float y,float z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- VECTOR3(int x,int y,int z)
- {
- this->x = (float)x;
- this->y = (float)y;
- this->z = (float)z;
- }
- VECTOR3 operator+(VECTOR operand)
- {
- return VECTOR3(x + operand.x,y + operand.y,z + operand.z);
- }
- VECTOR3 operator-(VECTOR operand)
- {
- return VECTOR3(x - operand.x,y - operand.y,z - operand.z);
- }
- void operator+=(VECTOR operand)
- {
- x += operand.x;
- y += operand.y;
- z += operand.z;
- }
- void operator-=(VECTOR operand)
- {
- x -= operand.x;
- y -= operand.y;
- z -= operand.z;
- }
- VECTOR3 operator*(float operand)
- {
- return VECTOR3(x * operand,y * operand,z * operand);
- }
- VECTOR3 operator/(float operand)
- {
- if(operand != 0)
- return VECTOR3(x / operand,y / operand,z / operand);
- else
- return VECTOR3();
- }
- void operator*=(float operand)
- {
- x *= operand;
- y *= operand;
- z *= operand;
- }
- void operator/=(float operand)
- {
- if(operand !=0)
- {
- x /= operand;
- y /= operand;
- z /= operand;
- }
- }
- bool operator>(VECTOR operand)
- {
- return x>operand.x&&y>operand.y&&z>operand.z;
- }
- bool operator>=(VECTOR operand)
- {
- return x>=operand.x&&y>=operand.y&&z>=operand.z;
- }
- bool operator<(VECTOR operand)
- {
- return x<operand.x&&y<operand.y&&z<operand.z;
- }
- bool operator<=(VECTOR operand)
- {
- return x<=operand.x&&y<=operand.y&&z<=operand.z;
- }
- bool operator==(VECTOR operand)
- {
- return x==operand.x&&y==operand.y&&z==operand.z;
- }
- float Length()
- {
- return sqrtf(x*x + y*y + z*z);
- }
- VECTOR3 Normalize()
- { float len;
- if((len = sqrtf(x*x+y*y+z*z)) != 0)
- return (*this)/len;
- else return VECTOR3();
- }
- D3DXVECTOR3 toD3dVector3()
- {
- return D3DXVECTOR3(x,y,z);
- }
- };
- #endif // !defined(AFX_VECTOR_H__2F4A6770_82E4_417E_BA2C_E19DBFD2993F__INCLUDED_)