diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 1f2871f..0e17c4c 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -6,20 +6,26 @@ //注:GLM/CML(OpenGLMode)是列矩阵,计算坐标matrix*pos // 而MGL是行矩阵,需要反过来pos*matrix +#include + namespace hgl { - using Matrix3f=float3x3; - using Matrix4f=float4x4; - using Matrix3x4f=float3x4; + using Matrix3f=glm::mat3; + using Matrix4f=glm::mat4; inline Matrix4f identity() { - return Matrix4f::identity; + return Matrix4f(); } inline Matrix4f inverse(const Matrix4f &m) { - return m.Inverted(); + return glm::inverse(m); + } + + inline Matrix4f transpose(const Matrix4f &m) + { + return glm::transpose(m); } /** @@ -76,52 +82,52 @@ namespace hgl inline Matrix4f translate(const Vector3f &v) { - return Matrix4f::Translate(v); + return glm::translate(Matrix4f(1.0f),v); } inline Matrix4f translate(float x,float y,float z) { - return Matrix4f::Translate(x,y,z); + return glm::translate(Matrix4f(1.0f),Vector3f(x,y,z)); } inline Matrix4f translate(float x,float y) { - return Matrix4f::Translate(x,y,1.0f); + return translate(x,y,1.0f); } inline Matrix4f scale(const Vector3f &v) { - return Matrix4f::Scale(v,Vector3f::zero); + return glm::scale(Matrix4f(1.0f),v); } inline Matrix4f scale(float x,float y,float z) { - return Matrix4f::Scale(Vector3f(x,y,z),Vector3f::zero); + return glm::scale(Matrix4f(1.0f),Vector3f(x,y,z)); } inline Matrix4f scale(float x,float y) { - return Matrix4f::Scale(Vector3f(x,y,1.0f),Vector3f::zero); + return scale(x,y,1.0f); } inline Matrix4f scale(float s) { - return Matrix4f::Scale(Vector3f(s,s,s),Vector3f::zero); + return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s)); } inline Matrix4f rotate(float angle,const Vector3f &axis) { - return Matrix4f::RotateAxisAngle(axis.Normalized(),angle); + return glm::rotate(Matrix4f(1.0f),angle,axis); } inline Matrix4f rotate(float angle,float x,float y,float z) { - return rotate(angle,Vector3f(x,y,z)); + return glm::rotate(Matrix4f(1.0f),angle,Vector3f(x,y,z)); } inline Matrix4f rotate(float angle,float x,float y) { - return rotate(angle,Vector3f(x,y,1.0f)); + return rotate(angle,x,y,1.0f); } inline Matrix4f rotate(float angle,const Vector4f &axis) @@ -131,9 +137,9 @@ namespace hgl inline Vector3f rotate(const Vector3f &v3f,float angle,const Vector3f &axis) { - Vector4f result=rotate(angle,axis)*Vector4f(v3f,1.0f); + Vector4f result = rotate(angle, axis)*Vector4f(v3f, 1.0f); - return result.xyz(); + return Vector3f(result.x,result.y,result.z); } }//namespace hgl #endif//HGL_ALGORITHM_MATH_VECTOR_MATRIX_INCLUDE diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index c991e3c..00f2c74 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -3,37 +3,16 @@ #ifdef _MSC_VER #pragma warning(disable:4244) // double -> int 精度丢失警告 -#pragma warning(disable:4996) // sprintf may be unsafe, Consider using sprintf_s instead #endif//_MSC_VER #include -#include - -/** - * MathGeoLib - * Game Math and Geometry Library - * - * My C++ library for 3D mathematics and geometry manipulation. - * Jukka Jylänki - * - * offical web: http://clb.demon.fi/MathGeoLib/nightly/ - * - * License: - * - * This library is licensed under the Apache 2 license. I am not a lawyer, but to me that - * license means that you can use this code for any purpose, both commercial and closed source. - * You are however restricted from claiming you wrote it yourself, and cannot hold me liable - * for anything over this code. - * I acknowledge that most of the non-trivial math routines are taken off a book or a - * research paper. In all places, I have tried to be diligent to properly attribute the original - * source. Please contact me if you feel I have misattributed something. - */ +#include namespace hgl { - using Vector2f=float2; - using Vector3f=float3; - using Vector4f=float4; + using Vector2f=glm::vec2; + using Vector3f=glm::vec3; + using Vector4f=glm::vec4; using Vector2i=glm::ivec2; using Vector2u=glm::uvec2; @@ -120,18 +99,18 @@ namespace hgl template inline T normalized(const T &v) { - return v.Normalized(); + return glm::normalize(v); } template inline void normalize(T &v) { - v.Normalize(); + v=glm::normalize(v); } inline Vector3f cross(const Vector3f &v1,const Vector3f &v2) { - return v1.Cross(v2); + return glm::cross(v1,v2); } inline Vector4f cross(const Vector4f &v1,const Vector4f &v2) @@ -147,19 +126,19 @@ namespace hgl template inline float dot(const T &v1,const T &v2) { - return v1.Dot(v2); + return glm::dot(v1,v2); } - template - inline float dot2(const T &v) - { - return v.Dot(v); - } + //template + //inline float dot2(const T &v) + //{ + // return v.Dot(v); + //} - inline float ray_angle_cos(const Ray &ray,const vec &pos) - { - return ray.dir.Dot((pos-ray.pos).Normalized()); - } + //inline float ray_angle_cos(const Ray &ray,const vec &pos) + //{ + // return ray.dir.Dot((pos-ray.pos).Normalized()); + //} inline float length_squared(const Vector2f &v) {