[DEV] plop
This commit is contained in:
parent
ff59f92dd7
commit
e81cbbac0b
@ -1,236 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/math/Matrix2.hpp>
|
||||
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix2& _obj) {
|
||||
_os << "{";
|
||||
_os << _obj.m_mat[0] << ",";
|
||||
_os << _obj.m_mat[1] << ";";
|
||||
_os << _obj.m_mat[2] << ",";
|
||||
_os << _obj.m_mat[3] << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::Matrix2::Matrix2() {
|
||||
m_mat[0] = 0.0f;
|
||||
m_mat[1] = 0.0f;
|
||||
m_mat[2] = 0.0f;
|
||||
m_mat[3] = 0.0f;
|
||||
}
|
||||
|
||||
etk::Matrix2::Matrix2(float _value) {
|
||||
m_mat[0] = _value;
|
||||
m_mat[1] = _value;
|
||||
m_mat[2] = _value;
|
||||
m_mat[3] = _value;
|
||||
}
|
||||
|
||||
etk::Matrix2::Matrix2(float _a1, float _a2,float _b1, float _b2) {
|
||||
m_mat[0] = _a1;
|
||||
m_mat[1] = _a2;
|
||||
m_mat[2] = _b1;
|
||||
m_mat[3] = _b2;
|
||||
}
|
||||
|
||||
etk::Matrix2::Matrix2(const Matrix2& _obj) {
|
||||
m_mat[0] = _obj.m_mat[0];
|
||||
m_mat[1] = _obj.m_mat[1];
|
||||
m_mat[2] = _obj.m_mat[2];
|
||||
m_mat[3] = _obj.m_mat[3];
|
||||
}
|
||||
|
||||
void etk::Matrix2::setValue(float _a1, float _a2,float _b1, float _b2) {
|
||||
m_mat[0] = _a1;
|
||||
m_mat[1] = _a2;
|
||||
m_mat[2] = _b1;
|
||||
m_mat[3] = _b2;
|
||||
}
|
||||
|
||||
void etk::Matrix2::setZero() {
|
||||
m_mat[0] = 0;
|
||||
m_mat[1] = 0;
|
||||
m_mat[2] = 0;
|
||||
m_mat[3] = 0;
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2::getColumn(uint32_t _iii) const {
|
||||
if (_iii == 0) {
|
||||
return vec2(m_mat[0], m_mat[2]);
|
||||
}
|
||||
return vec2(m_mat[1], m_mat[3]);
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2::getRow(uint32_t _iii) const {
|
||||
if (_iii == 0) {
|
||||
return vec2(m_mat[0], m_mat[1]);
|
||||
}
|
||||
return vec2(m_mat[2], m_mat[3]);
|
||||
}
|
||||
|
||||
const etk::Matrix2& etk::Matrix2::operator= (const etk::Matrix2& _obj ) {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool etk::Matrix2::operator== (const etk::Matrix2& _obj) const {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::Matrix2::operator!= (const etk::Matrix2& _obj) const {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const etk::Matrix2& etk::Matrix2::operator+= (const etk::Matrix2& _obj) {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
m_mat[iii] += _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::operator+ (const etk::Matrix2& _obj) const {
|
||||
etk::Matrix2 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix2& etk::Matrix2::operator-= (const etk::Matrix2& _obj) {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
m_mat[iii] -= _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::operator- (const etk::Matrix2& _obj) const {
|
||||
etk::Matrix2 tmpp(*this);
|
||||
tmpp -= _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
|
||||
const etk::Matrix2& etk::Matrix2::operator *= (const etk::Matrix2& _obj) {
|
||||
float t0 = m_mat[0] * _obj.m_mat[0] + m_mat[1] * _obj.m_mat[2];
|
||||
float t2 = m_mat[2] * _obj.m_mat[0] + m_mat[3] * _obj.m_mat[2];
|
||||
m_mat[1] = m_mat[0] * _obj.m_mat[1] + m_mat[1] * _obj.m_mat[3];
|
||||
m_mat[3] = m_mat[2] * _obj.m_mat[1] + m_mat[3] * _obj.m_mat[3];
|
||||
m_mat[0] = t0;
|
||||
m_mat[2] = t2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::operator * (const etk::Matrix2& _obj) const {
|
||||
etk::Matrix2 tmp(*this);
|
||||
tmp *= _obj;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2::operator * (const vec2& _point) const {
|
||||
return vec2(_point.x()*m_mat[0] + _point.y()*m_mat[1],
|
||||
_point.x()*m_mat[2] + _point.y()*m_mat[3]);
|
||||
}
|
||||
|
||||
const etk::Matrix2& etk::Matrix2::operator *= (float _value) {
|
||||
m_mat[0] *= _value;
|
||||
m_mat[1] *= _value;
|
||||
m_mat[2] *= _value;
|
||||
m_mat[3] *= _value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::operator * (float _value) const {
|
||||
etk::Matrix2 tmp(*this);
|
||||
tmp *= _value;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::getTranspose() const {
|
||||
return Matrix2(m_mat[0], m_mat[2],
|
||||
m_mat[1], m_mat[3]);
|
||||
}
|
||||
void etk::Matrix2::transpose() {
|
||||
float tmp = m_mat[2];
|
||||
m_mat[2] = m_mat[1];
|
||||
m_mat[1] = tmp;
|
||||
}
|
||||
|
||||
float etk::Matrix2::determinant() const {
|
||||
return m_mat[0] * m_mat[3] - m_mat[2] * m_mat[1];
|
||||
}
|
||||
|
||||
float etk::Matrix2::getTrace() const {
|
||||
return m_mat[0] + m_mat[3];
|
||||
}
|
||||
|
||||
void etk::Matrix2::setIdentity() {
|
||||
m_mat[0] = 1.0f;
|
||||
m_mat[1] = 0.0f;
|
||||
m_mat[2] = 0.0f;
|
||||
m_mat[3] = 1.0f;
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::identity() {
|
||||
return etk::Matrix2(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::zero() {
|
||||
return etk::Matrix2(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::getAbsolute() const {
|
||||
return Matrix2(std::abs(m_mat[0]), std::abs(m_mat[1]),
|
||||
std::abs(m_mat[2]), std::abs(m_mat[3]));
|
||||
}
|
||||
void etk::Matrix2::absolute() {
|
||||
m_mat[0] = std::abs(m_mat[0]);
|
||||
m_mat[1] = std::abs(m_mat[1]);
|
||||
m_mat[2] = std::abs(m_mat[2]);
|
||||
m_mat[3] = std::abs(m_mat[3]);
|
||||
}
|
||||
|
||||
void etk::Matrix2::inverse() {
|
||||
*this = getInverse();
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::Matrix2::getInverse() const {
|
||||
float det = determinant();
|
||||
//assert(std::abs(det) > MACHINE_EPSILON);
|
||||
float invDet = 1.0f / det;
|
||||
return etk::Matrix2(m_mat[3], -m_mat[1], -m_mat[2], m_mat[0]) * invDet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
etk::Matrix2 etk::mat2Rotate(float _angleRad) {
|
||||
return Matrix2(cos(_angleRad), sin(_angleRad), -sin(_angleRad), cos(_angleRad));
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::mat2Scale(const vec2& _scale) {
|
||||
return Matrix2(_scale.x(), 0.0, 0.0, _scale.y());
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::mat2Scale(float _scale) {
|
||||
return Matrix2(_scale, 0.0, 0.0, _scale);
|
||||
}
|
||||
|
||||
etk::Matrix2 etk::mat2Skew(const vec2& _skew) {
|
||||
return Matrix2(1.0, tan(_skew.y()), tan(_skew.x()), 1.0);
|
||||
}
|
||||
|
||||
etk::Matrix2 operator-(const etk::Matrix2& _matrix) {
|
||||
return etk::Matrix2(-_matrix.m_mat[0], -_matrix.m_mat[1], -_matrix.m_mat[2], -_matrix.m_mat[3]);
|
||||
}
|
236
etk/math/Matrix2x2.cpp
Normal file
236
etk/math/Matrix2x2.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/math/Matrix2x2.hpp>
|
||||
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix2x2& _obj) {
|
||||
_os << "{";
|
||||
_os << _obj.m_mat[0] << ",";
|
||||
_os << _obj.m_mat[1] << ";";
|
||||
_os << _obj.m_mat[2] << ",";
|
||||
_os << _obj.m_mat[3] << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::Matrix2x2::Matrix2x2() {
|
||||
m_mat[0] = 0.0f;
|
||||
m_mat[1] = 0.0f;
|
||||
m_mat[2] = 0.0f;
|
||||
m_mat[3] = 0.0f;
|
||||
}
|
||||
|
||||
etk::Matrix2x2::Matrix2x2(float _value) {
|
||||
m_mat[0] = _value;
|
||||
m_mat[1] = _value;
|
||||
m_mat[2] = _value;
|
||||
m_mat[3] = _value;
|
||||
}
|
||||
|
||||
etk::Matrix2x2::Matrix2x2(float _a1, float _a2,float _b1, float _b2) {
|
||||
m_mat[0] = _a1;
|
||||
m_mat[1] = _a2;
|
||||
m_mat[2] = _b1;
|
||||
m_mat[3] = _b2;
|
||||
}
|
||||
|
||||
etk::Matrix2x2::Matrix2x2(const Matrix2x2& _obj) {
|
||||
m_mat[0] = _obj.m_mat[0];
|
||||
m_mat[1] = _obj.m_mat[1];
|
||||
m_mat[2] = _obj.m_mat[2];
|
||||
m_mat[3] = _obj.m_mat[3];
|
||||
}
|
||||
|
||||
void etk::Matrix2x2::setValue(float _a1, float _a2,float _b1, float _b2) {
|
||||
m_mat[0] = _a1;
|
||||
m_mat[1] = _a2;
|
||||
m_mat[2] = _b1;
|
||||
m_mat[3] = _b2;
|
||||
}
|
||||
|
||||
void etk::Matrix2x2::setZero() {
|
||||
m_mat[0] = 0;
|
||||
m_mat[1] = 0;
|
||||
m_mat[2] = 0;
|
||||
m_mat[3] = 0;
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2x2::getColumn(uint32_t _iii) const {
|
||||
if (_iii == 0) {
|
||||
return vec2(m_mat[0], m_mat[2]);
|
||||
}
|
||||
return vec2(m_mat[1], m_mat[3]);
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2x2::getRow(uint32_t _iii) const {
|
||||
if (_iii == 0) {
|
||||
return vec2(m_mat[0], m_mat[1]);
|
||||
}
|
||||
return vec2(m_mat[2], m_mat[3]);
|
||||
}
|
||||
|
||||
const etk::Matrix2x2& etk::Matrix2x2::operator= (const etk::Matrix2x2& _obj ) {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool etk::Matrix2x2::operator== (const etk::Matrix2x2& _obj) const {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::Matrix2x2::operator!= (const etk::Matrix2x2& _obj) const {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const etk::Matrix2x2& etk::Matrix2x2::operator+= (const etk::Matrix2x2& _obj) {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
m_mat[iii] += _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::operator+ (const etk::Matrix2x2& _obj) const {
|
||||
etk::Matrix2x2 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix2x2& etk::Matrix2x2::operator-= (const etk::Matrix2x2& _obj) {
|
||||
for(int32_t iii=0; iii<2*2 ; ++iii) {
|
||||
m_mat[iii] -= _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::operator- (const etk::Matrix2x2& _obj) const {
|
||||
etk::Matrix2x2 tmpp(*this);
|
||||
tmpp -= _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
|
||||
const etk::Matrix2x2& etk::Matrix2x2::operator *= (const etk::Matrix2x2& _obj) {
|
||||
float t0 = m_mat[0] * _obj.m_mat[0] + m_mat[1] * _obj.m_mat[2];
|
||||
float t2 = m_mat[2] * _obj.m_mat[0] + m_mat[3] * _obj.m_mat[2];
|
||||
m_mat[1] = m_mat[0] * _obj.m_mat[1] + m_mat[1] * _obj.m_mat[3];
|
||||
m_mat[3] = m_mat[2] * _obj.m_mat[1] + m_mat[3] * _obj.m_mat[3];
|
||||
m_mat[0] = t0;
|
||||
m_mat[2] = t2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::operator * (const etk::Matrix2x2& _obj) const {
|
||||
etk::Matrix2x2 tmp(*this);
|
||||
tmp *= _obj;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2x2::operator * (const vec2& _point) const {
|
||||
return vec2(_point.x()*m_mat[0] + _point.y()*m_mat[1],
|
||||
_point.x()*m_mat[2] + _point.y()*m_mat[3]);
|
||||
}
|
||||
|
||||
const etk::Matrix2x2& etk::Matrix2x2::operator *= (float _value) {
|
||||
m_mat[0] *= _value;
|
||||
m_mat[1] *= _value;
|
||||
m_mat[2] *= _value;
|
||||
m_mat[3] *= _value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::operator * (float _value) const {
|
||||
etk::Matrix2x2 tmp(*this);
|
||||
tmp *= _value;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::getTranspose() const {
|
||||
return Matrix2x2(m_mat[0], m_mat[2],
|
||||
m_mat[1], m_mat[3]);
|
||||
}
|
||||
void etk::Matrix2x2::transpose() {
|
||||
float tmp = m_mat[2];
|
||||
m_mat[2] = m_mat[1];
|
||||
m_mat[1] = tmp;
|
||||
}
|
||||
|
||||
float etk::Matrix2x2::determinant() const {
|
||||
return m_mat[0] * m_mat[3] - m_mat[2] * m_mat[1];
|
||||
}
|
||||
|
||||
float etk::Matrix2x2::getTrace() const {
|
||||
return m_mat[0] + m_mat[3];
|
||||
}
|
||||
|
||||
void etk::Matrix2x2::setIdentity() {
|
||||
m_mat[0] = 1.0f;
|
||||
m_mat[1] = 0.0f;
|
||||
m_mat[2] = 0.0f;
|
||||
m_mat[3] = 1.0f;
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::identity() {
|
||||
return etk::Matrix2x2(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::zero() {
|
||||
return etk::Matrix2x2(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::getAbsolute() const {
|
||||
return Matrix2x2(std::abs(m_mat[0]), std::abs(m_mat[1]),
|
||||
std::abs(m_mat[2]), std::abs(m_mat[3]));
|
||||
}
|
||||
void etk::Matrix2x2::absolute() {
|
||||
m_mat[0] = std::abs(m_mat[0]);
|
||||
m_mat[1] = std::abs(m_mat[1]);
|
||||
m_mat[2] = std::abs(m_mat[2]);
|
||||
m_mat[3] = std::abs(m_mat[3]);
|
||||
}
|
||||
|
||||
void etk::Matrix2x2::inverse() {
|
||||
*this = getInverse();
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::Matrix2x2::getInverse() const {
|
||||
float det = determinant();
|
||||
//assert(std::abs(det) > MACHINE_EPSILON);
|
||||
float invDet = 1.0f / det;
|
||||
return etk::Matrix2x2(m_mat[3], -m_mat[1], -m_mat[2], m_mat[0]) * invDet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
etk::Matrix2x2 etk::mat2x2Rotate(float _angleRad) {
|
||||
return Matrix2x2(cos(_angleRad), sin(_angleRad), -sin(_angleRad), cos(_angleRad));
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::mat2x2Scale(const vec2& _scale) {
|
||||
return Matrix2x2(_scale.x(), 0.0, 0.0, _scale.y());
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::mat2x2Scale(float _scale) {
|
||||
return Matrix2x2(_scale, 0.0, 0.0, _scale);
|
||||
}
|
||||
|
||||
etk::Matrix2x2 etk::mat2x2Skew(const vec2& _skew) {
|
||||
return Matrix2x2(1.0, tan(_skew.y()), tan(_skew.x()), 1.0);
|
||||
}
|
||||
|
||||
etk::Matrix2x2 operator-(const etk::Matrix2x2& _matrix) {
|
||||
return etk::Matrix2x2(-_matrix.m_mat[0], -_matrix.m_mat[1], -_matrix.m_mat[2], -_matrix.m_mat[3]);
|
||||
}
|
@ -12,7 +12,7 @@ namespace etk {
|
||||
/**
|
||||
* This class represents a 2x2 matrix.
|
||||
*/
|
||||
class Matrix2 {
|
||||
class Matrix2x2 {
|
||||
public:
|
||||
/**
|
||||
* @brief Internal data
|
||||
@ -24,12 +24,12 @@ namespace etk {
|
||||
/**
|
||||
* @brief Constructor that load zero matrix
|
||||
*/
|
||||
Matrix2();
|
||||
Matrix2x2();
|
||||
/**
|
||||
* @brief Configuration constructorwith single value.
|
||||
* @param[in] _value single vamue
|
||||
*/
|
||||
Matrix2(float _value);
|
||||
Matrix2x2(float _value);
|
||||
/**
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _a1 element 0x0
|
||||
@ -37,12 +37,12 @@ namespace etk {
|
||||
* @param[in] _b1 element 1x0
|
||||
* @param[in] _b2 element 1x1
|
||||
*/
|
||||
Matrix2(float _a1, float _a2, float _b1, float _b2);
|
||||
Matrix2x2(float _a1, float _a2, float _b1, float _b2);
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
* @param[in] _obj Matrix object to copy
|
||||
*/
|
||||
Matrix2(const Matrix2& _matrix);
|
||||
Matrix2x2(const Matrix2x2& _matrix);
|
||||
/**
|
||||
* @brief Set Value on the matrix
|
||||
* @param[in] _a1 element 0x0
|
||||
@ -71,7 +71,7 @@ namespace etk {
|
||||
* @brief get a transpose matrix of this one.
|
||||
* @return the transpose matrix
|
||||
*/
|
||||
Matrix2 getTranspose() const;
|
||||
Matrix2x2 getTranspose() const;
|
||||
/**
|
||||
* @brief Transpose the current matrix.
|
||||
*/
|
||||
@ -91,7 +91,7 @@ namespace etk {
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
* @return The inverted matrix.
|
||||
*/
|
||||
Matrix2 getInverse() const;
|
||||
Matrix2x2 getInverse() const;
|
||||
/**
|
||||
* @brief Inverts the current matrix.
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
@ -101,7 +101,7 @@ namespace etk {
|
||||
* @brief get the mathix with the absolute value
|
||||
* @return matix in absolute
|
||||
*/
|
||||
Matrix2 getAbsolute() const;
|
||||
Matrix2x2 getAbsolute() const;
|
||||
/**
|
||||
* @brief absolutise the matrix
|
||||
*/
|
||||
@ -114,80 +114,80 @@ namespace etk {
|
||||
* @brief create a Identity matrix
|
||||
* @return created new matrix
|
||||
*/
|
||||
static etk::Matrix2 identity();
|
||||
static etk::Matrix2x2 identity();
|
||||
/**
|
||||
* @brief create a ZERO matrix
|
||||
* @return created new matrix
|
||||
*/
|
||||
static Matrix2 zero();
|
||||
static Matrix2x2 zero();
|
||||
/**
|
||||
* @brief Operator= Asign the current object with an other object
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector asigned
|
||||
*/
|
||||
const Matrix2& operator= (const Matrix2& _obj );
|
||||
const Matrix2x2& operator= (const Matrix2x2& _obj );
|
||||
/**
|
||||
* @brief Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are identical
|
||||
* @return false The Objects are NOT identical
|
||||
*/
|
||||
bool operator== (const Matrix2& _obj) const;
|
||||
bool operator== (const Matrix2x2& _obj) const;
|
||||
/**
|
||||
* @brief In-Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are NOT identical
|
||||
* @return false The Objects are identical
|
||||
*/
|
||||
bool operator!= (const Matrix2& _obj) const;
|
||||
bool operator!= (const Matrix2x2& _obj) const;
|
||||
/**
|
||||
* @brief Operator+= Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector additionned
|
||||
*/
|
||||
const Matrix2& operator+= (const Matrix2& _obj);
|
||||
const Matrix2x2& operator+= (const Matrix2x2& _obj);
|
||||
/**
|
||||
* @brief Operator+ Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2 operator+ (const Matrix2& _obj) const;
|
||||
Matrix2x2 operator+ (const Matrix2x2& _obj) const;
|
||||
/**
|
||||
* @brief Operator-= Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector decremented
|
||||
*/
|
||||
const Matrix2& operator-= (const Matrix2& _obj);
|
||||
const Matrix2x2& operator-= (const Matrix2x2& _obj);
|
||||
/**
|
||||
* @brief Operator- Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2 operator- (const Matrix2& _obj) const;
|
||||
Matrix2x2 operator- (const Matrix2x2& _obj) const;
|
||||
/**
|
||||
* @brief Operator*= Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
const Matrix2& operator *= (const Matrix2& _obj);
|
||||
const Matrix2x2& operator *= (const Matrix2x2& _obj);
|
||||
/**
|
||||
* @brief Operator* Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2 operator * (const Matrix2& _obj) const;
|
||||
Matrix2x2 operator * (const Matrix2x2& _obj) const;
|
||||
/**
|
||||
* @brief Operator*= Multiplication a value
|
||||
* @param[in] _value value to multiply all the matrix
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
const Matrix2& operator *= (float _value);
|
||||
const Matrix2x2& operator *= (float _value);
|
||||
/**
|
||||
* @brief Operator*= Multiplication a value
|
||||
* @param[in] _value value to multiply all the matrix
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
Matrix2 operator * (float _value) const;
|
||||
Matrix2x2 operator * (float _value) const;
|
||||
/**
|
||||
* @brief Operator* apply matrix on a vector
|
||||
* @param[in] _point Point value to apply the matrix
|
||||
@ -201,32 +201,32 @@ namespace etk {
|
||||
* @param[in] _angleRad Radian angle to set at the matrix
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2 mat2Rotate(float _angleRad);
|
||||
Matrix2x2 mat2x2Rotate(float _angleRad);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple scale
|
||||
* @param[in] _scale 2 dimention scale
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2 mat2Scale(const vec2& _scale);
|
||||
Matrix2x2 mat2x2Scale(const vec2& _scale);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple scale
|
||||
* @param[in] _scale same scale in 2 and Y
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2 mat2Scale(float _scale);
|
||||
Matrix2x2 mat2x2Scale(float _scale);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple skew
|
||||
* @param[in] _skew 2 dimention skew
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2 mat2Skew(const vec2& _skew);
|
||||
Matrix2x2 mat2x2Skew(const vec2& _skew);
|
||||
//! @not_in_doc
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix2& _obj);
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix2x2& _obj);
|
||||
}
|
||||
|
||||
etk::Matrix2 operator-(const etk::Matrix2& _matrix);
|
||||
etk::Matrix2x2 operator-(const etk::Matrix2x2& _matrix);
|
||||
|
||||
// simplify using of matrix ...
|
||||
using mat2 = etk::Matrix2; //!< Use simplification in upper application to use matrix like openGL shader
|
||||
using mat2 = etk::Matrix2x2; //!< Use simplification in upper application to use matrix like openGL shader
|
||||
|
||||
|
248
etk/math/Matrix2x3.cpp
Normal file
248
etk/math/Matrix2x3.cpp
Normal file
@ -0,0 +1,248 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/math/Matrix2x3.hpp>
|
||||
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix2x3& _obj) {
|
||||
_os << "{";
|
||||
_os << _obj.m_mat[0] << ",";
|
||||
_os << _obj.m_mat[4] << ",";
|
||||
_os << _obj.m_mat[1] << ",";
|
||||
_os << _obj.m_mat[3] << ",";
|
||||
_os << _obj.m_mat[2] << ",";
|
||||
_os << _obj.m_mat[5] << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::identity() {
|
||||
m_mat[0] = 1.0;
|
||||
m_mat[1] = 0.0;
|
||||
m_mat[2] = 0.0;
|
||||
m_mat[3] = 1.0;
|
||||
m_mat[4] = 0.0;
|
||||
m_mat[5] = 0.0;
|
||||
}
|
||||
|
||||
etk::Matrix2x3::Matrix2x3() {
|
||||
// TODO: Remove this ...
|
||||
identity();
|
||||
}
|
||||
etk::Matrix2x3::Matrix2x3(const etk::Matrix2x3& _obj) {
|
||||
for(int32_t iii=0; iii<2*3 ; iii++) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
}
|
||||
|
||||
etk::Matrix2x3::Matrix2x3(float _sx,
|
||||
float _shy,
|
||||
float _shx,
|
||||
float _sy,
|
||||
float _tx,
|
||||
float _ty) {
|
||||
m_mat[0] = _sx;
|
||||
m_mat[4] = _shy;
|
||||
m_mat[1] = _shx;
|
||||
m_mat[3] = _sy;
|
||||
m_mat[2] = _tx;
|
||||
m_mat[5] = _ty;
|
||||
}
|
||||
|
||||
etk::Matrix2x3::Matrix2x3(const float* _values) {
|
||||
if (_values == nullptr) {
|
||||
identity();
|
||||
return;
|
||||
}
|
||||
m_mat[0] = _values[0];
|
||||
m_mat[4] = _values[1];
|
||||
m_mat[1] = _values[2];
|
||||
m_mat[3] = _values[3];
|
||||
m_mat[2] = _values[4];
|
||||
m_mat[5] = _values[5];
|
||||
}
|
||||
|
||||
etk::Matrix2x3::Matrix2x3(const double* _values) {
|
||||
if (_values == nullptr) {
|
||||
identity();
|
||||
return;
|
||||
}
|
||||
m_mat[0] = _values[0];
|
||||
m_mat[4] = _values[1];
|
||||
m_mat[1] = _values[2];
|
||||
m_mat[3] = _values[3];
|
||||
m_mat[2] = _values[4];
|
||||
m_mat[5] = _values[5];
|
||||
}
|
||||
|
||||
const etk::Matrix2x3& etk::Matrix2x3::operator= (const etk::Matrix2x3& _obj ) {
|
||||
for(int32_t iii=0; iii<2*3 ; ++iii) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool etk::Matrix2x3::operator== (const etk::Matrix2x3& _obj) const {
|
||||
for(int32_t iii=0; iii<2*3 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::Matrix2x3::operator!= (const etk::Matrix2x3& _obj) const {
|
||||
for(int32_t iii=0; iii<2*3 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const etk::Matrix2x3& etk::Matrix2x3::operator+= (const etk::Matrix2x3& _obj) {
|
||||
for(int32_t iii=0; iii<2*3 ; ++iii) {
|
||||
m_mat[iii] += _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x3 etk::Matrix2x3::operator+ (const etk::Matrix2x3& _obj) const {
|
||||
etk::Matrix2x3 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix2x3& etk::Matrix2x3::operator-= (const etk::Matrix2x3& _obj) {
|
||||
for(int32_t iii=0; iii<2*3 ; ++iii) {
|
||||
m_mat[iii] -= _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x3 etk::Matrix2x3::operator- (const etk::Matrix2x3& _obj) const {
|
||||
etk::Matrix2x3 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix2x3& etk::Matrix2x3::operator *= (const etk::Matrix2x3& _obj) {
|
||||
float t0 = m_mat[0] * _obj.m_mat[0] + m_mat[4] * _obj.m_mat[1];
|
||||
float t2 = m_mat[1] * _obj.m_mat[0] + m_mat[3] * _obj.m_mat[1];
|
||||
float t4 = m_mat[2] * _obj.m_mat[0] + m_mat[5] * _obj.m_mat[1] + _obj.m_mat[2];
|
||||
m_mat[4] = m_mat[0] * _obj.m_mat[4] + m_mat[4] * _obj.m_mat[3];
|
||||
m_mat[3] = m_mat[1] * _obj.m_mat[4] + m_mat[3] * _obj.m_mat[3];
|
||||
m_mat[5] = m_mat[2] * _obj.m_mat[4] + m_mat[5] * _obj.m_mat[3] + _obj.m_mat[5];
|
||||
m_mat[0] = t0;
|
||||
m_mat[1] = t2;
|
||||
m_mat[2] = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix2x3 etk::Matrix2x3::operator * (const etk::Matrix2x3& _obj) {
|
||||
etk::Matrix2x3 tmp(*this);
|
||||
tmp *= _obj;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2x3::operator * (const vec2& _point) const {
|
||||
return vec2(_point.x()*m_mat[0] + _point.y()*m_mat[1] + m_mat[2],
|
||||
_point.x()*m_mat[4] + _point.y()*m_mat[3] + m_mat[5]);
|
||||
}
|
||||
|
||||
vec2 etk::Matrix2x3::applyScaleRotation(const vec2& _point) const {
|
||||
return vec2(_point.x()*m_mat[0] + _point.y()*m_mat[1],
|
||||
_point.x()*m_mat[4] + _point.y()*m_mat[3]);
|
||||
}
|
||||
|
||||
etk::Matrix2x3 etk::Matrix2x3::operator ~ () const {
|
||||
etk::Matrix2x3 tmp(*this);
|
||||
tmp.invert();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::flipX() {
|
||||
m_mat[0] = -m_mat[0];
|
||||
m_mat[4] = -m_mat[4];
|
||||
m_mat[2] = -m_mat[2];
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::flipY() {
|
||||
m_mat[1] = -m_mat[1];
|
||||
m_mat[3] = -m_mat[3];
|
||||
m_mat[5] = -m_mat[5];
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::scale(const vec2& _vect) {
|
||||
m_mat[0] *= _vect.x();
|
||||
m_mat[1] *= _vect.x();
|
||||
m_mat[2] *= _vect.x();
|
||||
m_mat[4] *= _vect.y();
|
||||
m_mat[3] *= _vect.y();
|
||||
m_mat[5] *= _vect.y();
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::scale(float _value) {
|
||||
m_mat[0] *= _value;
|
||||
m_mat[1] *= _value;
|
||||
m_mat[2] *= _value;
|
||||
m_mat[4] *= _value;
|
||||
m_mat[3] *= _value;
|
||||
m_mat[5] *= _value;
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::rotate(float _angleRad) {
|
||||
float ca = cos(_angleRad);
|
||||
float sa = sin(_angleRad);
|
||||
float t0 = m_mat[0] * ca - m_mat[4] * sa;
|
||||
float t2 = m_mat[1] * ca - m_mat[3] * sa;
|
||||
float t4 = m_mat[2] * ca - m_mat[5] * sa;
|
||||
m_mat[4] = m_mat[0] * sa + m_mat[4] * ca;
|
||||
m_mat[3] = m_mat[1] * sa + m_mat[3] * ca;
|
||||
m_mat[5] = m_mat[2] * sa + m_mat[5] * ca;
|
||||
m_mat[0] = t0;
|
||||
m_mat[1] = t2;
|
||||
m_mat[2] = t4;
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::translate(const vec2& _vect) {
|
||||
m_mat[2] += _vect.x();
|
||||
m_mat[5] += _vect.y();
|
||||
}
|
||||
|
||||
float etk::Matrix2x3::determinant() const {
|
||||
return m_mat[0] * m_mat[3] - m_mat[4] * m_mat[1];
|
||||
}
|
||||
|
||||
void etk::Matrix2x3::invert() {
|
||||
float det = 1.0f / determinant();
|
||||
float t0 = m_mat[3] * det;
|
||||
m_mat[3] = m_mat[0] * det;
|
||||
m_mat[4] = -m_mat[4] * det;
|
||||
m_mat[1] = -m_mat[1] * det;
|
||||
float t4 = -m_mat[2] * t0 - m_mat[5] * m_mat[1];
|
||||
m_mat[5] = -m_mat[2] * m_mat[4] - m_mat[5] * m_mat[3];
|
||||
m_mat[0] = t0;
|
||||
m_mat[2] = t4;
|
||||
}
|
||||
|
||||
etk::Matrix2x3 etk::mat2x3Rotate(float _angleRad) {
|
||||
return etk::Matrix2x3(cos(_angleRad), sin(_angleRad), -sin(_angleRad), cos(_angleRad), 0.0, 0.0);
|
||||
};
|
||||
|
||||
etk::Matrix2x3 etk::mat2x3Scale(const vec2& _scale) {
|
||||
return etk::Matrix2x3(_scale.x(), 0.0, 0.0, _scale.y(), 0.0, 0.0);
|
||||
};
|
||||
|
||||
etk::Matrix2x3 etk::mat2x3Scale(float _scale) {
|
||||
return etk::Matrix2x3(_scale, 0.0, 0.0, _scale, 0.0, 0.0);
|
||||
};
|
||||
|
||||
etk::Matrix2x3 etk::mat2x3Translate(const vec2& _translate) {
|
||||
return etk::Matrix2x3(1.0, 0.0, 0.0, 1.0, _translate.x(), _translate.y());
|
||||
};
|
||||
|
||||
etk::Matrix2x3 etk::mat2x3Skew(const vec2& _skew) {
|
||||
return etk::Matrix2x3(1.0, tan(_skew.y()), tan(_skew.x()), 1.0, 0.0, 0.0);
|
||||
};
|
211
etk/math/Matrix2x3.hpp
Normal file
211
etk/math/Matrix2x3.hpp
Normal file
@ -0,0 +1,211 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <etk/types.hpp>
|
||||
namespace etk {
|
||||
/**
|
||||
* @brief Transformation matrix for vector 2D.
|
||||
*/
|
||||
class Matrix2x3 {
|
||||
public:
|
||||
/**
|
||||
* @brief Internal data
|
||||
* sx shx tx
|
||||
* sy shy ty
|
||||
*/
|
||||
float m_mat[2*3];
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor that load identity
|
||||
*/
|
||||
Matrix2x3();
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
* @param[in] _obj Matrix object to copy
|
||||
*/
|
||||
Matrix2x3(const Matrix2x3& _obj);
|
||||
/**
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _sx Scale threw X axis
|
||||
* @param[in] _shy Rotate in radian threw Y axis
|
||||
* @param[in] _shx Rotate in radian threw X axis
|
||||
* @param[in] _sy Scale threw Y axis
|
||||
* @param[in] _tx Translate threw X axis
|
||||
* @param[in] _ty translate threw Y axis
|
||||
*/
|
||||
Matrix2x3(float _sx,
|
||||
float _shy,
|
||||
float _shx,
|
||||
float _sy,
|
||||
float _tx,
|
||||
float _ty);
|
||||
/**
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _values vector of values in float
|
||||
*/
|
||||
Matrix2x3(const float* _values);
|
||||
/**
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _values vector of values in double
|
||||
*/
|
||||
Matrix2x3(const double* _values);
|
||||
/**
|
||||
* @brief Load Identity matrix
|
||||
*/
|
||||
void identity();
|
||||
/**
|
||||
* @brief Operator= Asign the current object with an other object
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector asigned
|
||||
*/
|
||||
const Matrix2x3& operator= (const Matrix2x3& _obj );
|
||||
/**
|
||||
* @brief Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are identical
|
||||
* @return false The Objects are NOT identical
|
||||
*/
|
||||
bool operator== (const Matrix2x3& _obj) const;
|
||||
/**
|
||||
* @brief In-Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are NOT identical
|
||||
* @return false The Objects are identical
|
||||
*/
|
||||
bool operator!= (const Matrix2x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator+= Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector additionned
|
||||
*/
|
||||
const Matrix2x3& operator+= (const Matrix2x3& _obj);
|
||||
/**
|
||||
* @brief Operator+ Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2x3 operator+ (const Matrix2x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator-= Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector decremented
|
||||
*/
|
||||
const Matrix2x3& operator-= (const Matrix2x3& _obj);
|
||||
/**
|
||||
* @brief Operator- Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2x3 operator- (const Matrix2x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator*= Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
const Matrix2x3& operator *= (const Matrix2x3& _obj);
|
||||
/**
|
||||
* @brief Operator* Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2x3 operator * (const Matrix2x3& _obj);
|
||||
/**
|
||||
* @brief Operator* apply matrix on a vector
|
||||
* @param[in] _point Point value to apply the matrix
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
vec2 operator * (const vec2& _point) const;
|
||||
/**
|
||||
* @brief Apply matrix on a vector Scale Rotate, but NOT the translation
|
||||
* @param[in] _point Point value to apply the matrix
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
vec2 applyScaleRotation(const vec2& _point) const;
|
||||
/**
|
||||
* @brief Inverse the current Matrix
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix2x3 operator ~ () const;
|
||||
/**
|
||||
* @brief Flip the mathix threw the X axis
|
||||
*/
|
||||
void flipX();
|
||||
/**
|
||||
* @brief Flip the mathix threw the Y axis
|
||||
*/
|
||||
void flipY();
|
||||
/**
|
||||
* @brief Scale the current Matrix.
|
||||
* @param[in] _vect Vector to scale matrix.
|
||||
*/
|
||||
void scale(const vec2& _vect);
|
||||
/**
|
||||
* @brief Scale the current Matrix.
|
||||
* @param[in] _value Single value to scale in X andf Y.
|
||||
*/
|
||||
void scale(float _value);
|
||||
/**
|
||||
* @brief Makes a rotation matrix.
|
||||
* @param[in] _angleRad angle to apply.
|
||||
*/
|
||||
void rotate(float _angleRad);
|
||||
/**
|
||||
* @brief Makes a translation of the matrix
|
||||
* @param[in] _vect Translation to apply.
|
||||
*/
|
||||
void translate(const vec2& _vect);
|
||||
/**
|
||||
* @brief Computes the determinant of the matrix.
|
||||
* @return The determinent Value.
|
||||
*/
|
||||
float determinant() const;
|
||||
/**
|
||||
* @brief Inverts the matrix.
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
* @return The inverted matrix.
|
||||
*/
|
||||
void invert();
|
||||
};
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple rotation
|
||||
* @param[in] _angleRad Radian angle to set at the matrix
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2x3 mat2x3Rotate(float _angleRad);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple scale
|
||||
* @param[in] _scale 2 dimention scale
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2x3 mat2x3Scale(const vec2& _scale);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple scale
|
||||
* @param[in] _scale same scale in 2 and Y
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2x3 mat2x3Scale(float _scale);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple translation
|
||||
* @param[in] _translate 2 dimention translation
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2x3 mat2x3Translate(const vec2& _translate);
|
||||
/**
|
||||
* @brief Create a matrix 2D with a simple skew
|
||||
* @param[in] _skew 2 dimention skew
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix2x3 mat2x3Skew(const vec2& _skew);
|
||||
//! @not_in_doc
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix2x3& _obj);
|
||||
}
|
||||
// simplify using of matrix ...
|
||||
using mat2x3 = etk::Matrix2x3; //!< Use simplification in upper application to use matrix like openGL shader
|
||||
|
||||
|
@ -4,10 +4,10 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/math/Matrix3.hpp>
|
||||
#include <etk/math/Matrix3x3.hpp>
|
||||
|
||||
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix3& _obj) {
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix3x3& _obj) {
|
||||
_os << "{";
|
||||
_os << _obj.m_mat[0] << ",";
|
||||
_os << _obj.m_mat[1] << ",";
|
||||
@ -21,7 +21,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix3& _obj) {
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::Matrix3::Matrix3() {
|
||||
etk::Matrix3x3::Matrix3x3() {
|
||||
m_mat[0] = 0.0f;
|
||||
m_mat[1] = 0.0f;
|
||||
m_mat[2] = 0.0f;
|
||||
@ -33,7 +33,7 @@ etk::Matrix3::Matrix3() {
|
||||
m_mat[8] = 0.0f;
|
||||
}
|
||||
|
||||
etk::Matrix3::Matrix3(float _value) {
|
||||
etk::Matrix3x3::Matrix3x3(float _value) {
|
||||
m_mat[0] = _value;
|
||||
m_mat[1] = _value;
|
||||
m_mat[2] = _value;
|
||||
@ -45,7 +45,7 @@ etk::Matrix3::Matrix3(float _value) {
|
||||
m_mat[8] = _value;
|
||||
}
|
||||
|
||||
etk::Matrix3::Matrix3(float _a1, float _a2, float _a3,
|
||||
etk::Matrix3x3::Matrix3x3(float _a1, float _a2, float _a3,
|
||||
float _b1, float _b2, float _b3,
|
||||
float _c1, float _c2, float _c3) {
|
||||
m_mat[0] = _a1; m_mat[1] = _a2; m_mat[2] = _a3;
|
||||
@ -53,7 +53,7 @@ etk::Matrix3::Matrix3(float _a1, float _a2, float _a3,
|
||||
m_mat[6] = _c1; m_mat[7] = _c2; m_mat[8] = _c3;
|
||||
}
|
||||
|
||||
etk::Matrix3::Matrix3(const etk::Matrix3& _obj) {
|
||||
etk::Matrix3x3::Matrix3x3(const etk::Matrix3x3& _obj) {
|
||||
m_mat[0] = _obj.m_mat[0];
|
||||
m_mat[1] = _obj.m_mat[1];
|
||||
m_mat[2] = _obj.m_mat[2];
|
||||
@ -65,7 +65,7 @@ etk::Matrix3::Matrix3(const etk::Matrix3& _obj) {
|
||||
m_mat[8] = _obj.m_mat[8];
|
||||
}
|
||||
|
||||
void etk::Matrix3::setValue(float _a1, float _a2, float _a3,
|
||||
void etk::Matrix3x3::setValue(float _a1, float _a2, float _a3,
|
||||
float _b1, float _b2, float _b3,
|
||||
float _c1, float _c2, float _c3) {
|
||||
m_mat[0] = _a1; m_mat[1] = _a2; m_mat[2] = _a3;
|
||||
@ -73,7 +73,7 @@ void etk::Matrix3::setValue(float _a1, float _a2, float _a3,
|
||||
m_mat[6] = _c1; m_mat[7] = _c2; m_mat[8] = _c3;
|
||||
}
|
||||
|
||||
void etk::Matrix3::setZero() {
|
||||
void etk::Matrix3x3::setZero() {
|
||||
m_mat[0] = 0.0f;
|
||||
m_mat[1] = 0.0f;
|
||||
m_mat[2] = 0.0f;
|
||||
@ -85,7 +85,7 @@ void etk::Matrix3::setZero() {
|
||||
m_mat[8] = 0.0f;
|
||||
}
|
||||
|
||||
vec3 etk::Matrix3::getColumn(uint32_t _iii) const {
|
||||
vec3 etk::Matrix3x3::getColumn(uint32_t _iii) const {
|
||||
if (_iii == 0) {
|
||||
return vec3(m_mat[0], m_mat[3], m_mat[6]);
|
||||
} else if (_iii == 1) {
|
||||
@ -94,7 +94,7 @@ vec3 etk::Matrix3::getColumn(uint32_t _iii) const {
|
||||
return vec3(m_mat[2], m_mat[5], m_mat[8]);
|
||||
}
|
||||
|
||||
vec3 etk::Matrix3::getRow(uint32_t _iii) const {
|
||||
vec3 etk::Matrix3x3::getRow(uint32_t _iii) const {
|
||||
if (_iii == 0) {
|
||||
return vec3(m_mat[0], m_mat[1], m_mat[2]);
|
||||
} else if (_iii == 1) {
|
||||
@ -103,13 +103,13 @@ vec3 etk::Matrix3::getRow(uint32_t _iii) const {
|
||||
return vec3(m_mat[6], m_mat[7], m_mat[8]);
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::getTranspose() const {
|
||||
return etk::Matrix3(m_mat[0], m_mat[3], m_mat[6],
|
||||
etk::Matrix3x3 etk::Matrix3x3::getTranspose() const {
|
||||
return etk::Matrix3x3(m_mat[0], m_mat[3], m_mat[6],
|
||||
m_mat[1], m_mat[4], m_mat[7],
|
||||
m_mat[2], m_mat[5], m_mat[8]);
|
||||
}
|
||||
|
||||
void etk::Matrix3::transpose() {
|
||||
void etk::Matrix3x3::transpose() {
|
||||
float tmp = m_mat[1];
|
||||
m_mat[1] = m_mat[3];
|
||||
m_mat[3] = tmp;
|
||||
@ -121,31 +121,31 @@ void etk::Matrix3::transpose() {
|
||||
m_mat[7] = tmp;
|
||||
}
|
||||
|
||||
float etk::Matrix3::determinant() const {
|
||||
float etk::Matrix3x3::determinant() const {
|
||||
return m_mat[0]*(m_mat[4]*m_mat[8]-m_mat[7]*m_mat[5])
|
||||
- m_mat[1]*(m_mat[3]*m_mat[8]-m_mat[6]*m_mat[5])
|
||||
+ m_mat[2]*(m_mat[3]*m_mat[7]-m_mat[6]*m_mat[4]);
|
||||
}
|
||||
|
||||
float etk::Matrix3::getTrace() const {
|
||||
float etk::Matrix3x3::getTrace() const {
|
||||
return (m_mat[0] + m_mat[4] + m_mat[8]);
|
||||
}
|
||||
|
||||
void etk::Matrix3::setIdentity() {
|
||||
void etk::Matrix3x3::setIdentity() {
|
||||
m_mat[0] = 1.0; m_mat[1] = 0.0; m_mat[2] = 0.0;
|
||||
m_mat[3] = 0.0; m_mat[4] = 1.0; m_mat[5] = 0.0;
|
||||
m_mat[6] = 0.0; m_mat[7] = 0.0; m_mat[8] = 1.0;
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::identity() {
|
||||
return etk::Matrix3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
|
||||
etk::Matrix3x3 etk::Matrix3x3::identity() {
|
||||
return etk::Matrix3x3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::zero() {
|
||||
return etk::Matrix3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
||||
etk::Matrix3x3 etk::Matrix3x3::zero() {
|
||||
return etk::Matrix3x3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
void etk::Matrix3::absolute() {
|
||||
void etk::Matrix3x3::absolute() {
|
||||
m_mat[0] = std::abs(m_mat[0]);
|
||||
m_mat[1] = std::abs(m_mat[1]);
|
||||
m_mat[2] = std::abs(m_mat[2]);
|
||||
@ -157,22 +157,22 @@ void etk::Matrix3::absolute() {
|
||||
m_mat[8] = std::abs(m_mat[8]);
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::getAbsolute() const {
|
||||
return etk::Matrix3(std::abs(m_mat[0]), std::abs(m_mat[1]), std::abs(m_mat[2]),
|
||||
etk::Matrix3x3 etk::Matrix3x3::getAbsolute() const {
|
||||
return etk::Matrix3x3(std::abs(m_mat[0]), std::abs(m_mat[1]), std::abs(m_mat[2]),
|
||||
std::abs(m_mat[3]), std::abs(m_mat[4]), std::abs(m_mat[5]),
|
||||
std::abs(m_mat[6]), std::abs(m_mat[7]), std::abs(m_mat[8]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
const etk::Matrix3& etk::Matrix3::operator= (const etk::Matrix3& _obj ) {
|
||||
const etk::Matrix3x3& etk::Matrix3x3::operator= (const etk::Matrix3x3& _obj ) {
|
||||
for(int32_t iii=0; iii<3*3 ; ++iii) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool etk::Matrix3::operator== (const etk::Matrix3& _obj) const {
|
||||
bool etk::Matrix3x3::operator== (const etk::Matrix3x3& _obj) const {
|
||||
for(int32_t iii=0; iii<3*3 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return false;
|
||||
@ -181,7 +181,7 @@ bool etk::Matrix3::operator== (const etk::Matrix3& _obj) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::Matrix3::operator!= (const etk::Matrix3& _obj) const {
|
||||
bool etk::Matrix3x3::operator!= (const etk::Matrix3x3& _obj) const {
|
||||
for(int32_t iii=0; iii<3*3 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return true;
|
||||
@ -190,33 +190,33 @@ bool etk::Matrix3::operator!= (const etk::Matrix3& _obj) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const etk::Matrix3& etk::Matrix3::operator+= (const etk::Matrix3& _obj) {
|
||||
const etk::Matrix3x3& etk::Matrix3x3::operator+= (const etk::Matrix3x3& _obj) {
|
||||
for(int32_t iii=0; iii<3*3 ; ++iii) {
|
||||
m_mat[iii] += _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::operator+ (const etk::Matrix3& _obj) const {
|
||||
etk::Matrix3 tmpp(*this);
|
||||
etk::Matrix3x3 etk::Matrix3x3::operator+ (const etk::Matrix3x3& _obj) const {
|
||||
etk::Matrix3x3 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix3& etk::Matrix3::operator-= (const etk::Matrix3& _obj) {
|
||||
const etk::Matrix3x3& etk::Matrix3x3::operator-= (const etk::Matrix3x3& _obj) {
|
||||
for(int32_t iii=0; iii<3*3 ; ++iii) {
|
||||
m_mat[iii] -= _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::operator- (const etk::Matrix3& _obj) const {
|
||||
etk::Matrix3 tmpp(*this);
|
||||
etk::Matrix3x3 etk::Matrix3x3::operator- (const etk::Matrix3x3& _obj) const {
|
||||
etk::Matrix3x3 tmpp(*this);
|
||||
tmpp -= _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix3& etk::Matrix3::operator *= (const etk::Matrix3& _obj) {
|
||||
const etk::Matrix3x3& etk::Matrix3x3::operator *= (const etk::Matrix3x3& _obj) {
|
||||
float a1 = m_mat[0]*_obj.m_mat[0] + m_mat[1]*_obj.m_mat[3] + m_mat[2]*_obj.m_mat[6];
|
||||
float b1 = m_mat[3]*_obj.m_mat[0] + m_mat[4]*_obj.m_mat[3] + m_mat[5]*_obj.m_mat[6];
|
||||
float c1 = m_mat[6]*_obj.m_mat[0] + m_mat[7]*_obj.m_mat[3] + m_mat[8]*_obj.m_mat[6];
|
||||
@ -235,19 +235,19 @@ const etk::Matrix3& etk::Matrix3::operator *= (const etk::Matrix3& _obj) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::operator * (const etk::Matrix3& _obj) const {
|
||||
etk::Matrix3 tmp(*this);
|
||||
etk::Matrix3x3 etk::Matrix3x3::operator * (const etk::Matrix3x3& _obj) const {
|
||||
etk::Matrix3x3 tmp(*this);
|
||||
tmp *= _obj;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
vec3 etk::Matrix3::operator * (const vec3& _point) const {
|
||||
vec3 etk::Matrix3x3::operator * (const vec3& _point) const {
|
||||
return vec3(_point.x()*m_mat[0] + _point.y()*m_mat[1] + _point.z()*m_mat[2],
|
||||
_point.x()*m_mat[3] + _point.y()*m_mat[4] + _point.z()*m_mat[5],
|
||||
_point.x()*m_mat[6] + _point.y()*m_mat[7] + _point.z()*m_mat[8]);
|
||||
}
|
||||
|
||||
const etk::Matrix3& etk::Matrix3::operator *= (float _value) {
|
||||
const etk::Matrix3x3& etk::Matrix3x3::operator *= (float _value) {
|
||||
m_mat[0] *= _value;
|
||||
m_mat[1] *= _value;
|
||||
m_mat[2] *= _value;
|
||||
@ -260,21 +260,21 @@ const etk::Matrix3& etk::Matrix3::operator *= (float _value) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::operator * (float _value) const {
|
||||
etk::Matrix3 tmp(*this);
|
||||
etk::Matrix3x3 etk::Matrix3x3::operator * (float _value) const {
|
||||
etk::Matrix3x3 tmp(*this);
|
||||
tmp *= _value;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void etk::Matrix3::inverse() {
|
||||
void etk::Matrix3x3::inverse() {
|
||||
*this = getInverse();
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::getInverse() const {
|
||||
etk::Matrix3x3 etk::Matrix3x3::getInverse() const {
|
||||
float det = determinant();
|
||||
//assert(std::abs(det) > MACHINE_EPSILON);
|
||||
float invDet = 1.0f / det;
|
||||
return etk::Matrix3( (m_mat[4]*m_mat[8]-m_mat[7]*m_mat[5]),
|
||||
return etk::Matrix3x3( (m_mat[4]*m_mat[8]-m_mat[7]*m_mat[5]),
|
||||
-(m_mat[1]*m_mat[8]-m_mat[7]*m_mat[2]),
|
||||
(m_mat[1]*m_mat[5]-m_mat[2]*m_mat[4]),
|
||||
-(m_mat[3]*m_mat[8]-m_mat[6]*m_mat[5]),
|
||||
@ -285,14 +285,14 @@ etk::Matrix3 etk::Matrix3::getInverse() const {
|
||||
(m_mat[0]*m_mat[4]-m_mat[1]*m_mat[3]))* invDet;
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Matrix3::computeSkewSymmetricMatrixForCrossProduct(const vec3& vector) {
|
||||
return etk::Matrix3( 0.0f , -vector.z(), vector.y(),
|
||||
etk::Matrix3x3 etk::Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(const vec3& vector) {
|
||||
return etk::Matrix3x3( 0.0f , -vector.z(), vector.y(),
|
||||
vector.z(), 0.0f , -vector.x(),
|
||||
-vector.y(), vector.x(), 0.0f);
|
||||
}
|
||||
|
||||
etk::Matrix3 operator-(const etk::Matrix3& _matrix) {
|
||||
return etk::Matrix3(-_matrix.m_mat[0], -_matrix.m_mat[1], -_matrix.m_mat[2],
|
||||
etk::Matrix3x3 operator-(const etk::Matrix3x3& _matrix) {
|
||||
return etk::Matrix3x3(-_matrix.m_mat[0], -_matrix.m_mat[1], -_matrix.m_mat[2],
|
||||
-_matrix.m_mat[3], -_matrix.m_mat[4], -_matrix.m_mat[5],
|
||||
-_matrix.m_mat[6], -_matrix.m_mat[7], -_matrix.m_mat[8]);
|
||||
}
|
@ -12,19 +12,19 @@ namespace etk {
|
||||
/**
|
||||
* @brief This class represents a 3x3 matrix.
|
||||
*/
|
||||
class Matrix3 {
|
||||
class Matrix3x3 {
|
||||
public:
|
||||
float m_mat[3*3]; //!< matrix data
|
||||
public :
|
||||
/**
|
||||
* @brief Constructor that load zero matrix
|
||||
*/
|
||||
Matrix3();
|
||||
Matrix3x3();
|
||||
/**
|
||||
* @brief Configuration constructorwith single value.
|
||||
* @param[in] _value single vamue
|
||||
*/
|
||||
Matrix3(float value);
|
||||
Matrix3x3(float value);
|
||||
/**
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _a1 element 0x0
|
||||
@ -37,14 +37,14 @@ namespace etk {
|
||||
* @param[in] _c2 element 2x1
|
||||
* @param[in] _c3 element 2x2
|
||||
*/
|
||||
Matrix3(float _a1, float _a2, float _a3,
|
||||
Matrix3x3(float _a1, float _a2, float _a3,
|
||||
float _b1, float _b2, float _b3,
|
||||
float _c1, float _c2, float _c3);
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
* @param[in] _obj Matrix object to copy
|
||||
*/
|
||||
Matrix3(const Matrix3& _obj);
|
||||
Matrix3x3(const Matrix3x3& _obj);
|
||||
/**
|
||||
* @brief Set Value on the matrix
|
||||
* @param[in] _a1 element 0x0
|
||||
@ -80,7 +80,7 @@ namespace etk {
|
||||
* @brief get a transpose matrix of this one.
|
||||
* @return the transpose matrix
|
||||
*/
|
||||
Matrix3 getTranspose() const;
|
||||
Matrix3x3 getTranspose() const;
|
||||
/**
|
||||
* @brief Transpose the current matrix.
|
||||
*/
|
||||
@ -100,7 +100,7 @@ namespace etk {
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
* @return The inverted matrix.
|
||||
*/
|
||||
Matrix3 getInverse() const;
|
||||
Matrix3x3 getInverse() const;
|
||||
/**
|
||||
* @brief Inverts the current matrix.
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
@ -110,7 +110,7 @@ namespace etk {
|
||||
* @brief get the matrix with the absolute value
|
||||
* @return matix in absolute
|
||||
*/
|
||||
Matrix3 getAbsolute() const;
|
||||
Matrix3x3 getAbsolute() const;
|
||||
/**
|
||||
* @brief absolutise the matrix
|
||||
*/
|
||||
@ -123,86 +123,86 @@ namespace etk {
|
||||
* @brief create a Identity matrix
|
||||
* @return created new matrix
|
||||
*/
|
||||
static Matrix3 identity();
|
||||
static Matrix3x3 identity();
|
||||
/**
|
||||
* @brief create a ZERO matrix
|
||||
* @return created new matrix
|
||||
*/
|
||||
static Matrix3 zero();
|
||||
static Matrix3x3 zero();
|
||||
/**
|
||||
* @brief create a skew-symmetric matrix using a given vector that can be used to compute cross product with another vector using matrix multiplication
|
||||
* @param[in] _vector Vector to comute
|
||||
* @return Matrix to compute
|
||||
*/
|
||||
static Matrix3 computeSkewSymmetricMatrixForCrossProduct(const vec3& _vector);
|
||||
static Matrix3x3 computeSkewSymmetricMatrixForCrossProduct(const vec3& _vector);
|
||||
/**
|
||||
* @brief Operator= Asign the current object with an other object
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector asigned
|
||||
*/
|
||||
const Matrix3& operator= (const Matrix3& _obj );
|
||||
const Matrix3x3& operator= (const Matrix3x3& _obj );
|
||||
/**
|
||||
* @brief Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are identical
|
||||
* @return false The Objects are NOT identical
|
||||
*/
|
||||
bool operator== (const Matrix3& _obj) const;
|
||||
bool operator== (const Matrix3x3& _obj) const;
|
||||
/**
|
||||
* @brief In-Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are NOT identical
|
||||
* @return false The Objects are identical
|
||||
*/
|
||||
bool operator!= (const Matrix3& _obj) const;
|
||||
bool operator!= (const Matrix3x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator+= Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector additionned
|
||||
*/
|
||||
const Matrix3& operator+= (const Matrix3& _obj);
|
||||
const Matrix3x3& operator+= (const Matrix3x3& _obj);
|
||||
/**
|
||||
* @brief Operator+ Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix3 operator+ (const Matrix3& _obj) const;
|
||||
Matrix3x3 operator+ (const Matrix3x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator-= Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector decremented
|
||||
*/
|
||||
const Matrix3& operator-= (const Matrix3& _obj);
|
||||
const Matrix3x3& operator-= (const Matrix3x3& _obj);
|
||||
/**
|
||||
* @brief Operator- Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix3 operator- (const Matrix3& _obj) const;
|
||||
Matrix3x3 operator- (const Matrix3x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator*= Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
const Matrix3& operator *= (const Matrix3& _obj);
|
||||
const Matrix3x3& operator *= (const Matrix3x3& _obj);
|
||||
/**
|
||||
* @brief Operator* Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix3 operator * (const Matrix3& _obj) const;
|
||||
Matrix3x3 operator * (const Matrix3x3& _obj) const;
|
||||
/**
|
||||
* @brief Operator*= Multiplication a value
|
||||
* @param[in] _value value to multiply all the matrix
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
const Matrix3& operator *= (float _value);
|
||||
const Matrix3x3& operator *= (float _value);
|
||||
/**
|
||||
* @brief Operator*= Multiplication a value
|
||||
* @param[in] _value value to multiply all the matrix
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
Matrix3 operator * (float _value) const;
|
||||
Matrix3x3 operator * (float _value) const;
|
||||
/**
|
||||
* @brief Operator* apply matrix on a vector
|
||||
* @param[in] _point Point value to apply the matrix
|
||||
@ -211,12 +211,12 @@ namespace etk {
|
||||
vec3 operator * (const vec3& _point) const;
|
||||
};
|
||||
//! @not_in_doc
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix3& _obj);
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix3x3& _obj);
|
||||
}
|
||||
|
||||
etk::Matrix3 operator-(const etk::Matrix3& _matrix);
|
||||
etk::Matrix3x3 operator-(const etk::Matrix3x3& _matrix);
|
||||
|
||||
// simplify using of matrix ...
|
||||
using mat3 = etk::Matrix3; //!< Use simplification in upper application to use matrix like openGL shader
|
||||
using mat3 = etk::Matrix3x3; //!< Use simplification in upper application to use matrix like openGL shader
|
||||
|
||||
|
@ -5,11 +5,11 @@
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/math/Matrix4.hpp>
|
||||
#include <etk/math/Matrix4x4.hpp>
|
||||
#include <etk/debug.hpp>
|
||||
#include <cmath>
|
||||
|
||||
void etk::Matrix4::identity() {
|
||||
void etk::Matrix4x4::identity() {
|
||||
for(int32_t iii=0; iii<4*4 ; iii++) {
|
||||
m_mat[iii] = 0;
|
||||
}
|
||||
@ -19,17 +19,17 @@ void etk::Matrix4::identity() {
|
||||
m_mat[15] = 1.0;
|
||||
}
|
||||
|
||||
etk::Matrix4::Matrix4() {
|
||||
etk::Matrix4x4::Matrix4x4() {
|
||||
identity();
|
||||
}
|
||||
|
||||
etk::Matrix4::Matrix4(const Matrix4& _obj) {
|
||||
etk::Matrix4x4::Matrix4x4(const Matrix4x4& _obj) {
|
||||
for(int32_t iii=0; iii<4*4 ; iii++) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
}
|
||||
|
||||
etk::Matrix4::Matrix4(float _a1, float _b1, float _c1, float _d1,
|
||||
etk::Matrix4x4::Matrix4x4(float _a1, float _b1, float _c1, float _d1,
|
||||
float _a2, float _b2, float _c2, float _d2,
|
||||
float _a3, float _b3, float _c3, float _d3,
|
||||
float _a4, float _b4, float _c4, float _d4) {
|
||||
@ -51,7 +51,7 @@ etk::Matrix4::Matrix4(float _a1, float _b1, float _c1, float _d1,
|
||||
m_mat[15] = _d4;
|
||||
}
|
||||
|
||||
etk::Matrix4::Matrix4(float* _obj) {
|
||||
etk::Matrix4x4::Matrix4x4(float* _obj) {
|
||||
if (_obj == nullptr) {
|
||||
identity();
|
||||
return;
|
||||
@ -61,14 +61,14 @@ etk::Matrix4::Matrix4(float* _obj) {
|
||||
}
|
||||
}
|
||||
|
||||
const etk::Matrix4& etk::Matrix4::operator= (const etk::Matrix4& _obj ) {
|
||||
const etk::Matrix4x4& etk::Matrix4x4::operator= (const etk::Matrix4x4& _obj ) {
|
||||
for(int32_t iii=0; iii<4*4 ; ++iii) {
|
||||
m_mat[iii] = _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool etk::Matrix4::operator== (const etk::Matrix4& _obj) const {
|
||||
bool etk::Matrix4x4::operator== (const etk::Matrix4x4& _obj) const {
|
||||
for(int32_t iii=0; iii<4*4 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return false;
|
||||
@ -77,7 +77,7 @@ bool etk::Matrix4::operator== (const etk::Matrix4& _obj) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::Matrix4::operator!= (const etk::Matrix4& _obj) const {
|
||||
bool etk::Matrix4x4::operator!= (const etk::Matrix4x4& _obj) const {
|
||||
for(int32_t iii=0; iii<4*4 ; ++iii) {
|
||||
if(m_mat[iii] != _obj.m_mat[iii]) {
|
||||
return true;
|
||||
@ -86,33 +86,33 @@ bool etk::Matrix4::operator!= (const etk::Matrix4& _obj) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const etk::Matrix4& etk::Matrix4::operator+= (const etk::Matrix4& _obj) {
|
||||
const etk::Matrix4x4& etk::Matrix4x4::operator+= (const etk::Matrix4x4& _obj) {
|
||||
for(int32_t iii=0; iii<4*4 ; ++iii) {
|
||||
m_mat[iii] += _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::Matrix4::operator+ (const etk::Matrix4& _obj) const {
|
||||
etk::Matrix4 tmpp(*this);
|
||||
etk::Matrix4x4 etk::Matrix4x4::operator+ (const etk::Matrix4x4& _obj) const {
|
||||
etk::Matrix4x4 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix4& etk::Matrix4::operator-= (const etk::Matrix4& _obj) {
|
||||
const etk::Matrix4x4& etk::Matrix4x4::operator-= (const etk::Matrix4x4& _obj) {
|
||||
for(int32_t iii=0; iii<4*4 ; ++iii) {
|
||||
m_mat[iii] -= _obj.m_mat[iii];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::Matrix4::operator- (const etk::Matrix4& _obj) const {
|
||||
etk::Matrix4 tmpp(*this);
|
||||
etk::Matrix4x4 etk::Matrix4x4::operator- (const etk::Matrix4x4& _obj) const {
|
||||
etk::Matrix4x4 tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
const etk::Matrix4& etk::Matrix4::operator*= (const etk::Matrix4& _obj) {
|
||||
const etk::Matrix4x4& etk::Matrix4x4::operator*= (const etk::Matrix4x4& _obj) {
|
||||
// output Matrix
|
||||
float matrixOut[4*4];
|
||||
for(int32_t jjj=0; jjj<4 ; jjj++) {
|
||||
@ -136,19 +136,19 @@ const etk::Matrix4& etk::Matrix4::operator*= (const etk::Matrix4& _obj) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::Matrix4::operator* (const etk::Matrix4& _obj) const {
|
||||
etk::Matrix4 tmpp(*this);
|
||||
etk::Matrix4x4 etk::Matrix4x4::operator* (const etk::Matrix4x4& _obj) const {
|
||||
etk::Matrix4x4 tmpp(*this);
|
||||
tmpp *= _obj;
|
||||
return tmpp;
|
||||
}
|
||||
|
||||
vec3 etk::Matrix4::operator*(const vec3& _point) const {
|
||||
vec3 etk::Matrix4x4::operator*(const vec3& _point) const {
|
||||
return vec3( m_mat[0]*_point.x() + m_mat[1]*_point.y() + m_mat[2]*_point.z() + m_mat[3],
|
||||
m_mat[4]*_point.x() + m_mat[5]*_point.y() + m_mat[6]*_point.z() + m_mat[7],
|
||||
m_mat[8]*_point.x() + m_mat[9]*_point.y() + m_mat[10]*_point.z() + m_mat[11] );
|
||||
}
|
||||
|
||||
void etk::Matrix4::transpose() {
|
||||
void etk::Matrix4x4::transpose() {
|
||||
float tmpVal = m_mat[1];
|
||||
m_mat[1] = m_mat[4];
|
||||
m_mat[4] = tmpVal;
|
||||
@ -174,29 +174,29 @@ void etk::Matrix4::transpose() {
|
||||
m_mat[14] = tmpVal;
|
||||
}
|
||||
|
||||
void etk::Matrix4::scale(const vec3& _vect) {
|
||||
void etk::Matrix4x4::scale(const vec3& _vect) {
|
||||
scale(_vect.x(), _vect.y(), _vect.z());
|
||||
}
|
||||
|
||||
void etk::Matrix4::scale(float _sx, float _sy, float _sz) {
|
||||
void etk::Matrix4x4::scale(float _sx, float _sy, float _sz) {
|
||||
m_mat[0] *= _sx; m_mat[1] *= _sy; m_mat[2] *= _sz;
|
||||
m_mat[4] *= _sx; m_mat[5] *= _sy; m_mat[6] *= _sz;
|
||||
m_mat[8] *= _sx; m_mat[9] *= _sy; m_mat[10] *= _sz;
|
||||
}
|
||||
|
||||
void etk::Matrix4::rotate(const vec3& _vect, float _angleRad) {
|
||||
etk::Matrix4 tmpMat = etk::matRotate(_vect, _angleRad);
|
||||
void etk::Matrix4x4::rotate(const vec3& _vect, float _angleRad) {
|
||||
etk::Matrix4x4 tmpMat = etk::matRotate(_vect, _angleRad);
|
||||
*this *= tmpMat;
|
||||
}
|
||||
|
||||
void etk::Matrix4::translate(const vec3& _vect) {
|
||||
etk::Matrix4 tmpMat = etk::matTranslate(_vect);
|
||||
void etk::Matrix4x4::translate(const vec3& _vect) {
|
||||
etk::Matrix4x4 tmpMat = etk::matTranslate(_vect);
|
||||
*this *= tmpMat;
|
||||
}
|
||||
|
||||
|
||||
etk::Matrix4 etk::matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar) {
|
||||
etk::Matrix4 tmp;
|
||||
etk::Matrix4x4 etk::matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar) {
|
||||
etk::Matrix4x4 tmp;
|
||||
for(int32_t iii=0; iii<4*4 ; iii++) {
|
||||
tmp.m_mat[iii] = 0;
|
||||
}
|
||||
@ -214,7 +214,7 @@ etk::Matrix4 etk::matFrustum(float _xmin, float _xmax, float _ymin, float _ymax,
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matPerspective(float _fovx, float _aspect, float _zNear, float _zFar) {
|
||||
etk::Matrix4x4 etk::matPerspective(float _fovx, float _aspect, float _zNear, float _zFar) {
|
||||
//TK_DEBUG("drax perspective: fovx=" << fovx << "->" << aspect << " " << zNear << "->" << zFar);
|
||||
float xmax = _zNear * tanf(_fovx/2.0);
|
||||
float xmin = -xmax;
|
||||
@ -225,8 +225,8 @@ etk::Matrix4 etk::matPerspective(float _fovx, float _aspect, float _zNear, float
|
||||
return etk::matFrustum(xmin, xmax, ymin, ymax, _zNear, _zFar);
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal) {
|
||||
etk::Matrix4 tmp;
|
||||
etk::Matrix4x4 etk::matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal) {
|
||||
etk::Matrix4x4 tmp;
|
||||
for(int32_t iii=0; iii<4*4 ; iii++) {
|
||||
tmp.m_mat[iii] = 0;
|
||||
}
|
||||
@ -240,8 +240,8 @@ etk::Matrix4 etk::matOrtho(float _left, float _right, float _bottom, float _top,
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matTranslate(vec3 _vect) {
|
||||
etk::Matrix4 tmp;
|
||||
etk::Matrix4x4 etk::matTranslate(vec3 _vect) {
|
||||
etk::Matrix4x4 tmp;
|
||||
// set translation :
|
||||
tmp.m_mat[3] = _vect.x();
|
||||
tmp.m_mat[7] = _vect.y();
|
||||
@ -251,8 +251,8 @@ etk::Matrix4 etk::matTranslate(vec3 _vect) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matScale(vec3 _vect) {
|
||||
etk::Matrix4 tmp;
|
||||
etk::Matrix4x4 etk::matScale(vec3 _vect) {
|
||||
etk::Matrix4x4 tmp;
|
||||
tmp.scale(_vect);
|
||||
/*
|
||||
// set scale :
|
||||
@ -265,8 +265,8 @@ etk::Matrix4 etk::matScale(vec3 _vect) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matRotate(vec3 _vect, float _angleRad) {
|
||||
etk::Matrix4 tmp;
|
||||
etk::Matrix4x4 etk::matRotate(vec3 _vect, float _angleRad) {
|
||||
etk::Matrix4x4 tmp;
|
||||
float cosVal = cos(_angleRad);
|
||||
float sinVal = sin(_angleRad);
|
||||
float invVal = 1.0-cosVal;
|
||||
@ -285,14 +285,14 @@ etk::Matrix4 etk::matRotate(vec3 _vect, float _angleRad) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matRotate2(vec3 _vect) {
|
||||
etk::Matrix4x4 etk::matRotate2(vec3 _vect) {
|
||||
return matLookAt(_vect, vec3(0,0,0), vec3(0,1,0));
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matLookAt(const vec3& _eye,
|
||||
etk::Matrix4x4 etk::matLookAt(const vec3& _eye,
|
||||
const vec3& _target,
|
||||
const vec3& _up) {
|
||||
etk::Matrix4 tmp;
|
||||
etk::Matrix4x4 tmp;
|
||||
|
||||
vec3 forward = _eye;
|
||||
forward -= _target;
|
||||
@ -325,7 +325,7 @@ etk::Matrix4 etk::matLookAt(const vec3& _eye,
|
||||
}
|
||||
|
||||
|
||||
float etk::Matrix4::coFactor(int32_t _row, int32_t _col) const {
|
||||
float etk::Matrix4x4::coFactor(int32_t _row, int32_t _col) const {
|
||||
return ( ( m_mat[((_row+1)&3)*4 + ((_col+1)&3)] * m_mat[((_row+2)&3)*4 + ((_col+2)&3)] * m_mat[((_row+3)&3)*4 + ((_col+3)&3)]
|
||||
+ m_mat[((_row+1)&3)*4 + ((_col+2)&3)] * m_mat[((_row+2)&3)*4 + ((_col+3)&3)] * m_mat[((_row+3)&3)*4 + ((_col+1)&3)]
|
||||
+ m_mat[((_row+1)&3)*4 + ((_col+3)&3)] * m_mat[((_row+2)&3)*4 + ((_col+1)&3)] * m_mat[((_row+3)&3)*4 + ((_col+2)&3)] )
|
||||
@ -336,7 +336,7 @@ float etk::Matrix4::coFactor(int32_t _row, int32_t _col) const {
|
||||
}
|
||||
|
||||
|
||||
float etk::Matrix4::determinant() const {
|
||||
float etk::Matrix4x4::determinant() const {
|
||||
return m_mat[0] * coFactor(0, 0) +
|
||||
m_mat[1] * coFactor(0, 1) +
|
||||
m_mat[2] * coFactor(0, 2) +
|
||||
@ -344,13 +344,13 @@ float etk::Matrix4::determinant() const {
|
||||
}
|
||||
|
||||
|
||||
etk::Matrix4 etk::Matrix4::invert() {
|
||||
etk::Matrix4x4 etk::Matrix4x4::invert() {
|
||||
float det = determinant();
|
||||
if(std::abs(det) < (1.0e-7f)) {
|
||||
// The matrix is not invertible! Singular case!
|
||||
return *this;
|
||||
}
|
||||
etk::Matrix4 temp;
|
||||
etk::Matrix4x4 temp;
|
||||
float iDet = 1.0f / det;
|
||||
temp.m_mat[0] = coFactor(0,0) * iDet;
|
||||
temp.m_mat[1] = coFactor(0,1) * iDet;
|
||||
@ -372,7 +372,7 @@ etk::Matrix4 etk::Matrix4::invert() {
|
||||
}
|
||||
|
||||
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix4& _obj) {
|
||||
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix4x4& _obj) {
|
||||
_os << "matrix4 : (";
|
||||
for (int32_t iii=0; iii<16; iii++) {
|
||||
_os << _obj.m_mat[iii];
|
@ -34,7 +34,7 @@ namespace etk {
|
||||
/**
|
||||
* @brief This class represents a 4x4 matrix.
|
||||
*/
|
||||
class Matrix4 {
|
||||
class Matrix4x4 {
|
||||
public:
|
||||
float m_mat[4*4]; //!< matrix data
|
||||
public:
|
||||
@ -45,12 +45,12 @@ namespace etk {
|
||||
/**
|
||||
* @brief Constructor that load identity
|
||||
*/
|
||||
Matrix4();
|
||||
Matrix4x4();
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
* @param[in] _obj Matrix object to copy
|
||||
*/
|
||||
Matrix4(const Matrix4& _obj);
|
||||
Matrix4x4(const Matrix4x4& _obj);
|
||||
/**
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _a1 1st colomn, 1 line value
|
||||
@ -70,7 +70,7 @@ namespace etk {
|
||||
* @param[in] _c4 3rd colomn, 4 line value
|
||||
* @param[in] _d4 4th colomn, 4 line value
|
||||
*/
|
||||
Matrix4(float _a1, float _b1, float _c1, float _d1,
|
||||
Matrix4x4(float _a1, float _b1, float _c1, float _d1,
|
||||
float _a2, float _b2, float _c2, float _d2,
|
||||
float _a3, float _b3, float _c3, float _d3,
|
||||
float _a4, float _b4, float _c4, float _d4);
|
||||
@ -78,63 +78,63 @@ namespace etk {
|
||||
* @brief Configuration constructor.
|
||||
* @param[in] _values vector of values
|
||||
*/
|
||||
Matrix4(float* _values);
|
||||
Matrix4x4(float* _values);
|
||||
/**
|
||||
* @brief Operator= Asign the current object with an other object
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector asigned
|
||||
*/
|
||||
const Matrix4& operator= (const Matrix4& _obj);
|
||||
const Matrix4x4& operator= (const Matrix4x4& _obj);
|
||||
/**
|
||||
* @brief Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are identical
|
||||
* @return false The Objects are NOT identical
|
||||
*/
|
||||
bool operator== (const Matrix4& _obj) const;
|
||||
bool operator== (const Matrix4x4& _obj) const;
|
||||
/**
|
||||
* @brief In-Equality compare operator with an other object.
|
||||
* @param[in] _obj Reference on the comparing object
|
||||
* @return true The Objects are NOT identical
|
||||
* @return false The Objects are identical
|
||||
*/
|
||||
bool operator!= (const Matrix4& _obj) const;
|
||||
bool operator!= (const Matrix4x4& _obj) const;
|
||||
/**
|
||||
* @brief Operator+= Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector additionned
|
||||
*/
|
||||
const Matrix4& operator+= (const Matrix4& _obj);
|
||||
const Matrix4x4& operator+= (const Matrix4x4& _obj);
|
||||
/**
|
||||
* @brief Operator+ Addition an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix4 operator+ (const Matrix4& _obj) const;
|
||||
Matrix4x4 operator+ (const Matrix4x4& _obj) const;
|
||||
/**
|
||||
* @brief Operator-= Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector decremented
|
||||
*/
|
||||
const Matrix4& operator-= (const Matrix4& _obj);
|
||||
const Matrix4x4& operator-= (const Matrix4x4& _obj);
|
||||
/**
|
||||
* @brief Operator- Decrement an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix4 operator- (const Matrix4& _obj) const;
|
||||
Matrix4x4 operator- (const Matrix4x4& _obj) const;
|
||||
/**
|
||||
* @brief Operator*= Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector multiplicated
|
||||
*/
|
||||
const Matrix4& operator*= (const Matrix4& _obj);
|
||||
const Matrix4x4& operator*= (const Matrix4x4& _obj);
|
||||
/**
|
||||
* @brief Operator* Multiplication an other matrix with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
Matrix4 operator* (const Matrix4& _obj) const;
|
||||
Matrix4x4 operator* (const Matrix4x4& _obj) const;
|
||||
/**
|
||||
* @brief Operator* apply matrix on a vector
|
||||
* @param[in] _point Point value to apply the matrix
|
||||
@ -185,7 +185,7 @@ namespace etk {
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
* @return The inverted matrix.
|
||||
*/
|
||||
Matrix4 invert();
|
||||
Matrix4x4 invert();
|
||||
};
|
||||
/**
|
||||
* @brief Create projection matrix with the box parameter (camera view in -z axis)
|
||||
@ -197,7 +197,7 @@ namespace etk {
|
||||
* @param[in] _zFar Z maximum size of the frustum
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar);
|
||||
Matrix4x4 matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar);
|
||||
/**
|
||||
* @brief Create projection matrix with human repensentation view (camera view in -z axis)
|
||||
* @param[in] _foxy Focal in radian of the camera
|
||||
@ -206,7 +206,7 @@ namespace etk {
|
||||
* @param[in] _zFar Z far size of the camera
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matPerspective(float _foxy, float _aspect, float _zNear, float _zFar);
|
||||
Matrix4x4 matPerspective(float _foxy, float _aspect, float _zNear, float _zFar);
|
||||
/**
|
||||
* @brief Create orthogonal projection matrix with the box parameter (camera view in -z axis)
|
||||
* @param[in] _left left size of the camera
|
||||
@ -217,28 +217,28 @@ namespace etk {
|
||||
* @param[in] _farVal Z far size of the camera
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal);
|
||||
Matrix4x4 matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal);
|
||||
/**
|
||||
* @brief Create a matrix 3D with a simple translation
|
||||
* @param[in] _translate 3 dimention translation
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matTranslate(vec3 _translate);
|
||||
Matrix4x4 matTranslate(vec3 _translate);
|
||||
/**
|
||||
* @brief Create a matrix 3D with a simple scale
|
||||
* @param[in] _scale 3 dimention scale
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matScale(vec3 _scale);
|
||||
Matrix4x4 matScale(vec3 _scale);
|
||||
/**
|
||||
* @brief Create a matrix 3D with a simple rotation
|
||||
* @param[in] _normal vector aroud witch apply the rotation
|
||||
* @param[in] _angleRad Radian angle to set at the matrix
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matRotate(vec3 _normal, float _angleRad=0.0);
|
||||
Matrix4x4 matRotate(vec3 _normal, float _angleRad=0.0);
|
||||
//! @not_in_doc
|
||||
Matrix4 matRotate2(vec3 _vect);
|
||||
Matrix4x4 matRotate2(vec3 _vect);
|
||||
/**
|
||||
* @brief Create projection matrix with camera property (camera view in -z axis)
|
||||
* @param[in] _eye Optical center of the camera
|
||||
@ -246,14 +246,14 @@ namespace etk {
|
||||
* @param[in] _up Up vector of the camera
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
Matrix4 matLookAt(const vec3& _eye,
|
||||
Matrix4x4 matLookAt(const vec3& _eye,
|
||||
const vec3& _target,
|
||||
const vec3& _up);
|
||||
//! @not_in_doc
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix4& _obj);
|
||||
std::ostream& operator <<(std::ostream& _os, const etk::Matrix4x4& _obj);
|
||||
};
|
||||
|
||||
|
||||
// To siplify the writing of the code ==> this permit to have the same name with the glsl language...
|
||||
using mat4 = etk::Matrix4; //!< Matrix naming like openGl shader
|
||||
using mat4 = etk::Matrix4x4; //!< Matrix naming like openGl shader
|
||||
|
@ -19,7 +19,7 @@ std::ostream& etk::operator <<(std::ostream &_os, const etk::Quaternion& _obj) {
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::Quaternion::Quaternion(const etk::Matrix3& _matrix) {
|
||||
etk::Quaternion::Quaternion(const etk::Matrix3x3& _matrix) {
|
||||
float trace = _matrix.getTrace();
|
||||
if (trace < 0.0f) {
|
||||
if (_matrix.m_mat[4] > _matrix.m_mat[0]) {
|
||||
@ -71,7 +71,7 @@ void etk::Quaternion::getAngleAxis(float& _angle, vec3& _axis) const {
|
||||
_axis.setValue(rotationAxis.x(), rotationAxis.y(), rotationAxis.z());
|
||||
}
|
||||
|
||||
etk::Matrix3 etk::Quaternion::getMatrix() const {
|
||||
etk::Matrix3x3 etk::Quaternion::getMatrix() const {
|
||||
float nQ = m_floats[0]*m_floats[0]
|
||||
+ m_floats[1]*m_floats[1]
|
||||
+ m_floats[2]*m_floats[2]
|
||||
@ -92,7 +92,7 @@ etk::Matrix3 etk::Quaternion::getMatrix() const {
|
||||
float yys = m_floats[1]*ys;
|
||||
float yzs = m_floats[1]*zs;
|
||||
float zzs = m_floats[2]*zs;
|
||||
return etk::Matrix3(1.0f - yys - zzs,
|
||||
return etk::Matrix3x3(1.0f - yys - zzs,
|
||||
xys - wzs,
|
||||
xzs + wys,
|
||||
xys + wzs,
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <etk/types.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <etk/math/Matrix3.hpp>
|
||||
#include <etk/math/Matrix3x3.hpp>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
|
||||
namespace etk {
|
||||
@ -63,7 +63,7 @@ namespace etk {
|
||||
* @brief Create a unit quaternion from a rotation matrix
|
||||
* @param _matrix generic matrix
|
||||
*/
|
||||
Quaternion(const etk::Matrix3& _matrix);
|
||||
Quaternion(const etk::Matrix3x3& _matrix);
|
||||
/**
|
||||
* @brief Add a vector to this one.
|
||||
* @param[in] _obj The vector to add to this one
|
||||
@ -527,7 +527,7 @@ namespace etk {
|
||||
* @brief Get the orientation matrix corresponding to this quaternion
|
||||
* @return the 3x3 transformation matrix
|
||||
*/
|
||||
etk::Matrix3 getMatrix() const;
|
||||
etk::Matrix3x3 getMatrix() const;
|
||||
/**
|
||||
* @brief Compute the spherical linear interpolation between two quaternions.
|
||||
* @param[in] _obj1 First quaternion
|
||||
|
@ -15,24 +15,24 @@ namespace etk {
|
||||
/**
|
||||
* @brief This class represents a position and an orientation in 3D. It can also be seen as representing a translation and a rotation.
|
||||
*/
|
||||
class Transform {
|
||||
class Transform3D {
|
||||
public:
|
||||
Transform():
|
||||
Transform3D():
|
||||
m_position(vec3(0.0, 0.0, 0.0)),
|
||||
m_orientation(Quaternion::identity()) {
|
||||
|
||||
}
|
||||
Transform(const vec3& _position, const Matrix3x3& _orientation):
|
||||
Transform3D(const vec3& _position, const Matrix3x3& _orientation):
|
||||
m_position(_position),
|
||||
m_orientation(Quaternion(_orientation)) {
|
||||
|
||||
}
|
||||
Transform(const vec3& _position, const Quaternion& _orientation):
|
||||
Transform3D(const vec3& _position, const Quaternion& _orientation):
|
||||
m_position(_position),
|
||||
m_orientation(_orientation) {
|
||||
|
||||
}
|
||||
Transform(const Transform& _other):
|
||||
Transform3D(const Transform3D& _other):
|
||||
m_position(_other.m_position),
|
||||
m_orientation(_other.m_orientation) {
|
||||
|
||||
@ -60,7 +60,7 @@ namespace etk {
|
||||
m_orientation = _orientation;
|
||||
}
|
||||
public:
|
||||
/// Set the transform to the identity transform
|
||||
/// Set the Transform3D to the identity transform
|
||||
void setToIdentity() {
|
||||
m_position = vec3(0.0, 0.0, 0.0);
|
||||
m_orientation = Quaternion::identity();
|
||||
@ -94,45 +94,45 @@ namespace etk {
|
||||
_matrix[15] = 1.0;
|
||||
}
|
||||
/// Return the inverse of the transform
|
||||
Transform getInverse() const {
|
||||
Transform3D getInverse() const {
|
||||
const Quaternion& invQuaternion = m_orientation.getInverse();
|
||||
Matrix3x3 invMatrix = invQuaternion.getMatrix();
|
||||
return Transform(invMatrix * (-m_position), invQuaternion);
|
||||
return Transform3D(invMatrix * (-m_position), invQuaternion);
|
||||
}
|
||||
/// Return an interpolated transform
|
||||
Transform interpolateTransforms(const Transform& _old,
|
||||
const Transform& _new,
|
||||
Transform3D interpolateTransforms(const Transform3D& _old,
|
||||
const Transform3D& _new,
|
||||
float _interpolationFactor) {
|
||||
vec3 interPosition = _old.m_position * (decimal(1.0) - _interpolationFactor) +
|
||||
_new.m_position * _interpolationFactor;
|
||||
Quaternion interOrientation = Quaternion::slerp(_old.m_orientation,
|
||||
_naw.m_orientation,
|
||||
_interpolationFactor);
|
||||
return Transform(interPosition, interOrientation);
|
||||
return Transform3D(interPosition, interOrientation);
|
||||
}
|
||||
/// Return the identity transform
|
||||
Transform identity() {
|
||||
return Transform(vec3(0, 0, 0), Quaternion::identity());
|
||||
Transform3D identity() {
|
||||
return Transform3D(vec3(0, 0, 0), Quaternion::identity());
|
||||
}
|
||||
/// Return the transformed vector
|
||||
vec3 operator*(const vec3& _vector) const {
|
||||
return (m_orientation.getMatrix() * _vector) + m_position;
|
||||
}
|
||||
/// Operator of multiplication of a transform with another one
|
||||
Transform operator*(const Transform& _transform2) const {
|
||||
return Transform(m_position + m_orientation.getMatrix() * _transform2.m_position,
|
||||
Transform3D operator*(const Transform3D& _transform2) const {
|
||||
return Transform3D(m_position + m_orientation.getMatrix() * _transform2.m_position,
|
||||
m_orientation * _transform2.m_orientation);
|
||||
}
|
||||
/// Return true if the two transforms are equal
|
||||
bool operator==(const Transform& _transform2) const {
|
||||
bool operator==(const Transform3D& _transform2) const {
|
||||
return (m_position == _transform2.m_position) && (m_orientation == _transform2.m_orientation);
|
||||
}
|
||||
/// Return true if the two transforms are different
|
||||
bool operator!=(const Transform& _transform2) const {
|
||||
bool operator!=(const Transform3D& _transform2) const {
|
||||
return !(*this == _transform2);
|
||||
}
|
||||
/// Assignment operator
|
||||
Transform& operator=(const Transform& _transform) {
|
||||
Transform3D& operator=(const Transform3D& _transform) {
|
||||
if (&_transform != this) {
|
||||
m_position = _transform.m_position;
|
||||
m_orientation = _transform.m_orientation;
|
18
lutin_etk.py
18
lutin_etk.py
@ -35,14 +35,15 @@ def configure(target, my_module):
|
||||
'etk/Noise.cpp',
|
||||
'etk/Color.cpp',
|
||||
'etk/RegExp.cpp',
|
||||
'etk/math/Matrix2.cpp',
|
||||
'etk/math/Matrix3.cpp',
|
||||
'etk/math/Matrix4.cpp',
|
||||
'etk/math/Matrix2x2.cpp',
|
||||
'etk/math/Matrix2x3.cpp',
|
||||
'etk/math/Matrix3x3.cpp',
|
||||
'etk/math/Matrix4x4.cpp',
|
||||
'etk/math/Vector2D.cpp',
|
||||
'etk/math/Vector3D.cpp',
|
||||
'etk/math/Vector4D.cpp',
|
||||
'etk/math/Quaternion.cpp',
|
||||
'etk/math/Transform.cpp',
|
||||
'etk/math/Transform3D.cpp',
|
||||
'etk/os/FSNode.cpp',
|
||||
'etk/os/FSNodeRight.cpp',
|
||||
'etk/archive/Archive.cpp',
|
||||
@ -59,14 +60,15 @@ def configure(target, my_module):
|
||||
'etk/RegExp.hpp',
|
||||
'etk/Buffer.hpp',
|
||||
'etk/Hash.hpp',
|
||||
'etk/math/Matrix2.hpp',
|
||||
'etk/math/Matrix3.hpp',
|
||||
'etk/math/Matrix4.hpp',
|
||||
'etk/math/Matrix2x2.hpp',
|
||||
'etk/math/Matrix2x3.hpp',
|
||||
'etk/math/Matrix3x3.hpp',
|
||||
'etk/math/Matrix4x4.hpp',
|
||||
'etk/math/Vector2D.hpp',
|
||||
'etk/math/Vector3D.hpp',
|
||||
'etk/math/Vector4D.hpp',
|
||||
'etk/math/Quaternion.hpp',
|
||||
'etk/math/Transform.hpp',
|
||||
'etk/math/Transform3D.hpp',
|
||||
'etk/os/Fifo.hpp',
|
||||
'etk/os/FSNode.hpp',
|
||||
'etk/os/FSNodeRight.hpp',
|
||||
|
@ -7,29 +7,29 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etk/math/Matrix2.hpp>
|
||||
#include <etk/math/Matrix2x2.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
|
||||
#define NAME "etk::Matrix2x2"
|
||||
|
||||
TEST(TestMatrix2x2, constructor) {
|
||||
// Test contructor value
|
||||
etk::Matrix2 test1(99.0);
|
||||
etk::Matrix2x2 test1(99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[2], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[3], 99.0);
|
||||
etk::Matrix2 test2(11,22,33,44);
|
||||
etk::Matrix2x2 test2(11,22,33,44);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[0], 11.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[1], 22.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[2], 33.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[3], 44.0);
|
||||
etk::Matrix2 test3(test2);
|
||||
etk::Matrix2x2 test3(test2);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[0], 11.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[1], 22.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[2], 33.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[3], 44.0);
|
||||
etk::Matrix2 test4 = test1;
|
||||
etk::Matrix2x2 test4 = test1;
|
||||
EXPECT_FLOAT_EQ(test4.m_mat[0], 99.0);
|
||||
EXPECT_FLOAT_EQ(test4.m_mat[1], 99.0);
|
||||
EXPECT_FLOAT_EQ(test4.m_mat[2], 99.0);
|
||||
@ -42,9 +42,9 @@ TEST(TestMatrix2x2, constructor) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, equity) {
|
||||
etk::Matrix2 test1(99,32,56,92);
|
||||
etk::Matrix2 test2(11,22,33,44);
|
||||
etk::Matrix2 test3(11,22,33,44);
|
||||
etk::Matrix2x2 test1(99,32,56,92);
|
||||
etk::Matrix2x2 test2(11,22,33,44);
|
||||
etk::Matrix2x2 test3(11,22,33,44);
|
||||
EXPECT_EQ(test1 == test2, false);
|
||||
EXPECT_EQ(test1 != test2, true);
|
||||
EXPECT_EQ(test3 == test2, true);
|
||||
@ -52,7 +52,7 @@ TEST(TestMatrix2x2, equity) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, set) {
|
||||
etk::Matrix2 test;
|
||||
etk::Matrix2x2 test;
|
||||
test.setValue(22, 54, 45, 985);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 22.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 54.0);
|
||||
@ -68,12 +68,12 @@ TEST(TestMatrix2x2, set) {
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[2], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[3], 1.0);
|
||||
test = etk::Matrix2::zero();
|
||||
test = etk::Matrix2x2::zero();
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[2], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[3], 0.0);
|
||||
test = etk::Matrix2::identity();
|
||||
test = etk::Matrix2x2::identity();
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 1.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[2], 0.0);
|
||||
@ -81,7 +81,7 @@ TEST(TestMatrix2x2, set) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, getRowColomn) {
|
||||
etk::Matrix2 test(11, 22, 33, 44);
|
||||
etk::Matrix2x2 test(11, 22, 33, 44);
|
||||
EXPECT_FLOAT_EQ(test.getColumn(0).x(), 11.0);
|
||||
EXPECT_FLOAT_EQ(test.getColumn(0).y(), 33.0);
|
||||
EXPECT_FLOAT_EQ(test.getColumn(1).x(), 22.0);
|
||||
@ -97,8 +97,8 @@ TEST(TestMatrix2x2, getRowColomn) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, transpose) {
|
||||
etk::Matrix2 test(11, 22, 33, 44);
|
||||
etk::Matrix2 test2 = test.getTranspose();
|
||||
etk::Matrix2x2 test(11, 22, 33, 44);
|
||||
etk::Matrix2x2 test2 = test.getTranspose();
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[0], 11.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[1], 33.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[2], 22.0);
|
||||
@ -116,19 +116,19 @@ TEST(TestMatrix2x2, transpose) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, determinant) {
|
||||
etk::Matrix2 test(11, 22, 33, 44);
|
||||
etk::Matrix2x2 test(11, 22, 33, 44);
|
||||
EXPECT_FLOAT_EQ(test.determinant(), -242.0);
|
||||
EXPECT_FLOAT_EQ(etk::Matrix2::identity().determinant(), 1.0);
|
||||
EXPECT_FLOAT_EQ(etk::Matrix2x2::identity().determinant(), 1.0);
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, trace) {
|
||||
etk::Matrix2 test(11, 22, 33, 44);
|
||||
etk::Matrix2x2 test(11, 22, 33, 44);
|
||||
EXPECT_FLOAT_EQ(test.getTrace(), 55.0);
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, inverse) {
|
||||
etk::Matrix2 test(1, 2, 3, 4);
|
||||
etk::Matrix2 test2 = test.getInverse();
|
||||
etk::Matrix2x2 test(1, 2, 3, 4);
|
||||
etk::Matrix2x2 test2 = test.getInverse();
|
||||
// check if original matrix is not inversed
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 1.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 2.0);
|
||||
@ -146,8 +146,8 @@ TEST(TestMatrix2x2, inverse) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, absolute) {
|
||||
etk::Matrix2 test(-1, -2, -3, -4);
|
||||
etk::Matrix2 test2 = test.getAbsolute();
|
||||
etk::Matrix2x2 test(-1, -2, -3, -4);
|
||||
etk::Matrix2x2 test2 = test.getAbsolute();
|
||||
// check if original matrix is not inversed
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], -2.0);
|
||||
@ -165,9 +165,9 @@ TEST(TestMatrix2x2, absolute) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, operatorAddition) {
|
||||
etk::Matrix2 test1(-1, -2, -3, -4);
|
||||
etk::Matrix2 test2(1, 2, 3, 4);
|
||||
etk::Matrix2 test3 = test1 + test2;
|
||||
etk::Matrix2x2 test1(-1, -2, -3, -4);
|
||||
etk::Matrix2x2 test2(1, 2, 3, 4);
|
||||
etk::Matrix2x2 test3 = test1 + test2;
|
||||
// check no change
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
@ -190,9 +190,9 @@ TEST(TestMatrix2x2, operatorAddition) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, operatorSubstraction) {
|
||||
etk::Matrix2 test1(-1, -2, -3, -4);
|
||||
etk::Matrix2 test2(1, 2, 3, 4);
|
||||
etk::Matrix2 test3 = test1 - test2;
|
||||
etk::Matrix2x2 test1(-1, -2, -3, -4);
|
||||
etk::Matrix2x2 test2(1, 2, 3, 4);
|
||||
etk::Matrix2x2 test3 = test1 - test2;
|
||||
// check no change
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
@ -214,8 +214,8 @@ TEST(TestMatrix2x2, operatorSubstraction) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, operatorNegation) {
|
||||
etk::Matrix2 test1(-1, -2, -3, -4);
|
||||
etk::Matrix2 test2 = -test1;
|
||||
etk::Matrix2x2 test1(-1, -2, -3, -4);
|
||||
etk::Matrix2x2 test2 = -test1;
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[2], -3.0);
|
||||
@ -227,9 +227,9 @@ TEST(TestMatrix2x2, operatorNegation) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, operatorMultiplicationMatrix) {
|
||||
etk::Matrix2 test1(1, 2, 3, 4);
|
||||
etk::Matrix2 test2(5, 6, 7, 10);
|
||||
etk::Matrix2 test3 = test1 * test2;
|
||||
etk::Matrix2x2 test1(1, 2, 3, 4);
|
||||
etk::Matrix2x2 test2(5, 6, 7, 10);
|
||||
etk::Matrix2x2 test3 = test1 * test2;
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], 1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], 2.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[2], 3.0);
|
||||
@ -250,7 +250,7 @@ TEST(TestMatrix2x2, operatorMultiplicationMatrix) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix2x2, operatorMultiplicationVector) {
|
||||
etk::Matrix2 test1(1, 2, 3, 4);
|
||||
etk::Matrix2x2 test1(1, 2, 3, 4);
|
||||
vec2 result = test1 * vec2(1,2);
|
||||
EXPECT_FLOAT_EQ(result.x(), 5.0);
|
||||
EXPECT_FLOAT_EQ(result.y(), 11.0);
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
#include <etk/math/Matrix3.hpp>
|
||||
#include <etk/math/Matrix3x3.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
|
||||
#define NAME "etk::Matrix3"
|
||||
#define NAME "etk::Matrix3x3"
|
||||
|
||||
TEST(TestMatrix3x3, constructor) {
|
||||
// Test contructor value
|
||||
etk::Matrix3 test1(99.0);
|
||||
etk::Matrix3x3 test1(99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[2], 99.0);
|
||||
@ -25,7 +25,7 @@ TEST(TestMatrix3x3, constructor) {
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[6], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[7], 99.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[8], 99.0);
|
||||
etk::Matrix3 test2(11,22,33,44,55,66,77,88,99);
|
||||
etk::Matrix3x3 test2(11,22,33,44,55,66,77,88,99);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[0], 11.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[1], 22.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[2], 33.0);
|
||||
@ -35,7 +35,7 @@ TEST(TestMatrix3x3, constructor) {
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[6], 77.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[7], 88.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[8], 99.0);
|
||||
etk::Matrix3 test3(test2);
|
||||
etk::Matrix3x3 test3(test2);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[0], 11.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[1], 22.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[2], 33.0);
|
||||
@ -45,7 +45,7 @@ TEST(TestMatrix3x3, constructor) {
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[6], 77.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[7], 88.0);
|
||||
EXPECT_FLOAT_EQ(test3.m_mat[8], 99.0);
|
||||
etk::Matrix3 test4 = test1;
|
||||
etk::Matrix3x3 test4 = test1;
|
||||
EXPECT_FLOAT_EQ(test4.m_mat[0], 99.0);
|
||||
EXPECT_FLOAT_EQ(test4.m_mat[1], 99.0);
|
||||
EXPECT_FLOAT_EQ(test4.m_mat[2], 99.0);
|
||||
@ -68,9 +68,9 @@ TEST(TestMatrix3x3, constructor) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, equity) {
|
||||
etk::Matrix3 test1(99,32,56,92,56,32,45,12,54);
|
||||
etk::Matrix3 test2(11,22,33,44,55,66,77,88,99);
|
||||
etk::Matrix3 test3(11,22,33,44,55,66,77,88,99);
|
||||
etk::Matrix3x3 test1(99,32,56,92,56,32,45,12,54);
|
||||
etk::Matrix3x3 test2(11,22,33,44,55,66,77,88,99);
|
||||
etk::Matrix3x3 test3(11,22,33,44,55,66,77,88,99);
|
||||
EXPECT_EQ(test1 == test2, false);
|
||||
EXPECT_EQ(test1 != test2, true);
|
||||
EXPECT_EQ(test3 == test2, true);
|
||||
@ -78,7 +78,7 @@ TEST(TestMatrix3x3, equity) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, set) {
|
||||
etk::Matrix3 test;
|
||||
etk::Matrix3x3 test;
|
||||
test.setValue(22, 54, 45, 985, 54, 87, 98, 6532, -8652);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 22.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 54.0);
|
||||
@ -109,7 +109,7 @@ TEST(TestMatrix3x3, set) {
|
||||
EXPECT_FLOAT_EQ(test.m_mat[6], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[7], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[8], 1.0);
|
||||
test = etk::Matrix3::zero();
|
||||
test = etk::Matrix3x3::zero();
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[2], 0.0);
|
||||
@ -119,7 +119,7 @@ TEST(TestMatrix3x3, set) {
|
||||
EXPECT_FLOAT_EQ(test.m_mat[6], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[7], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[8], 0.0);
|
||||
test = etk::Matrix3::identity();
|
||||
test = etk::Matrix3x3::identity();
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 1.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], 0.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[2], 0.0);
|
||||
@ -132,7 +132,7 @@ TEST(TestMatrix3x3, set) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, getRowColomn) {
|
||||
etk::Matrix3 test(11, 22, 33, 44, 55, 66, 77, 88, 99);
|
||||
etk::Matrix3x3 test(11, 22, 33, 44, 55, 66, 77, 88, 99);
|
||||
EXPECT_FLOAT_EQ(test.getColumn(0).x(), 11.0);
|
||||
EXPECT_FLOAT_EQ(test.getColumn(0).y(), 44.0);
|
||||
EXPECT_FLOAT_EQ(test.getColumn(0).z(), 77.0);
|
||||
@ -160,8 +160,8 @@ TEST(TestMatrix3x3, getRowColomn) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, transpose) {
|
||||
etk::Matrix3 test(11, 22, 33, 44, 55, 66, 77, 88, 99);
|
||||
etk::Matrix3 test2 = test.getTranspose();
|
||||
etk::Matrix3x3 test(11, 22, 33, 44, 55, 66, 77, 88, 99);
|
||||
etk::Matrix3x3 test2 = test.getTranspose();
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[0], 11.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[1], 44.0);
|
||||
EXPECT_FLOAT_EQ(test2.m_mat[2], 77.0);
|
||||
@ -194,19 +194,19 @@ TEST(TestMatrix3x3, transpose) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, determinant) {
|
||||
etk::Matrix3 test(11, -6, 6, 4, -5, 1, 8, -9, -6);
|
||||
etk::Matrix3x3 test(11, -6, 6, 4, -5, 1, 8, -9, -6);
|
||||
EXPECT_FLOAT_EQ(test.determinant(), 261.0);
|
||||
EXPECT_FLOAT_EQ(etk::Matrix3::identity().determinant(), 1.0);
|
||||
EXPECT_FLOAT_EQ(etk::Matrix3x3::identity().determinant(), 1.0);
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, trace) {
|
||||
etk::Matrix3 test(11, 22, 33, 44, 55, 66, 77, 88, 99);
|
||||
etk::Matrix3x3 test(11, 22, 33, 44, 55, 66, 77, 88, 99);
|
||||
EXPECT_FLOAT_EQ(test.getTrace(), 165.0);
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, inverse) {
|
||||
etk::Matrix3 test(1, -4, 3, -6, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3 test2 = test.getInverse();
|
||||
etk::Matrix3x3 test(1, -4, 3, -6, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3x3 test2 = test.getInverse();
|
||||
// check if original matrix is not inversed
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], 1.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], -4.0);
|
||||
@ -239,8 +239,8 @@ TEST(TestMatrix3x3, inverse) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, absolute) {
|
||||
etk::Matrix3 test(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3 test2 = test.getAbsolute();
|
||||
etk::Matrix3x3 test(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3x3 test2 = test.getAbsolute();
|
||||
// check if original matrix is not inversed
|
||||
EXPECT_FLOAT_EQ(test.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test.m_mat[1], -2.0);
|
||||
@ -273,9 +273,9 @@ TEST(TestMatrix3x3, absolute) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, operatorAddition) {
|
||||
etk::Matrix3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3 test2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3 test3 = test1 + test2;
|
||||
etk::Matrix3x3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3x3 test2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3x3 test3 = test1 + test2;
|
||||
// check no change
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
@ -317,9 +317,9 @@ TEST(TestMatrix3x3, operatorAddition) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, operatorSubstraction) {
|
||||
etk::Matrix3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3 test2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3 test3 = test1 - test2;
|
||||
etk::Matrix3x3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3x3 test2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3x3 test3 = test1 - test2;
|
||||
// check no change
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
@ -361,8 +361,8 @@ TEST(TestMatrix3x3, operatorSubstraction) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, operatorNegation) {
|
||||
etk::Matrix3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3 test2 = -test1;
|
||||
etk::Matrix3x3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3x3 test2 = -test1;
|
||||
// check no change
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
@ -385,9 +385,9 @@ TEST(TestMatrix3x3, operatorNegation) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, operatorMultiplicationMatrix) {
|
||||
etk::Matrix3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3 test2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3 test3 = test1 * test2;
|
||||
etk::Matrix3x3 test1(-1, -2, -3, -4, -5, -6, -7, -8, -9);
|
||||
etk::Matrix3x3 test2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3x3 test3 = test1 * test2;
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[0], -1.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[1], -2.0);
|
||||
EXPECT_FLOAT_EQ(test1.m_mat[2], -3.0);
|
||||
@ -428,7 +428,7 @@ TEST(TestMatrix3x3, operatorMultiplicationMatrix) {
|
||||
}
|
||||
|
||||
TEST(TestMatrix3x3, operatorMultiplicationVector) {
|
||||
etk::Matrix3 test1(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
etk::Matrix3x3 test1(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
vec3 result = test1 * vec3(1,2,3);
|
||||
EXPECT_FLOAT_EQ(result.x(), 14.0);
|
||||
EXPECT_FLOAT_EQ(result.y(), 32.0);
|
||||
|
@ -16,7 +16,7 @@ TEST(TestQuaternion, constructor) {
|
||||
EXPECT_FLOAT_EQ(test0.y(), 2.0);
|
||||
EXPECT_FLOAT_EQ(test0.z(), 3.0);
|
||||
EXPECT_FLOAT_EQ(test0.w(), 4.0);
|
||||
etk::Quaternion test1(4, etk::Vector3D<float>(1,2,3));
|
||||
etk::Quaternion test1(4, vec3(1,2,3));
|
||||
EXPECT_FLOAT_EQ(test1.x(), 1.0);
|
||||
EXPECT_FLOAT_EQ(test1.y(), 2.0);
|
||||
EXPECT_FLOAT_EQ(test1.z(), 3.0);
|
||||
@ -53,7 +53,7 @@ TEST(TestQuaternion, constructorMatrix) {
|
||||
}
|
||||
|
||||
TEST(TestQuaternion, constructorEuler) {
|
||||
etk::Quaternion test0(etk::Vector3D<float>(M_PI*0.5f, 0, 0));
|
||||
etk::Quaternion test0(vec3(M_PI*0.5f, 0, 0));
|
||||
etk::Quaternion test01(std::sin(M_PI*0.25f), 0, 0, std::cos(M_PI*0.25f));
|
||||
test01.normalize();
|
||||
EXPECT_FLOAT_EQ(test0.x(), test01.x());
|
||||
@ -61,7 +61,7 @@ TEST(TestQuaternion, constructorEuler) {
|
||||
EXPECT_FLOAT_EQ(test0.z(), test01.z());
|
||||
EXPECT_FLOAT_EQ(test0.w(), test01.w());
|
||||
|
||||
etk::Quaternion test1(etk::Vector3D<float>(0, M_PI*0.5f, 0));
|
||||
etk::Quaternion test1(vec3(0, M_PI*0.5f, 0));
|
||||
etk::Quaternion test11(0, std::sin(M_PI*0.25f), 0, std::cos(M_PI*0.25f));
|
||||
test11.normalize();
|
||||
EXPECT_FLOAT_EQ(test1.x(), test11.x());
|
||||
@ -69,7 +69,7 @@ TEST(TestQuaternion, constructorEuler) {
|
||||
EXPECT_FLOAT_EQ(test1.z(), test11.z());
|
||||
EXPECT_FLOAT_EQ(test1.w(), test11.w());
|
||||
|
||||
etk::Quaternion test2(etk::Vector3D<float>(0, 0, M_PI*0.5f));
|
||||
etk::Quaternion test2(vec3(0, 0, M_PI*0.5f));
|
||||
etk::Quaternion test21(0, 0, std::sin(M_PI*0.25f), std::cos(M_PI*0.25f));
|
||||
test21.normalize();
|
||||
EXPECT_FLOAT_EQ(test2.x(), test21.x());
|
||||
@ -135,7 +135,7 @@ TEST(TestQuaternion, set) {
|
||||
|
||||
TEST(TestQuaternion, getVector) {
|
||||
etk::Quaternion test1(5, 3, 8, 2);
|
||||
etk::Vector3D<float> test2 = test1.getVectorV();
|
||||
vec3 test2 = test1.getVectorV();
|
||||
EXPECT_FLOAT_EQ(test2.x(), 5.0);
|
||||
EXPECT_FLOAT_EQ(test2.y(), 3.0);
|
||||
EXPECT_FLOAT_EQ(test2.z(), 8.0);
|
||||
|
@ -12,19 +12,19 @@
|
||||
|
||||
TEST(TestVector3D_f, constructor) {
|
||||
// Test contructor value
|
||||
etk::Vector3D<float> test0(0,0,0);
|
||||
vec3 test0(0,0,0);
|
||||
EXPECT_FLOAT_EQ(test0.x(), 0.0);
|
||||
EXPECT_FLOAT_EQ(test0.y(), 0.0);
|
||||
EXPECT_FLOAT_EQ(test0.z(), 0.0);
|
||||
etk::Vector3D<float> vect1(4,5,8);
|
||||
vec3 vect1(4,5,8);
|
||||
EXPECT_FLOAT_EQ(vect1.x(), 4.0);
|
||||
EXPECT_FLOAT_EQ(vect1.y(), 5.0);
|
||||
EXPECT_FLOAT_EQ(vect1.z(), 8.0);
|
||||
etk::Vector3D<float> vect2(vect1);
|
||||
vec3 vect2(vect1);
|
||||
EXPECT_FLOAT_EQ(vect2.x(), 4.0);
|
||||
EXPECT_FLOAT_EQ(vect2.y(), 5.0);
|
||||
EXPECT_FLOAT_EQ(vect2.z(), 8.0);
|
||||
etk::Vector3D<float> vect3 = vect1;
|
||||
vec3 vect3 = vect1;
|
||||
EXPECT_FLOAT_EQ(vect3.x(), 4.0);
|
||||
EXPECT_FLOAT_EQ(vect3.y(), 5.0);
|
||||
EXPECT_FLOAT_EQ(vect3.z(), 8.0);
|
||||
@ -35,9 +35,9 @@ TEST(TestVector3D_f, constructor) {
|
||||
}
|
||||
|
||||
TEST(TestVector3D_f, equity) {
|
||||
etk::Vector3D<float> test1(99,32,56);
|
||||
etk::Vector3D<float> test2(11,22,33);
|
||||
etk::Vector3D<float> test3(11,22,33);
|
||||
vec3 test1(99,32,56);
|
||||
vec3 test2(11,22,33);
|
||||
vec3 test3(11,22,33);
|
||||
EXPECT_EQ(test1 == test2, false);
|
||||
EXPECT_EQ(test1 != test2, true);
|
||||
EXPECT_EQ(test3 == test2, true);
|
||||
@ -46,7 +46,7 @@ TEST(TestVector3D_f, equity) {
|
||||
|
||||
TEST(TestVector3D_f, set) {
|
||||
// Test contructor value
|
||||
etk::Vector3D<float> test1(0,0,0);
|
||||
vec3 test1(0,0,0);
|
||||
EXPECT_FLOAT_EQ(test1.x(), 0.0);
|
||||
EXPECT_FLOAT_EQ(test1.y(), 0.0);
|
||||
EXPECT_FLOAT_EQ(test1.z(), 0.0);
|
||||
@ -58,7 +58,7 @@ TEST(TestVector3D_f, set) {
|
||||
|
||||
TEST(TestVector3D_f, setSetZero) {
|
||||
// Test contructor value
|
||||
etk::Vector3D<float> test1(4,5,6);
|
||||
vec3 test1(4,5,6);
|
||||
EXPECT_FLOAT_EQ(test1.x(), 4.0);
|
||||
EXPECT_FLOAT_EQ(test1.y(), 5.0);
|
||||
EXPECT_FLOAT_EQ(test1.z(), 6.0);
|
||||
@ -71,7 +71,7 @@ TEST(TestVector3D_f, setSetZero) {
|
||||
|
||||
TEST(TestVector3D_f, length) {
|
||||
// Test contructor value
|
||||
etk::Vector3D<float> test1(0,0,0);
|
||||
vec3 test1(0,0,0);
|
||||
EXPECT_FLOAT_EQ(test1.length(), 0.0);
|
||||
EXPECT_FLOAT_EQ(test1.length2(), 0.0);
|
||||
test1.setValue(2,0,0);
|
||||
@ -85,8 +85,8 @@ TEST(TestVector3D_f, length) {
|
||||
}
|
||||
|
||||
TEST(TestVector3D_f, normalize) {
|
||||
etk::Vector3D<float> test1(11,22,33);
|
||||
etk::Vector3D<float> test2 = test1.normalized();
|
||||
vec3 test1(11,22,33);
|
||||
vec3 test2 = test1.normalized();
|
||||
EXPECT_FLOAT_EQ(test1.x(), 11.0);
|
||||
EXPECT_FLOAT_EQ(test1.y(), 22.0);
|
||||
EXPECT_FLOAT_EQ(test1.z(), 33.0);
|
||||
@ -100,8 +100,8 @@ TEST(TestVector3D_f, normalize) {
|
||||
}
|
||||
|
||||
TEST(TestVector3D_f, dot) {
|
||||
etk::Vector3D<float> test1(11,0,0);
|
||||
etk::Vector3D<float> test2(0,88,66);
|
||||
vec3 test1(11,0,0);
|
||||
vec3 test2(0,88,66);
|
||||
EXPECT_FLOAT_EQ(test1.dot(test1), 121.0);
|
||||
EXPECT_FLOAT_EQ(test1.dot(test2), 0.0);
|
||||
test1.setValue(2,3,5);
|
||||
@ -110,8 +110,8 @@ TEST(TestVector3D_f, dot) {
|
||||
}
|
||||
|
||||
TEST(TestVector3D_f, cross) {
|
||||
etk::Vector3D<float> test1(0,0,0);
|
||||
etk::Vector3D<float> test2(-55,88,66);
|
||||
vec3 test1(0,0,0);
|
||||
vec3 test2(-55,88,66);
|
||||
EXPECT_EQ(test1.cross(test1), vec3(0,0,0));
|
||||
EXPECT_EQ(test2.cross(test2), vec3(0,0,0));
|
||||
test1.setValue(1,0,0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user