16 #define MINFLOAT 1.17549435E-38F
18 #define M_PI 3.14159265358979323846
31 vector(
const T* &pv){
x = pv[0];
y = pv[1];
z = pv[2];};
34 {
x = pv.x;
y = pv.y;
z = pv.z;
return *
this;};
35 inline void Set(T px, T py, T pz){
x=px;
y=py;
z=pz;};
45 void Normalize(
void){
vector<T> pv((T)(
x*
x),(T)(
y*
y), (T)(
z*
z));T fLength = (T)(1.0f/(
float)(pv.x + pv.y + pv.z));
if (fLength < 1e-08)
return;
x = (T)(pv.x * fLength);
y = (T)(pv.y * fLength);
z = (T)(pv.z * fLength);};
53 template<
typename T,
int size>
58 Array(
const T* pT){memcpy(
data, pT, size *
sizeof(T));};
61 {memcpy(
data, pA.
data, size *
sizeof(T));
return *
this;};
70 typedef Array<unsigned short, 3>
Face;
71 typedef Array<float, 3>
Vertex;
72 typedef Array<float, 2>
TCoord;
73 typedef Array<float, 4>
Color4;
74 typedef Array<float, 3>
Color3;
92 void Zero(
void){memset(
data, 0, 16 *
sizeof(T));};
106 T _fastcall
Index(
int pRow,
int pCol)
const{
return data[(pRow<<2) + pCol];};
122 template <
typename T>
139 float qACos(
float pValue);
145 template <
typename T>
153 {
xs = prect.
xs;
ys = prect.
ys;
xe = prect.
xe;
ye = prect.
ye;
return *
this;};
155 {
xs += pV.x;
ys += pV.y;
xe += pV.x;
ye += pV.y;
return *
this;};
158 trect(
const T pxs,
const T pys,
const T pxe,
const T pye)
159 {
xs = pxs;
ys = pys;
xe = pxe;
ye = pye;};
160 inline void Set(
const T pxs,
const T pys,
const T pxe,
const T pye)
161 {
xs = pxs;
ys = pys;
xe = pxe;
ye = pye;};
162 bool _fastcall
InRect(
const T &px,
const T &py)
163 {
if (px <
xs)
return false;
164 if (px >
xe)
return false;
165 if (py <
ys)
return false;
166 if (py >
ye)
return false;
169 {
if (pv.x <
xs)
return false;
170 if (pv.x >
xe)
return false;
171 if (pv.y <
ys)
return false;
172 if (pv.y >
ye)
return false;
181 {
if ((prect.
xe <=
xe) &&
188 {
if (prect.
xe <
xs)
return false;
189 if (prect.
xs >
xe)
return false;
190 if (prect.
ye <
ys)
return false;
191 if (prect.
ys >
ye)
return false;
204 template<
typename T,
int size>
207 for (
int i= 0; i< size; i++)
212 template<
typename T,
int size>
216 memcpy(rdata,
data, size *
sizeof(T));
217 for (
int i= 0; i< size; i++)
222 template<
typename T,
int size>
226 for (
int i= 0; i< size; i++)
231 template<
typename T,
int size>
235 for (
int i= 0; i< size; i++)
244 for(k = 0; k < 16; k++)
245 Rdata[k] =
data[k] + pm.data[k];
253 for(k = 0; k < 16; k++)
254 Rdata[k] =
data[k] - pm.data[k];
262 for (row = 0; row < 16; row +=4)
263 for (col = 0; col < 4; col ++)
266 Rdata[row + col] = 0;
267 for (k = 0; k < 4; k++, l += 4)
268 Rdata[row + col] +=
data[row + k] * pm.data[l + col];
277 for (row = 0; row < 16; row +=4)
278 for (col = 0; col < 4; col ++)
281 Rdata[row + col] = 0;
282 for (k = 0; k < 4; k++, l += 4)
283 Rdata[row + col] +=
data[row + k] * pm.data[l + col];
285 memcpy(
data, Rdata, 16*
sizeof(T));
293 memcpy(Rdata,
data, 16 *
sizeof(T));
294 for(k = 0; k < 16; k++)
296 return matrix<T>(Rdata);
302 T vdata[4], pvdata[4];
307 for (col = 0; col < 4; col++)
311 for (row = 0; row < 4; row++, k+=4)
312 vdata[col] +=
data[k + col]*pvdata[row];
314 return vector<T>(vdata);
320 T vdata[4], pvdata[4];
322 memcpy(pvdata, pV.data, 3*
sizeof(T));
325 for (col = 0; col < 4; col++)
329 for (row = 0; row < 4; row++, k+=4)
330 vdata[col] +=
data[k + col]*pvdata[row];
333 return Array<T, 3>(vdata);
357 T xx = x*x; T yy = y*y; T zz = z*z;
358 T xy = x*y; T xz = x*z; T yz = y*z;
359 T wx = w*x; T wy = w*y; T wz = w*z;
361 data[0] = 1 - 2 * ( yy + zz );
362 data[1] = 2 * ( xy - wz );
363 data[2] = 2 * ( xz + wy );
365 data[4] = 2 * ( xy + wz );
366 data[5] = 1 - 2 * ( xx + zz );
367 data[6] = 2 * ( yz - wx );
369 data[8] = 2 * ( xz - wy );
370 data[9] = 2 * ( yz + wx );
371 data[10] = 1 - 2 * ( xx + yy );
384 if ( -1.0f < pValue )
387 return (
float)acos(pValue);
410 rdata[0] = pT *
data[0];
411 rdata[1] = pT *
data[1];
412 rdata[2] = pT *
data[2];
413 rdata[3] = pT *
data[3];
427 T AngleCos = pq.
Dot(*
this);
428 T Angle = qACos(AngleCos);
433 T InvAngleSin = (T)(1.0f / sin(Angle));
435 T Coeff0 = sin((1-pT) * Angle) * InvAngleSin;
436 T Coeff1 = sin(pT * Angle) * InvAngleSin;
Using X files without the sources and the makefile How to use you just create a debug directory e the sample3 directory must contain Sample3 Final Sample3 exe Sample3 Final Debug Sample3 Final Gfx OpenGL bmp Sample3 Final Gfx tiny_skin bmp Sample3 Final Gfx tiny_4anim x The source files have the DevCpp project file plus the makefile The demos use standard FreeGlut functions Technical without warranty Neither Paul Coppens nor GameDev net make any or either express or with respect to the their or fitness for a specific purpose neither Paul Coppens nor GameDev net shall have any liability to you or any other person or entity with respect to any or damage caused or alleged to have been caused directly or indirectly by the programs provided by Paul Coppens and GameDev net This but is not limited interruption of loss of data
Definition: Readme.txt:39
Definition: Frm_3DMath.h:79
void QuaternionMatrix(T &x, T &y, T &z, T &w)
Definition: Frm_3DMath.h:355
T & operator[](int index)
Definition: Frm_3DMath.h:104
vector< T > GetRow(int index)
Definition: Frm_3DMath.h:109
void Zero(void)
Definition: Frm_3DMath.h:92
matrix< T > operator*(matrix< T > &pm)
Definition: Frm_3DMath.h:218
matrix< T > & operator*=(matrix< T > &pm)
matrix(const T *pT)
Definition: Frm_3DMath.h:91
void Identity(void)
Definition: Frm_3DMath.h:93
matrix(const matrix< T > &pm)
Definition: Frm_3DMath.h:90
matrix< T > operator-(matrix< T > &pm)
Definition: Frm_3DMath.h:209
matrix< T > & operator*=(matrix< T > &pm)
Definition: Frm_3DMath.h:233
T data[16]
Definition: Frm_3DMath.h:81
matrix< T > operator+(matrix< T > pm)
Definition: Frm_3DMath.h:241
Array< T, 3 > operator*(const Array< T, 3 > &pV)
matrix< T > & operator=(const matrix< T > &pm)
Definition: Frm_3DMath.h:94
vector< T > GetColumn(int index)
Definition: Frm_3DMath.h:110
matrix< T > operator+(matrix< T > &pm)
Definition: Frm_3DMath.h:200
matrix< T > operator*(matrix< T > pm)
Definition: Frm_3DMath.h:259
T operator()(int pRow, int pCol) const
Definition: Frm_3DMath.h:107
T _fastcall Index(int pRow, int pCol) const
Definition: Frm_3DMath.h:106
matrix(void)
Definition: Frm_3DMath.h:89
matrix< T > operator-(matrix< T > pm)
Definition: Frm_3DMath.h:250
vector< T > operator*(const vector< T > &pV)
T operator[](int index) const
Definition: Frm_3DMath.h:103
T & operator()(int pRow, int pCol)
Definition: Frm_3DMath.h:108
void ScalingMatrix(const vector< T > &pvT)
Definition: Frm_3DMath.h:337
matrix< T > operator*(T pT)
void TranslationMatrix(const Array< T, 3 > &pAT)
Definition: Frm_3DMath.h:346
Definition: Frm_3DMath.h:123
void Zero(void)
Definition: Frm_3DMath.h:129
T data[4]
Definition: Frm_3DMath.h:125
quaternion< T > & operator=(const quaternion< T > &pq)
Definition: Frm_3DMath.h:132
quaternion< T > operator*(T pT)
Definition: Frm_3DMath.h:407
quaternion(const T *pT)
Definition: Frm_3DMath.h:128
quaternion< T > operator*(quaternion< T > pq)
T & operator[](int index)
Definition: Frm_3DMath.h:131
quaternion(const quaternion< T > &pq)
Definition: Frm_3DMath.h:127
quaternion< T > Slerp(T pT, quaternion< T > &pq)
Definition: Frm_3DMath.h:424
T Dot(quaternion< T > &pq)
Definition: Frm_3DMath.h:418
quaternion< T > operator+(quaternion< T > pq)
Definition: Frm_3DMath.h:396
quaternion(void)
Definition: Frm_3DMath.h:126
T operator[](int index) const
Definition: Frm_3DMath.h:130
Definition: Frm_3DMath.h:114
bool _fastcall Union(const trect< T > &prect)
Definition: Frm_3DMath.h:193
trect< T > & operator=(const trect< T > &prect)
Definition: Frm_3DMath.h:152
bool _fastcall InRect(const trect< T > &prect)
Definition: Frm_3DMath.h:180
trect(const T pxs, const T pys, const T pxe, const T pye)
Definition: Frm_3DMath.h:158
trect(void)
Definition: Frm_3DMath.h:149
T ys
Definition: Frm_3DMath.h:116
bool _fastcall InRect(const T &px, const T &py)
Definition: Frm_3DMath.h:162
bool _fastcall InRect(const vector< T > &pv)
Definition: Frm_3DMath.h:168
trect< T > & operator+=(const vector< T > &pV)
Definition: Frm_3DMath.h:154
trect(const trect< T > &prect)
Definition: Frm_3DMath.h:150
bool _fastcall Intersect(const trect< T > &prect)
Definition: Frm_3DMath.h:187
T xs
Definition: Frm_3DMath.h:116
T xe
Definition: Frm_3DMath.h:116
T ye
Definition: Frm_3DMath.h:116
void Set(const T pxs, const T pys, const T pxe, const T pye)
Definition: Frm_3DMath.h:160
Definition: Frm_3DMath.h:16
vector< T > & operator=(const vector< T > &pv)
Definition: Frm_3DMath.h:33
T y
Definition: Frm_3DMath.h:18
T & operator[](int index)
Definition: Frm_3DMath.h:39
vector< T > operator*(T pT) const
Definition: Frm_3DMath.h:43
vector< T > Cross(vector< T > pV) const
Definition: Frm_3DMath.h:47
vector< T > operator-(vector< T > &pv) const
Definition: Frm_3DMath.h:42
bool operator>(const vector< T > &pv)
Definition: Frm_3DMath.h:36
vector(T px, T py, T pz)
Definition: Frm_3DMath.h:29
void Set(T px, T py, T pz)
Definition: Frm_3DMath.h:35
vector< T > operator+(vector< T > pv) const
Definition: Frm_3DMath.h:41
T x
Definition: Frm_3DMath.h:18
vector(const T *&pv)
Definition: Frm_3DMath.h:31
vector(const vector< T > &pv)
Definition: Frm_3DMath.h:30
vector(void)
Definition: Frm_3DMath.h:28
T operator[](int index) const
Definition: Frm_3DMath.h:38
vector< T > UnitCross(vector< T > pV) const
Definition: Frm_3DMath.h:48
T Dot(vector< T > pV) const
Definition: Frm_3DMath.h:46
void Normalize(void)
Definition: Frm_3DMath.h:45
T z
Definition: Frm_3DMath.h:18
Array< T, 2 > Set2(T pu, T pv)
Definition: Frm_3DMath.h:42
Array< T, 3 > Set3(T px, T py, T pz)
Definition: Frm_3DMath.h:39
Array< float, 3 > Vertex
Definition: Frm_3DMath.h:30
Array< float, 4 > Color4
Definition: Frm_3DMath.h:32
Array< T, 4 > Set4(T px, T py, T pz, T pw)
Definition: Frm_3DMath.h:36
Array< float, 2 > TCoord
Definition: Frm_3DMath.h:31
matrix< float > Matrix
Definition: Frm_3DMath.h:119
Array< float, 3 > Color3
Definition: Frm_3DMath.h:33
quaternion< float > Quaternion
Definition: Frm_3DMath.h:142
Array< unsigned short, 3 > Face
Definition: Frm_3DMath.h:58
vector< float > Vector
Definition: Frm_3DMath.h:51
#define MINFLOAT
Definition: Frm_3DMath.h:16
#define M_PI
Definition: Frm_3DMath.h:18
uint16 index
Definition: sample3.cpp:29
Definition: Frm_3DMath.h:15
Array(const T *pT)
Definition: Frm_3DMath.h:58
Array< T, size > operator+(Array< T, size > &pA)
Definition: Frm_3DMath.h:65
Array(void)
Definition: Frm_3DMath.h:56
Array< T, size > & operator=(Array< T, size > pA)
Definition: Frm_3DMath.h:60
Array< T, size > operator*(const T pScalar)
Definition: Frm_3DMath.h:181
Array< T, size > operator+(Array< T, size > pA)
Definition: Frm_3DMath.h:223
Array< T, size > & operator+=(Array< T, size > pA)
Definition: Frm_3DMath.h:205
T data[size]
Definition: Frm_3DMath.h:16
Array< T, size > operator*(const T pScalar)
T & operator[](int index)
Definition: Frm_3DMath.h:67
T operator[](int index) const
Definition: Frm_3DMath.h:66
Array(const Array< T, size > &pA)
Definition: Frm_3DMath.h:57
Array< T, size > operator-(Array< T, size > pA)
Definition: Frm_3DMath.h:232
Array< T, size > & operator+=(Array< T, size > &pA)
Definition: Frm_3DMath.h:47