1
This commit is contained in:
parent
fc50e2730a
commit
0615ee4061
@ -1,10 +1,14 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#define EIGEN_NO_DEBUG
|
||||
#if 1
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#else
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
#endif
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
#include "cs_proto.pb.h"
|
||||
|
||||
const Vector2D Vector2D::UP = Vector2D(0.0f, 1.0f);
|
||||
@ -26,10 +30,16 @@ void Vector2D::FromPB(const cs::MFVector2D* pb_obj)
|
||||
|
||||
Vector2D& Vector2D::Normalize()
|
||||
{
|
||||
#if 1
|
||||
glm::vec2 v = glm::normalize(glm::vec2(x, y));
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
#else
|
||||
Eigen::Vector2f v(x, y);
|
||||
v.normalize();
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -43,7 +53,6 @@ Vector2D Vector2D::operator + (const Vector2D& b) const
|
||||
#if 1
|
||||
glm::vec2 v = glm::vec2(x, y) + glm::vec2(b.x, b.y);
|
||||
return Vector2D(v[0], v[1]);
|
||||
// return Vector2D(x + b.x, y+b.y);
|
||||
#else
|
||||
Eigen::Vector2f v = Eigen::Vector2f(x, y) + Eigen::Vector2f(b.x, b.y);
|
||||
return Vector2D(v[0], v[1]);
|
||||
@ -53,7 +62,8 @@ Vector2D Vector2D::operator + (const Vector2D& b) const
|
||||
Vector2D Vector2D::operator - (const Vector2D& b) const
|
||||
{
|
||||
#if 1
|
||||
return Vector2D(x - b.x, y-b.y);
|
||||
glm::vec2 v = glm::vec2(x, y) - glm::vec2(b.x, b.y);
|
||||
return Vector2D(v[0], v[1]);
|
||||
#else
|
||||
Eigen::Vector2f v = Eigen::Vector2f(x, y) - Eigen::Vector2f(b.x, b.y);
|
||||
return Vector2D(v[0], v[1]);
|
||||
@ -62,16 +72,31 @@ Vector2D Vector2D::operator - (const Vector2D& b) const
|
||||
|
||||
Vector2D Vector2D::operator * (float scale) const
|
||||
{
|
||||
#if 1
|
||||
glm::vec2 v = glm::vec2(x, y) * scale;
|
||||
return Vector2D(v[0], v[1]);
|
||||
#else
|
||||
Eigen::Vector2f v = Eigen::Vector2f(x, y) * scale;
|
||||
return Vector2D(v[0], v[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
Vector2D Vector2D::operator / (float scale) const
|
||||
{
|
||||
#if 1
|
||||
glm::vec2 v = glm::vec2(x, y) / scale;
|
||||
return Vector2D(v[0], v[1]);
|
||||
#else
|
||||
Eigen::Vector2f v = Eigen::Vector2f(x, y) * (1.0 / scale);
|
||||
return Vector2D(v[0], v[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 1
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
#endif
|
||||
|
||||
Vector2D Vector2D::Rotate(float angle)
|
||||
{
|
||||
Eigen::Vector3f v(x, y, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user