[DEBUG] some matrix and vector corections
This commit is contained in:
parent
df8a54b55a
commit
e3890a6c14
@ -12,6 +12,11 @@
|
||||
#include <math.h>
|
||||
|
||||
|
||||
void etk::Matrix4::Rotate(etk::Vector3D<float> vect, float angleRad)
|
||||
{
|
||||
etk::Matrix4 tmpMat = etk::matRotate(vect, angleRad);
|
||||
*this *= tmpMat;
|
||||
}
|
||||
|
||||
void etk::Matrix4::Rotate(etk::Vector3D<float>& vect, float angleRad)
|
||||
{
|
||||
@ -21,13 +26,41 @@ void etk::Matrix4::Rotate(etk::Vector3D<float>& vect, float angleRad)
|
||||
|
||||
void etk::Matrix4::Translate(etk::Vector3D<float>& vect)
|
||||
{
|
||||
etk::Matrix4 tmpMat = etk::matScale(vect);
|
||||
etk::Matrix4 tmpMat = etk::matTranslate(vect);
|
||||
*this *= tmpMat;
|
||||
}
|
||||
|
||||
|
||||
etk::Matrix4 etk::matPerspective(float fovx, float aspect, float zNear, float zFar)
|
||||
{
|
||||
etk::Matrix4 tmp;
|
||||
for(int32_t iii=0; iii<4*4 ; iii++) {
|
||||
tmp.m_mat[iii] = 0;
|
||||
}
|
||||
|
||||
float xmax = zNear * tanf(fovx * M_PI / 360.0);
|
||||
float xmin = -xmax;
|
||||
|
||||
float ymin = xmin / aspect;
|
||||
float ymax = xmax / aspect;
|
||||
|
||||
// 0 1 2 3
|
||||
// 4 5 6 7
|
||||
// 8 9 10 11
|
||||
// 12 13 14 15
|
||||
|
||||
tmp.m_mat[0] = (2.0 * zNear) / (xmax - xmin);
|
||||
tmp.m_mat[5] = (2.0 * zNear) / (ymax - ymin);
|
||||
tmp.m_mat[10] = -(zFar + zNear) / (zFar - zNear);
|
||||
tmp.m_mat[2] = (xmax + xmin) / (xmax - xmin);
|
||||
tmp.m_mat[6] = (ymax + ymin) / (ymax - ymin);
|
||||
tmp.m_mat[14] = -1.0;
|
||||
tmp.m_mat[11] = -(2.0 * zFar * zNear) / (zFar - zNear);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
etk::Matrix4 etk::matPerspective(float left, float right, float bottom, float top, float nearVal, float farVal)
|
||||
etk::Matrix4 etk::matOrtho(float left, float right, float bottom, float top, float nearVal, float farVal)
|
||||
{
|
||||
etk::Matrix4 tmp;
|
||||
for(int32_t iii=0; iii<4*4 ; iii++) {
|
||||
@ -40,8 +73,6 @@ etk::Matrix4 etk::matPerspective(float left, float right, float bottom, float to
|
||||
tmp.m_mat[7] = -1*(top + bottom) / (top - bottom);
|
||||
tmp.m_mat[11] = -1*(farVal + nearVal) / (farVal - nearVal);
|
||||
tmp.m_mat[15] = 1;
|
||||
//TK_INFO("Perspective :");
|
||||
//etk::matrix::Display(tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
@ -266,6 +266,7 @@ namespace etk
|
||||
* @param[in] angleRad angle to apply.
|
||||
*/
|
||||
void Rotate(etk::Vector3D<float>& vect, float angleRad=0.0);
|
||||
void Rotate(etk::Vector3D<float> vect, float angleRad=0.0);
|
||||
/**
|
||||
* @brief Makes a translation of the matrix
|
||||
* @param[in] vect Translation to apply.
|
||||
@ -290,7 +291,8 @@ namespace etk
|
||||
*/
|
||||
Matrix4 Invert(void);
|
||||
};
|
||||
Matrix4 matPerspective(float left, float right, float bottom, float top, float nearVal, float farVal);
|
||||
Matrix4 matPerspective(float fovx, float aspect, float zNear, float zFar);
|
||||
Matrix4 matOrtho(float left, float right, float bottom, float top, float nearVal, float farVal);
|
||||
Matrix4 matTranslate(etk::Vector3D<float> vect);
|
||||
Matrix4 matScale(etk::Vector3D<float> vect);
|
||||
Matrix4 matRotate(etk::Vector3D<float> vect, float angleRad=0.0);
|
||||
|
@ -33,8 +33,13 @@ namespace etk
|
||||
* = assigment
|
||||
*****************************************************/
|
||||
const Vector2D<T>& operator= (const Vector2D<T>& obj ) {
|
||||
x = (T)obj.x;
|
||||
y = (T)obj.y;
|
||||
x = obj.x;
|
||||
y = obj.y;
|
||||
return *this;
|
||||
}
|
||||
const Vector2D<T>& operator= (const T val ) {
|
||||
x = val;
|
||||
y = val;
|
||||
return *this;
|
||||
}
|
||||
/*****************************************************
|
||||
@ -59,8 +64,13 @@ namespace etk
|
||||
* += operator
|
||||
*****************************************************/
|
||||
const Vector2D<T>& operator+= (const Vector2D<T>& obj) {
|
||||
x += (T)obj.x;
|
||||
y += (T)obj.y;
|
||||
x += obj.x;
|
||||
y += obj.y;
|
||||
return *this;
|
||||
}
|
||||
const Vector2D<T>& operator+= (const T val) {
|
||||
x += val;
|
||||
y += val;
|
||||
return *this;
|
||||
}
|
||||
/*****************************************************
|
||||
@ -68,16 +78,27 @@ namespace etk
|
||||
*****************************************************/
|
||||
Vector2D<T> operator+ (const Vector2D<T>& obj) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x += (T)obj.x;
|
||||
tmpp.y += (T)obj.y;
|
||||
tmpp.x += obj.x;
|
||||
tmpp.y += obj.y;
|
||||
return tmpp;
|
||||
}
|
||||
Vector2D<T> operator+ (const T val) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x += val;
|
||||
tmpp.y += val;
|
||||
return tmpp;
|
||||
}
|
||||
/*****************************************************
|
||||
* -= operator
|
||||
*****************************************************/
|
||||
const Vector2D<T>& operator-= (const Vector2D<T>& obj) {
|
||||
x -= (T)obj.x;
|
||||
y -= (T)obj.y;
|
||||
x -= obj.x;
|
||||
y -= obj.y;
|
||||
return *this;
|
||||
}
|
||||
const Vector2D<T>& operator-= (const T val) {
|
||||
x -= val;
|
||||
y -= val;
|
||||
return *this;
|
||||
}
|
||||
/*****************************************************
|
||||
@ -85,16 +106,33 @@ namespace etk
|
||||
*****************************************************/
|
||||
Vector2D<T> operator- (const Vector2D<T>& obj) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x -= (T)obj.x;
|
||||
tmpp.y -= (T)obj.y;
|
||||
tmpp.x -= obj.x;
|
||||
tmpp.y -= obj.y;
|
||||
return tmpp;
|
||||
}
|
||||
Vector2D<T> operator- (const T val) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x -= val;
|
||||
tmpp.y -= val;
|
||||
return tmpp;
|
||||
}
|
||||
/*****************************************************
|
||||
* /= operator
|
||||
*****************************************************/
|
||||
const Vector2D<T>& operator/= (const Vector2D<T>& obj) {
|
||||
x /= (T)obj.x;
|
||||
y /= (T)obj.y;
|
||||
if (obj.x!=0) {
|
||||
x /= obj.x;
|
||||
}
|
||||
if (obj.y!=0) {
|
||||
y /= obj.y;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
const Vector2D<T>& operator/= (const T val) {
|
||||
if (val != 0) {
|
||||
x /= val;
|
||||
y /= val;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/*****************************************************
|
||||
@ -106,12 +144,23 @@ namespace etk
|
||||
tmpp.y /= (T)obj.y;
|
||||
return tmpp;
|
||||
}
|
||||
Vector2D<T> operator/ (const T val) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x /= val;
|
||||
tmpp.y /= val;
|
||||
return tmpp;
|
||||
}
|
||||
/*****************************************************
|
||||
* *= operator
|
||||
*****************************************************/
|
||||
const Vector2D<T>& operator*= (const Vector2D<T>& obj) {
|
||||
x *= (T)obj.x;
|
||||
y *= (T)obj.y;
|
||||
x *= obj.x;
|
||||
y *= obj.y;
|
||||
return *this;
|
||||
}
|
||||
const Vector2D<T>& operator*= (const T val) {
|
||||
x *= val;
|
||||
y *= val;
|
||||
return *this;
|
||||
}
|
||||
/*****************************************************
|
||||
@ -119,8 +168,14 @@ namespace etk
|
||||
*****************************************************/
|
||||
Vector2D<T> operator* (const Vector2D<T>& obj) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x *= (T)obj.x;
|
||||
tmpp.y *= (T)obj.y;
|
||||
tmpp.x *= obj.x;
|
||||
tmpp.y *= obj.y;
|
||||
return tmpp;
|
||||
}
|
||||
Vector2D<T> operator* (const T val) {
|
||||
Vector2D<T> tmpp(x,y);
|
||||
tmpp.x *= val;
|
||||
tmpp.y *= val;
|
||||
return tmpp;
|
||||
}
|
||||
/*****************************************************
|
||||
|
@ -66,7 +66,7 @@ namespace etk
|
||||
z += (T)obj.z;
|
||||
return *this;
|
||||
}
|
||||
const Vector3D<T>& operator+= (const float val) {
|
||||
const Vector3D<T>& operator+= (const T val) {
|
||||
x += val;
|
||||
y += val;
|
||||
z += val;
|
||||
@ -82,7 +82,7 @@ namespace etk
|
||||
tmpp.z += (T)obj.z;
|
||||
return tmpp;
|
||||
}
|
||||
Vector3D<T> operator+ (const float val) {
|
||||
Vector3D<T> operator+ (const T val) {
|
||||
Vector3D<T> tmpp(x,y,z);
|
||||
tmpp.x += val;
|
||||
tmpp.y += val;
|
||||
@ -98,7 +98,7 @@ namespace etk
|
||||
z -= (T)obj.z;
|
||||
return *this;
|
||||
}
|
||||
const Vector3D<T>& operator-= (const float val) {
|
||||
const Vector3D<T>& operator-= (const T val) {
|
||||
x -= val;
|
||||
y -= val;
|
||||
z -= val;
|
||||
@ -114,7 +114,7 @@ namespace etk
|
||||
tmpp.z -= (T)obj.z;
|
||||
return tmpp;
|
||||
}
|
||||
Vector3D<T> operator- (const float val) {
|
||||
Vector3D<T> operator- (const T val) {
|
||||
Vector3D<T> tmpp(x,y,z);
|
||||
tmpp.x -= val;
|
||||
tmpp.y -= val;
|
||||
@ -136,7 +136,7 @@ namespace etk
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
const Vector3D<T>& operator/= (const float val) {
|
||||
const Vector3D<T>& operator/= (const T val) {
|
||||
if (val==0) {
|
||||
return *this;
|
||||
}
|
||||
@ -161,7 +161,7 @@ namespace etk
|
||||
}
|
||||
return tmpp;
|
||||
}
|
||||
Vector3D<T> operator/ (const float val) {
|
||||
Vector3D<T> operator/ (const T val) {
|
||||
Vector3D<T> tmpp(x,y,z);
|
||||
if (val==0) {
|
||||
return tmpp;
|
||||
@ -180,7 +180,7 @@ namespace etk
|
||||
z *= (T)obj.z;
|
||||
return *this;
|
||||
}
|
||||
const Vector3D<T>& operator*= (const float val) {
|
||||
const Vector3D<T>& operator*= (const T val) {
|
||||
x *= val;
|
||||
y *= val;
|
||||
z *= val;
|
||||
@ -196,7 +196,7 @@ namespace etk
|
||||
tmpp.z *= (T)obj.z;
|
||||
return tmpp;
|
||||
}
|
||||
Vector3D<T> operator* (const float val) {
|
||||
Vector3D<T> operator* (const T val) {
|
||||
Vector3D<T> tmpp(x,y,z);
|
||||
tmpp.x *= val;
|
||||
tmpp.y *= val;
|
||||
|
Loading…
x
Reference in New Issue
Block a user