Skip to content

Commit

Permalink
2023-2-26
Browse files Browse the repository at this point in the history
update
  • Loading branch information
sdragonx committed Feb 26, 2023
1 parent 614e274 commit ca9450d
Show file tree
Hide file tree
Showing 27 changed files with 324 additions and 165 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ glm C++98 version.

![logo](./glm.jpg)

glm 原库作为图形基础库,下载使用量没有 cglm 多,其中一个原因就是,这个库竟然用 C++ 11。<br>
这里是一个 C++ 98 版本的 glm 库,兼容比较老的编译器。<br>
虽然有些方法在实现上,C++ 11 比 C++ 98 方便一些,但也不是不能完全实现。<br>
glm 原库作为图形基础库,下载使用量没有 cglm 多,其中一个原因就是,这个库竟然用 C++11。<br>
这里是一个 C++98 版本的 glm 库,兼容比较老的编译器。<br>
虽然有些方法在实现上,C++11 比 C++98 方便一些,但也不是不能完全实现。<br>
好吧,有问题欢迎指正!<br>
<br>
The original GLM library, as the basic graphics library, has not been downloaded as much as cglm.<br>
One of the reasons is that this library uses C++ 11.<br>
Here is a C + + 98 version of GLM library, compatible with older compilers.<br>
Although C + + 11 is more convenient than C + + 98 in the implementation of some methods, it is not completely realized.<br>
One of the reasons is that this library uses C++11.<br>
Here is a C++98 version of GLM library, compatible with older compilers.<br>
Although C++11 is more convenient than C++98 in the implementation of some methods, it is not completely realized.<br>
Well, if you have any questions, please correct them!<br>
<br>
# 说明<br>
程序部分,使用的是 C++ 98 标准,所有代码在 cgl::glm 命名空间下。<br>
程序部分,使用的是 C++98 标准,所有代码在 cgl::glm 命名空间下。<br>
glm.hpp 里面使用了 using namespace cgl 来暴露 glm 的命名空间。<br>
精简了结构,代码量更少,部分代码执行率比原版要快一些。<br>

# 更新历史<br>

### 2023-2-26
修复 isinf() isnan() bug,修复一些编译器错误。

### 2022-5-20
mat2x3 mat3x2 等行列不等的矩阵参数、功能修复。

Expand Down
79 changes: 68 additions & 11 deletions glm/detail/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,89 @@

