13 this->x =
static_cast<float>(
x);
14 this->y =
static_cast<float>(
y);
19 this->x =
static_cast<float>(
x);
20 this->y =
static_cast<float>(
y);
43 return Vec2(
x * scalar,
y * scalar);
47 return Vec2(
x / scalar,
y / scalar);
55 return (
x == other.
x) && (
y == other.
y);
59 return std::sqrt(
x *
x +
y *
y);
63 return std::sqrt((
x - other.
x) * (
x - other.
x) + (
y - other.
y) * (
y - other.
y));
66 template<
class Archive>
67 void serialize(Archive & ar,
const unsigned int version)
77 operator physx::PxExtendedVec3()
const {
78 return physx::PxExtendedVec3(
x,
y,
z);
80 operator physx::PxVec3()
const {
81 return physx::PxVec3(
x,
y,
z);
83 Vec3(
const physx::PxVec3& other) {
90 Vec3(
float x = 0.0f,
float y = 0.0f,
float z = 0.0f) :
x(
x),
y(
y),
z(
z) {}
106 return (
x == other.
x) && (
y == other.
y) && (
z == other.
z);
118 return (
x < other.
x) && (
y < other.
y) && (
z < other.
z);
123 return x *
x +
y *
y +
z *
z;
143 return Vec3(
x * scalar,
y * scalar,
z * scalar);
147 return std::sqrt(
x *
x +
y *
y +
z *
z);
157 y * other.
z -
z * other.
y,
158 z * other.
x -
x * other.
z,
159 x * other.
y -
y * other.
x);
163 float cosTheta = std::cos(angle);
164 float sinTheta = std::sin(angle);
168 (cosTheta + (1 - cosTheta) * normalizedAxis.
x * normalizedAxis.
x) *
x +
169 ((1 - cosTheta) * normalizedAxis.
x * normalizedAxis.
y - sinTheta * normalizedAxis.
z) *
y +
170 ((1 - cosTheta) * normalizedAxis.
x * normalizedAxis.
z + sinTheta * normalizedAxis.
y) *
z,
172 ((1 - cosTheta) * normalizedAxis.
x * normalizedAxis.
y + sinTheta * normalizedAxis.
z) *
x +
173 (cosTheta + (1 - cosTheta) * normalizedAxis.
y * normalizedAxis.
y) *
y +
174 ((1 - cosTheta) * normalizedAxis.
y * normalizedAxis.
z - sinTheta * normalizedAxis.
x) *
z,
176 ((1 - cosTheta) * normalizedAxis.
x * normalizedAxis.
z - sinTheta * normalizedAxis.
y) *
x +
177 ((1 - cosTheta) * normalizedAxis.
y * normalizedAxis.
z + sinTheta * normalizedAxis.
x) *
y +
178 (cosTheta + (1 - cosTheta) * normalizedAxis.
z * normalizedAxis.
z) *
z);
181 return x * rhs.
x +
y * rhs.
y +
z * rhs.
z;
184 template<
class Archive>
185 void serialize(Archive & ar,
const unsigned int version)
194 float length = std::sqrt(v.
x * v.
x + v.
y * v.
y + v.
z * v.
z);
195 return Vec3(v.
x / length, v.
y / length, v.
z / length);
201 a.
y * b.
z - a.
z * b.
y,
202 a.
z * b.
x - a.
x * b.
z,
203 a.
x * b.
y - a.
y * b.
x);
208 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z;
213 Vec4(
float x = 0.0f,
float y = 0.0f,
float z = 0.0f,
float w = 0.0f)
216 :
x(vec.
x),
y(vec.
y),
z(vec.
z),
w(
w) {}
221 return Vec4(
x - rhs.
x,
y - rhs.
y,
z - rhs.
z,
w - rhs.
w);
230 float length = std::sqrt(
x *
x +
y *
y +
z *
z +
w *
w);
232 return Vec4(
x / length,
y / length,
z / length,
w / length);
234 return Vec4(0.0f, 0.0f, 0.0f, 0.0f);
241 template<
class Archive>
242 void serialize(Archive & ar,
const unsigned int version)
float dot(const Vec3 &a, const Vec3 &b)
Vec3 normalize(const Vec3 &v)
Vec3 cross(const Vec3 &a, const Vec3 &b)
void serialize(Archive &ar, const unsigned int version)
Vec2 operator*(const Vec2 &rhs) const
float distance(const Vec2 &other) const
bool operator==(const Vec2 &other) const
Vec2 operator/(const Vec2 &rhs) const
Vec2(float x=0.0f, float y=0.0f)
Vec2 operator*(float scalar) const
friend class boost::serialization::access
Vec2(uint32_t x, uint32_t y)
Vec2 operator/(float scalar) const
Vec2 & operator+=(const Vec2 &rhs)
Vec2 operator-(const Vec2 &rhs) const
Vec2 operator+(const Vec2 &rhs) const
float dot(const Vec3 &rhs) const
Vec3 operator-(const Vec3 &rhs) const
bool operator<(const Vec3 &other) const
Vec3(float x=0.0f, float y=0.0f, float z=0.0f)
Vec3 cross(const Vec3 &other) const
Vec3 rotate(const Vec3 &axis, float angle) const
void serialize(Archive &ar, const unsigned int version)
bool operator==(const Vec3 &other) const
friend class boost::serialization::access
Vec3 & operator+=(const Vec3 &rhs)
Vec3(const physx::PxVec3 &other)
Vec3 operator*(float scalar) const
float lengthSquared() const
Vec3 operator+(const Vec3 &rhs) const
Vec3 & operator-=(const Vec3 &rhs)
void serialize(Archive &ar, const unsigned int version)
Vec4(Vec2 v, float z=0.0f, float w=0.0f)
Vec4(float x=0.0f, float y=0.0f, float z=0.0f, float w=0.0f)
friend class boost::serialization::access
Vec4 operator-(const Vec4 &rhs) const
Vec4(Vec3 vec, float w=0.0f)
Vector4(T x=0, T y=0, T z=0, T w=0)