Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
MathDX.h
Go to the documentation of this file.
1 //
6 //
7 
8 #ifndef _INC_MathDX_H
9 #define _INC_MathDX_H
10 #ifndef NO_PRAGMA_ONCE
11 #pragma once
12 #endif
13 
14 #include "../GrayLibBase.h"
15 #include "../Image/cColorRef.h"
17 
18 typedef float D3DVALUE; // #define DX_SHARED_DEFINES
19 
20 #ifdef USE_DXM
21 // let DX define its own math stuff.
22 #include <DirectXMath.h> // XMFLOAT3
23 using namespace DirectX;
24 
25 #else // USE_DXM
26 // define stuff i might use without including <DirectXMath.h>
27 
28 #if _MSC_VER >= 1300 // VC7
29 #define D3DX_ALIGN16 __declspec(align(16)) // for faster matrix access.
30 #else
31 #define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing.
32 #endif
33 
34 typedef DWORD D3DCOLOR;
35 
36 struct XMFLOAT2
37 {
38  // XMFLOAT2
39  XMFLOAT2() noexcept
40  {}
41  XMFLOAT2( const D3DVALUE* pVal ) noexcept
42  : x(pVal[0]), y(pVal[1])
43  {
44  }
45  operator D3DVALUE*() noexcept
46  {
47  return &x;
48  }
49  operator const D3DVALUE*() const noexcept
50  {
51  return &x;
52  }
53 public:
54  D3DVALUE x, y;
55 };
56 
57 struct XMFLOAT3
58 {
59  // XMFLOAT3
60  D3DVALUE x, y, z;
61 
62  XMFLOAT3() noexcept
63  {
64  // x=_x; y=_y; z=_z;
65  }
66  XMFLOAT3( D3DVALUE _x, D3DVALUE _y, D3DVALUE _z ) noexcept
67  {
68  x=_x; y=_y; z=_z;
69  }
70  XMFLOAT3( const XMFLOAT3& v ) noexcept
71  {
72  x = v.x; y = v.y; z = v.z;
73  }
74  XMFLOAT3( const D3DVALUE* pVal )
75  {
76  x = pVal[0]; y=pVal[1]; z=pVal[2];
77  }
78  operator D3DVALUE*() noexcept
79  {
80  return &x;
81  }
82  operator const D3DVALUE*() const noexcept
83  {
84  return &x;
85  }
86  XMFLOAT3 operator + ( const XMFLOAT3& v ) const
87  {
88  return XMFLOAT3( x + v.x, y + v.y, z + v.z );
89  }
90  XMFLOAT3 operator * ( const XMFLOAT3& v ) const
91  {
92  // HLSL, but no d3dx equivalent
93  return XMFLOAT3( x * v.x, y * v.y, z * v.z );
94  }
95  XMFLOAT3 operator * ( D3DVALUE fScale ) const
96  {
97  // HLSL, but no d3dx equivalent
98  return XMFLOAT3( x * fScale, y *fScale, z * fScale );
99  }
100  friend XMFLOAT3 operator * ( D3DVALUE f, const XMFLOAT3& v )
101  {
102  return XMFLOAT3( f * v.x, f * v.y, f * v.z);
103  }
104 };
105 struct XMFLOAT4
106 {
107  // like XMFLOAT4 .
108  // Use XMLoadFloat4() to get XMVECTOR FXMVECTOR
109 
110  XMFLOAT4() noexcept
111  {}
112  XMFLOAT4( D3DVALUE _x, D3DVALUE _y, D3DVALUE _z, D3DVALUE _w ) noexcept
113  : x(_x), y(_y), z(_z), w(_w)
114  {
115  }
116  XMFLOAT4( const D3DVALUE* pVal )
117  {
118  x = pVal[0]; y=pVal[1]; z=pVal[2]; w=pVal[3];
119  }
120  XMFLOAT4( const XMFLOAT3& xyz, float _w ) noexcept
121  {
122  x = xyz.x; y=xyz.y; z=xyz.z; w=_w;
123  }
124  operator D3DVALUE*() noexcept
125  {
126  return &x;
127  }
128  operator const D3DVALUE*() const noexcept
129  {
130  return &x;
131  }
132 
133 public:
134  D3DVALUE x, y, z, w;
135 };
136 
138 {
139  // XMFLOAT4X4
140  union
141  {
142  struct
143  {
144  D3DVALUE _11, _12, _13, _14;
145  D3DVALUE _21, _22, _23, _24;
146  D3DVALUE _31, _32, _33, _34;
147  D3DVALUE _41, _42, _43, _44;
148  };
149  D3DVALUE m[4][4];
150  D3DVALUE a[16];
151  };
152 };
153 
155 {
156  // 16 byte aligned block.
157  XMMATRIX() noexcept
158  {
159  // undefined.
160  }
162  {
163  ::memcpy( this->m, src, sizeof(m));
164  }
165  XMMATRIX( const XMFLOAT4X4& src ) noexcept
166  {
167  ::memcpy(this->m, src.m, sizeof(m));
168  }
170  D3DVALUE a21, D3DVALUE a22, D3DVALUE a23, D3DVALUE a24,
171  D3DVALUE a31, D3DVALUE a32, D3DVALUE a33, D3DVALUE a34,
172  D3DVALUE a41, D3DVALUE a42, D3DVALUE a43, D3DVALUE a44 ) noexcept
173  {
174  _11=a11; _12=a12; _13=a13; _14=a14;
175  _21=a21; _22=a22; _23=a23; _24=a24;
176  _31=a31; _32=a32; _33=a33; _34=a34;
177  _41=a41; _42=a42; _43=a43; _44=a44;
178  }
179 
180  D3DVALUE& operator()(int i, int j)
181  { return m[i][j]; }
182  D3DVALUE operator()(int i, int j) const
183  { return m[i][j]; }
184 };
185 
186 #endif // USE_DXM
187 
188 #endif // _INC_MathDX_H
#define D3DX_ALIGN16
Definition: MathDX.h:31
float D3DVALUE
Definition: MathDX.h:18
DWORD D3DCOLOR
Definition: MathDX.h:34
cVecT2< TYPE > operator*(const TYPE nVal, const cVecT2< TYPE > &v2)
Definition: cVecT.h:522
const cDebugSourceLine & src
Definition: cDebugAssert.h:51
cStringA operator+(const char *pStr1, const cStringA &s2)
Definition: cString.h:642
Definition: MathDX.h:37
XMFLOAT2(const D3DVALUE *pVal) noexcept
Definition: MathDX.h:41
XMFLOAT2() noexcept
Definition: MathDX.h:39
D3DVALUE x
Definition: MathDX.h:54
Definition: MathDX.h:58
D3DVALUE y
Definition: MathDX.h:60
XMFLOAT3() noexcept
Definition: MathDX.h:62
XMFLOAT3(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z) noexcept
Definition: MathDX.h:66
XMFLOAT3(const D3DVALUE *pVal)
Definition: MathDX.h:74
D3DVALUE z
Definition: MathDX.h:60
D3DVALUE x
Definition: MathDX.h:60
XMFLOAT3(const XMFLOAT3 &v) noexcept
Definition: MathDX.h:70
Definition: MathDX.h:138
D3DVALUE _11
Definition: MathDX.h:144
D3DVALUE _41
Definition: MathDX.h:147
D3DVALUE _21
Definition: MathDX.h:145
D3DVALUE _31
Definition: MathDX.h:146
Definition: MathDX.h:106
D3DVALUE w
Definition: MathDX.h:134
XMFLOAT4() noexcept
Definition: MathDX.h:110
XMFLOAT4(const XMFLOAT3 &xyz, float _w) noexcept
Definition: MathDX.h:120
XMFLOAT4(const D3DVALUE *pVal)
Definition: MathDX.h:116
XMFLOAT4(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z, D3DVALUE _w) noexcept
Definition: MathDX.h:112
Definition: MathDX.h:155
D3DVALUE operator()(int i, int j) const
Definition: MathDX.h:182
D3DVALUE & operator()(int i, int j)
Definition: MathDX.h:180
XMMATRIX() noexcept
Definition: MathDX.h:157
XMMATRIX(const D3DVALUE *src)
Definition: MathDX.h:161
XMMATRIX(D3DVALUE a11, D3DVALUE a12, D3DVALUE a13, D3DVALUE a14, D3DVALUE a21, D3DVALUE a22, D3DVALUE a23, D3DVALUE a24, D3DVALUE a31, D3DVALUE a32, D3DVALUE a33, D3DVALUE a34, D3DVALUE a41, D3DVALUE a42, D3DVALUE a43, D3DVALUE a44) noexcept
Definition: MathDX.h:169
XMMATRIX(const XMFLOAT4X4 &src) noexcept
Definition: MathDX.h:165