namespace glm {

#if !defined(FP_INFINITE) && !defined(FP_NAN)
#if defined(GLM_NATIVE_CPP11_SUPPORT)

template<typename T>
GLM_API bool isinf(const T& n)
using std::isfinite;
using std::isinf;
using std::isnan;
using std::isnormal;
using std::signbit;

#elif defined(_FPCLASS_SNAN) || defined(FP_SNAN)

//
// fpclass
//

GLM_API bool isfinite(double n)
{
return _finite(n);
return _finite(n);
}

template<typename T>
GLM_API bool isnan(const T& n)
GLM_API bool isinf(double n)
{
return _fpclass(n) & (_FPCLASS_NINF | _FPCLASS_PINF);
}

GLM_API bool isnan(double n)
{
//return _fpclass(n) & (_FPCLASS_SNAN | _FPCLASS_QNAN);
return _isnan(n);
}

#else
GLM_API bool isnormal(double n)
{
return _fpclass(n) & (_FPCLASS_NN | _FPCLASS_PN);
}

GLM_API bool signbit(double n)
{
return n < 0.0;
}

#elif defined(FP_INFINITE)

//
// __fpclassify() // msvc
//

template<typename T>
bool isfinite(T value)
{
return fpclassify(T) <= 0;
}

template<typename T>
bool isinf(T value)
{
return fpclassify(value) == FP_INFINITE;
}

template<typename T>
GLM_API bool isinf(const T& n)
bool isnan(T value)
{
return std::isinf(n);
return fpclassify(value) == FP_NAN;
}

template<typename T>
GLM_API bool isnan(const T& n)
bool isnormal(T value)
{
return fpclassify(value) == FP_NORMAL;
}

bool signbit(float value)
{
return _fdsign(value);
}

bool signbit(double value)
{
return _dsign(value);
}

bool signbit(long double value)
{
return std::isnan(n);
return _ldsign(value);
}

#endif
Expand Down
10 changes: 1 addition & 9 deletions glm/detail/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@

#include "constants.hpp"

#ifdef min
#undef min
#endif

#ifdef max
#undef max
#endif



namespace glm {

template<typename T>
GLM_API T min(const T& x, const T& y)
{
Expand Down
119 changes: 108 additions & 11 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,72 @@
#ifndef GLM_SETUP_HPP_20211115221355
#define GLM_SETUP_HPP_20211115221355

#if defined(min) || defined(max)
#if defined(_INC_WINDOWS)
#pragma message define NOMINMAX before include <windows.h>
#endif
#endif

#if defined(min)
#undef min
#endif

#if defined(max)
#undef max
#endif

#include <algorithm>
#include <cmath>
#include <float.h>
#include <limits>

#define GLM_VERSION_MAJOR 0
#define GLM_VERSION_MINOR 1
#define GLM_VERSION_PATCH 0
#define GLM_VERSION_REVISION 0
#define GLM_VERSION 100
#define GLM_VERSION_MESSAGE "glm version 0.1.0.0"
#if defined(_MSC_VER)
#if (_MSC_VER < 1300)
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
}
#elif (_MSC_VER < 1600)
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
#else
#include <stdint.h>
#endif
#else
#include <stdint.h>
#endif

#define GLM_VERSION_MAJOR 0
#define GLM_VERSION_MINOR 4
#define GLM_VERSION_PATCH 0
#define GLM_VERSION_REVISION 0
#define GLM_VERSION (GLM_VERSION_MAJOR * 1000 + GLM_VERSION_MINOR * 100 + GLM_VERSION_PATCH * 10 + GLM_VERSION_REVISION)
#define GLM_VERSION_MESSAGE "GLM: version 0.4.0.0 (c++98)"

#define GLM_SETUP_INCLUDED GLM_VERSION
#define GLM_SETUP_INCLUDED GLM_VERSION

///////////////////////////////////////////////////////////////////////////////////
// Active states

#define GLM_DISABLE 0
#define GLM_ENABLE 1
#define GLM_DISABLE 0
#define GLM_ENABLE 1

//
// platform
Expand All @@ -53,6 +101,39 @@
#define GLM_PLATFORM_UNKNOWN
#endif

//
// cpp11 check
//

#ifndef __has_feature
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif

// Any compiler claiming C++11 supports, Visual C++ 2015 and Clang version supporting constexpr
#if ((__cplusplus >= 201103L) || (_MSC_VER >= 1900) || (__has_feature(cxx_constexpr))) // C++ 11 implementation
#define GLM_NATIVE_CPP11_SUPPORT
#define GLM_NATIVE_CPP11_TYPES_SUPPORT
#endif

#if !defined(GLM_NATIVE_CPP11_TYPES_SUPPORT)
#if (__cplusplus > 199711L) || defined(__CODEGEARC__) || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
defined(__cpp_unicode_characters) || __has_feature(cxx_unicode_literals)
#define GLM_NATIVE_CPP11_TYPES_SUPPORT
#endif
#endif

#if ((!defined(_MSC_VER) || _MSC_VER < 1600) && !defined(GLM_NATIVE_CPP11_TYPES_SUPPORT)) || (defined(__CODEGEARC__) && !(defined(__clang__)))
#define GLM_IMPLEMENTS_NULLPTR_SUPPORT
#else
#define GLM_NATIVE_NULLPTR_SUPPORT
#endif

#if (_MSC_VER >= 1600)
#ifndef GLM_NATIVE_CPP11_TYPES_SUPPORT
#define GLM_NATIVE_CPP11_TYPES_SUPPORT
#endif
#endif

//
// types
//
Expand All @@ -64,19 +145,35 @@
typedef value_type* pointer;\
typedef const value_type* const_pointer;\
typedef value_type& reference;\
typedef const value_type& const_reference;
typedef const value_type& const_reference

#endif

#define GLM_API inline
#define GLM_INS_API static


#ifdef GLM_FORCE_EXPLICIT_CTOR
#define GLM_EXPLICIT explicit
#else
#define GLM_EXPLICIT
#endif

namespace glm {

// int type
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;

// size type
typedef size_t length_t;

// object type
template<length_t N, typename T> class vec;
template<length_t CX, length_t CY, typename T> class mat;

Expand Down
2 changes: 1 addition & 1 deletion glm/detail/trigonometric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@



namespace glm{
namespace glm {

template<typename T>
GLM_API T radians(T value)
Expand Down
3 changes: 1 addition & 2 deletions glm/geometric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@



namespace glm{
namespace glm {

//
// T dot( in vec<N, T>, in vec<N, T> )
Expand Down Expand Up @@ -73,7 +73,6 @@ GLM_API T distance(const vec<N, T>& a, const vec<N, T>& b)
// vec3 cross( in vec3, in vec3 )
//


/* 叉乘
*
* 返回两个向量的垂直向量
Expand Down
2 changes: 1 addition & 1 deletion glm/glm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@



namespace glm{
namespace glm {

typedef vec<1, bool> bvec1;
typedef vec<2, bool> bvec2;
Expand Down
12 changes: 7 additions & 5 deletions glm/gtc/matrix_projection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@



namespace glm{

namespace glm {

//
// project
Expand All @@ -30,13 +29,16 @@ GLM_API vec<4, T> project(
vec<4, T> product = modelview * v;
product = projection * product;

// 透视除法
/* 透视除法
*/
product /= product.w;

// 映射到 0 ~ 1
/* 映射到 0 ~ 1
*/
product = product * constants<T>::half + constants<T>::half;

// 转换到屏幕坐标
/* 转换到屏幕坐标
*/
const T x = static_cast<T>(viewport[0]);
const T y = static_cast<T>(viewport[1]);
const T w = static_cast<T>(viewport[2]);
Expand Down
Loading

0 comments on commit ca9450d

Please sign in to comment.