就196分了,orz
解决方案 »
- CDHtmlDialog访问框架jsp网站
- 为什么不能接收ON_WM_CHAR?
- 关于MSDN帮助不能正常显示的问题
- [dxshow]请问有没有能实现 反色 的filter啊?
- 求ZIP算法的集成类。
- 资源文件打不开了,说是语言的问题!
- 如何实现审核功能!
- VC 的 MFC ClassWizard 中 Messages 里的 Create,PreCreateWindow,WM_CREATE,WM_INITDIALOG 有什么区别?
- odbc数据库的简单问题!
- 关于编译的问题,有兴趣者请进!
- 求JPEG压缩算法的资料(C++/C版本)
- 外部程序中有两个名称相同的EDIT框(在SPY++中),如何判别?
那帖子lfchen提议了下,也没见有人响应啊,估计只是个想法
{
public:
float x,y,z; //缺省构造函数
Vector3();
//拷贝构造函数
Vector3(const Vector3 &a):x(a.x),y(a.y),z(a.z){}
//带参的构造函数
Vector3(float nx,float ny,float nz):x(nx),y(ny),z(nz){} //重载赋值操作符
Vector3 &operator =(const Vector3 &a)
{
x = a.x;
y = a.y;
z = a.z;
return *this;
} //重载==操作符
bool operator ==(const Vector3 &a) const
{
return x==a.x && y==a.y && z==a.z;
} //重载!=操作符
bool operator !=(const Vector3 &a) const
{
return x!=a.x || y!=a.y || z!=a.z;
} //向量运算 //零向量
void zero()
{
x = y = z = 0.0f;
}
//向量求负
Vector3 operator - ()const
{
return Vector3(-x,-y-z);
}
//向量加减法
Vector3 operator + (const Vector3 &a) const
{
return Vector3(x+a.x,y+a.y,z+a.z);
}
Vector3 operator - (const Vector3 &a) const
{
return Vector3(x-a.x,y-a.y,z-a.z);
}
//向量与标量的乘除法
Vector3 operator *(float a) const
{
return Vector3(x*a,y*a,z*a);
}
Vector3 operator /(float a) const
{
ASSERT(a!=0.0f);
float reverse = 1.0f / a;
return Vector3(x*reverse,y*reverse,z*reverse);
}
//重载复合运算操作符
Vector3 *operator +=(const Vector3 &a)
{
x += a.x;
y += a.y;
z += a.z;
return *this;
}
Vector3 *operator +=(const Vector3 &a)
{
x += a.x;
y += a.y;
z += a.z;
return *this;
}
Vector3 *operator -=(const Vector3 &a)
{
x -= a.x;
y -= a.y;
z -= a.z;
return *this;
}
Vector3 *operator *=(float a)
{
x *= a;
y *= a;
z *= a;
return *this;
}
Vector3 *operator /=(float a)
{
ASSERT(a!=0.0f);
float reverse = 1.0f / a;
x *= reverse;
y *= reverse;
z *= reverse;
return *this;
}
//向量归一
void normalize()
{
float magSq = x*x+y*y+z*z;
if(magSq > 0.0f)
{
float reverse = 1.0f / a;
x *= reverse;
y *= reverse;
z *= reverse;
}
}
//向量点乘
float operator *(const Vector3 &a) const
{
return x*a.x + y*a.y + z*a.z;
}
};//就地展开运算//求模
inline float vectorMag(const Vector3 &a)
{
return sqrt(a.x*a.x,a.y*a.y+a.z*a.z);
}
//叉乘
inline Vector3 crossProduct(const Vector3 &a,const Vector3 &b)
{
return Vector3(a.y*b.z - a.z*b.y,
a.z*b.x - a.x*b.z,
a.x*b.y - a.y*b.x);
}
//标量左乘
inline Vector3 operator *(float k,const Vector3 &v)
{
return Vector3(k*v.x,k*v.y,k*v.z);
}
//两点距离
inline float distance(const Vector3 &a,const Vector3 &b)
{
float dx = a.x - b.x;
float dy = a.y - b.y;
float dz = a.z - b.z;
return sqrt(dx*dx,dy*dy,dz*dz);
}extern const Vector3 g_ZeroVector;