使用C++实现游戏编程中常用的向量类
在游戏编程中,经常会使用向量来描述物体在平面、空间中的位置,本文可以帮助读者完成一个功能齐全的向量类。
根据上一篇Vector2的实现,我们今天来实现一下Vector3,所有函数功能都类似,添加了叉乘操作。好了,废话不多说,直接上代码。
首先是构造函数:
Vector3() :x(0), y(0), z(0) {
}
Vector3(float _x, float _y, float _z) :x(_x), y(_y), z(_z) {
}
explicit Vector3(float value) :x(value), y(value), z(value) {
}
Vector3(const Vector3& other) :x(other.x), y(other.y), z(other.z) {
}
//other construct support
Vector3(const Vector2& other) :x(other.x), y(other.y), z(0) {
}
Vector3(const Vector2& other, float value) :x(other.x), y(other.