This commit is contained in:
aozhiwei 2019-07-29 09:59:13 +08:00
parent 0f45b14f63
commit e27c816d97

View File

@ -18,18 +18,15 @@ namespace a8
void Vec2::Normalize()
{
#if 1
glm::vec2 v = glm::normalize(glm::vec2(x, y));
assert(!isnan(v[0]));
assert(!isnan(v[1]));
if (isnan(v[0])) {
abort();
}
if (isnan(v[1])) {
abort();
}
x = v[0];
y = v[1];
#else
Eigen::Vector2f v(x, y);
v.normalize();
x = v[0];
y = v[1];
#endif
}
bool Vec2::operator == (const Vec2& b) const
@ -39,46 +36,26 @@ namespace a8
Vec2 Vec2::operator + (const Vec2& b) const
{
#if 1
glm::vec2 v = glm::vec2(x, y) + glm::vec2(b.x, b.y);
return Vec2(v[0], v[1]);
#else
Eigen::Vector2f v = Eigen::Vector2f(x, y) + Eigen::Vector2f(b.x, b.y);
return Vec2(v[0], v[1]);
#endif
}
Vec2 Vec2::operator - (const Vec2& b) const
{
#if 1
glm::vec2 v = glm::vec2(x, y) - glm::vec2(b.x, b.y);
return Vec2(v[0], v[1]);
#else
Eigen::Vector2f v = Eigen::Vector2f(x, y) - Eigen::Vector2f(b.x, b.y);
return Vec2(v[0], v[1]);
#endif
}
Vec2 Vec2::operator * (float scale) const
{
#if 1
glm::vec2 v = glm::vec2(x, y) * scale;
return Vec2(v[0], v[1]);
#else
Eigen::Vector2f v = Eigen::Vector2f(x, y) * scale;
return Vec2(v[0], v[1]);
#endif
}
Vec2 Vec2::operator / (float scale) const
{
#if 1
glm::vec2 v = glm::vec2(x, y) / scale;
return Vec2(v[0], v[1]);
#else
Eigen::Vector2f v = Eigen::Vector2f(x, y) * (1.0 / scale);
return Vec2(v[0], v[1]);
#endif
}
void Vec2::Rotate(float angle)
@ -92,18 +69,11 @@ namespace a8
float Vec2::CalcAngle(const Vec2& b)
{
float a1 = acos(Dot(b) / Norm() / b.Norm());
#if 0
float a2 = atan2(y, x);
float a3 = atan2(y, x) / 0.017 - 90.0f;
return a2;
#else
bool at_right_side = Vec2::RIGHT.Dot(*this) > 0.0001f;
if (at_right_side) {
a1 = -a1;
}
return a1 / 3.1415926f;
// return a3 / 360.0f;
#endif
}
Vec2 Vec2::FromAngle(float angle)