NW4F G3d
Loading...
Searching...
No Matches
g3d_MathCommon.h
Go to the documentation of this file.
1#ifndef NW_G3D_MATH_COMMON_H_
2#define NW_G3D_MATH_COMMON_H_
3
4#include <nw/g3d/g3d_config.h>
5
6namespace nw { namespace g3d { namespace math {
7
8class Math
9{
10public:
11 static float Abs(float x);
12 static float NAbs(float x);
13 static float Mod(float x, float y);
14 static float Select(float cond, float pos, float neg);
15 static float Min(float x, float y);
16 static float Max(float x, float y);
17 static float Clamp(float x, float minVal, float maxVal);
18
19 static float Ceil(float x);
20 static float Floor(float x);
21 static float Trunc(float x);
22 static float Round(float x);
23
24 template <typename T> static T Ceil(float x);
25 template <typename T> static T Floor(float x);
26 template <typename T> static T Trunc(float x);
27 template <typename T> static T Round(float x);
28
29 static float Rcp(float x);
30 static float RSqrt(float x);
31 static float Sqrt(float x);
32 static float Exp(float x);
33 static float Log(float x);
34 static float Log10(float x);
35
36 static float Sin(float rad);
37 static float Cos(float rad);
38 static float Tan(float rad);
39 static float Asin(float x);
40 static float Acos(float x);
41 static float Atan(float x);
42 static float Atan2(float y, float x);
43 static void SinCos(float* pSin, float* pCos, float rad);
44
45 static float SinIdx(u32 idx);
46 static float CosIdx(u32 idx);
47 static float TanIdx(u32 idx);
48 static u32 AsinIdx(float x);
49 static u32 AcosIdx(float x);
50 static u32 AtanIdx(float x);
51 static u32 Atan2Idx(float y, float x);
52 static void SinCosIdx(float* pSin, float* pCos, u32 idx);
53
54#if defined( __ghs__ )
55 static f32x2 Rcp(f32x2 x);
56 static f32x2 RSqrt(f32x2 x);
57 static f32x2 SinCos(float rad);
58 static f32x2 SinCosIdx(u32 idx);
59#endif // defined( __ghs__ )
60
61 static bool IsNaN(float x);
62
63 NW_G3D_MATH_INLINE static float Pi() { return 3.141592653589793f; }
64 NW_G3D_MATH_INLINE static float Napier() { return 2.718281828459045f; }
65
67 static u32 RadToIdx(float rad)
68 {
69 return static_cast<u32>(static_cast<s64>(rad * (float(0x80000000) / Pi())));
70 }
71
73 static u32 DegToIdx(float deg)
74 {
75 return static_cast<u32>(static_cast<s64>(deg * (float(0x80000000) / 180.0f)));
76 }
77
79 static float IdxToRad(u32 idx)
80 {
81 return idx * (Pi() / float(0x80000000));
82 }
83
85 static float IdxToDeg(u32 idx)
86 {
87 return idx * (180.0f / float(0x80000000));
88 }
89
91 static float RadToDeg(float rad)
92 {
93 return rad * (180.0f / Pi());
94 }
95
97 static float DegToRad(float deg)
98 {
99 return deg * (Pi() / 180.0f);
100 }
101
102};
103
104namespace internal {
105
107{
108 enum {
115 };
116
117 float sinValue;
118 float cosValue;
119 float sinDelta;
120 float cosDelta;
121};
122
124
125} // namespace internal
126
127} } } // namespace nw::g3d::math
128
129#include "inl/g3d_MathCommon-inl.h"
130
131#endif // NW_G3D_MATH_COMMON_H_
Definition g3d_MathCommon.h:9
static float Atan2(float y, float x)
Definition g3d_MathCommon-inl.h:232
static float Ceil(float x)
Definition g3d_MathCommon-inl.h:125
static u32 AtanIdx(float x)
Definition g3d_MathCommon-inl.h:292
static void SinCos(float *pSin, float *pCos, float rad)
Definition g3d_MathCommon-inl.h:238
static float Sqrt(float x)
Definition g3d_MathCommon-inl.h:163
static float Max(float x, float y)
Definition g3d_MathCommon-inl.h:50
static u32 AsinIdx(float x)
Definition g3d_MathCommon-inl.h:278
static NW_G3D_MATH_INLINE float DegToRad(float deg)
Definition g3d_MathCommon.h:97
static NW_G3D_MATH_INLINE float IdxToRad(u32 idx)
Definition g3d_MathCommon.h:79
static float Round(float x)
Definition g3d_MathCommon-inl.h:134
static float Tan(float rad)
Definition g3d_MathCommon-inl.h:205
static T Trunc(float x)
static float Log(float x)
Definition g3d_MathCommon-inl.h:179
static float Asin(float x)
Definition g3d_MathCommon-inl.h:211
static float Min(float x, float y)
Definition g3d_MathCommon-inl.h:44
static bool IsNaN(float x)
Definition g3d_MathCommon-inl.h:367
static float Cos(float rad)
Definition g3d_MathCommon-inl.h:199
static float Clamp(float x, float minVal, float maxVal)
Definition g3d_MathCommon-inl.h:56
static float Trunc(float x)
Definition g3d_MathCommon-inl.h:131
static float Abs(float x)
Definition g3d_MathCommon-inl.h:16
static float Sin(float rad)
Definition g3d_MathCommon-inl.h:193
static T Round(float x)
static float Log10(float x)
Definition g3d_MathCommon-inl.h:185
static float Exp(float x)
Definition g3d_MathCommon-inl.h:173
static T Floor(float x)
static T Ceil(float x)
static float Acos(float x)
Definition g3d_MathCommon-inl.h:218
static float Mod(float x, float y)
Definition g3d_MathCommon-inl.h:28
static float Atan(float x)
Definition g3d_MathCommon-inl.h:225
static float TanIdx(u32 idx)
Definition g3d_MathCommon-inl.h:270
static u32 AcosIdx(float x)
Definition g3d_MathCommon-inl.h:285
static float SinIdx(u32 idx)
Definition g3d_MathCommon-inl.h:246
static NW_G3D_MATH_INLINE float Pi()
Definition g3d_MathCommon.h:63
static float Select(float cond, float pos, float neg)
Definition g3d_MathCommon-inl.h:34
static NW_G3D_MATH_INLINE u32 RadToIdx(float rad)
Definition g3d_MathCommon.h:67
static u32 Atan2Idx(float y, float x)
Definition g3d_MathCommon-inl.h:299
static float CosIdx(u32 idx)
Definition g3d_MathCommon-inl.h:258
static NW_G3D_MATH_INLINE float Napier()
Definition g3d_MathCommon.h:64
static NW_G3D_MATH_INLINE float IdxToDeg(u32 idx)
Definition g3d_MathCommon.h:85
static float RSqrt(float x)
Definition g3d_MathCommon-inl.h:150
static float Rcp(float x)
Definition g3d_MathCommon-inl.h:139
static float NAbs(float x)
Definition g3d_MathCommon-inl.h:22
static NW_G3D_MATH_INLINE u32 DegToIdx(float deg)
Definition g3d_MathCommon.h:73
static NW_G3D_MATH_INLINE float RadToDeg(float rad)
Definition g3d_MathCommon.h:91
static void SinCosIdx(float *pSin, float *pCos, u32 idx)
Definition g3d_MathCommon-inl.h:305
static float Floor(float x)
Definition g3d_MathCommon-inl.h:128
#define NW_G3D_MATH_INLINE
Definition g3d_defs.h:69
Definition g3d_MathCommon.h:104
const SinCosSample gSinCosTable[SinCosSample::TABLE_SIZE]
Definition g3d_MathCommon.cpp:5
Definition g3d_MathCommon.h:6
Definition g3d_GfxManage.cpp:10
Definition g3d_MathCommon.h:107
@ FRAC_BIT
Definition g3d_MathCommon.h:110
@ TABLE_SIZE
Definition g3d_MathCommon.h:111
@ INDEX_MASK
Definition g3d_MathCommon.h:113
@ INDEX_BIT
Definition g3d_MathCommon.h:109
@ FRAC_MASK
Definition g3d_MathCommon.h:114
@ FRAC_SIZE
Definition g3d_MathCommon.h:112
float cosValue
Definition g3d_MathCommon.h:118
float cosDelta
Definition g3d_MathCommon.h:120
float sinDelta
Definition g3d_MathCommon.h:119
float sinValue
Definition g3d_MathCommon.h:117