Add CVector2i class

This commit is contained in:
Jack Andersen 2016-02-13 17:39:47 -10:00
parent 033bfd71e1
commit 082cac124c
5 changed files with 59 additions and 0 deletions

View File

@ -37,6 +37,7 @@ add_library(Math
include/Global.hpp
include/MathLib.hpp
include/TVectorUnion.hpp
include/CVector2i.hpp
include/CVector2f.hpp
include/CVector3f.hpp
include/CVector3d.hpp

View File

@ -132,6 +132,12 @@ public:
return ret;
}
inline CVector3f multiplyOneOverW(const CVector3f& point) const
{
CVector4f xfVec = *this * point;
return xfVec.toVec3f() / xfVec.w;
}
union
{
float m[4][4];

View File

@ -126,6 +126,11 @@ public:
m_basis[1] -= b0;
}
inline CVector3f transposeRotate(const CVector3f& in) const
{
return CVector3f(m_basis[0].dot(in), m_basis[1].dot(in), m_basis[2].dot(in));
}
inline void scaleBy(float factor)
{ CTransform xfrm(CMatrix3f(CVector3f(factor, factor, factor))); *this = *this * xfrm; }

34
include/CVector2i.hpp Normal file
View File

@ -0,0 +1,34 @@
#ifndef CVECTOR2i_HPP
#define CVECTOR2i_HPP
#include "Global.hpp"
#include "Math.hpp"
#if ZE_ATHENA_TYPES
#include <Athena/IStreamReader.hpp>
#endif
#include <math.h>
#include <assert.h>
namespace Zeus
{
class CVector2i
{
public:
union
{
struct
{
int x, y;
};
int v[2];
};
CVector2i() = default;
CVector2i(int xin, int yin) : x(xin), y(yin) {}
};
}
#endif // CVECTOR2i_HPP

View File

@ -88,12 +88,25 @@ public:
CVector4f(const CVector3f& other)
{
#if __SSE__
mVec128 = other.mVec128;
#else
x = other.x;
y = other.y;
z = other.z;
#endif
w = 1.0f;
}
inline CVector3f toVec3f() const
{
#if __SSE__
return CVector3f(mVec128);
#else
return CVector3f(x, y, z);
#endif
}
CVector4f& operator=(const CColor& other);
inline bool operator ==(const CVector4f& rhs) const
{