12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228 |
- //////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (C) Microsoft Corporation. All Rights Reserved.
- //
- // File: d3dx10math.inl
- // Content: D3DX10 math inline functions
- //
- //////////////////////////////////////////////////////////////////////////////
- #ifndef __D3DXMATH_INL__
- #define __D3DXMATH_INL__
- //===========================================================================
- //
- // Inline Class Methods
- //
- //===========================================================================
- #ifdef __cplusplus
- //--------------------------
- // Float16
- //--------------------------
- D3DX10INLINE
- D3DXFLOAT16::D3DXFLOAT16( FLOAT f )
- {
- D3DXFloat32To16Array(this, &f, 1);
- }
- D3DX10INLINE
- D3DXFLOAT16::D3DXFLOAT16( CONST D3DXFLOAT16& f )
- {
- value = f.value;
- }
- // casting
- D3DX10INLINE
- D3DXFLOAT16::operator FLOAT ()
- {
- FLOAT f;
- D3DXFloat16To32Array(&f, this, 1);
- return f;
- }
- // binary operators
- D3DX10INLINE BOOL
- D3DXFLOAT16::operator == ( CONST D3DXFLOAT16& f ) const
- {
- // At least one is NaN
- if(((value & D3DX_16F_EXP_MASK) == D3DX_16F_EXP_MASK && (value & D3DX_16F_FRAC_MASK))
- || ((f.value & D3DX_16F_EXP_MASK) == D3DX_16F_EXP_MASK && (f.value & D3DX_16F_FRAC_MASK)))
- return false;
- // +/- Zero
- else if((value & ~D3DX_16F_SIGN_MASK) == 0 && (f.value & ~D3DX_16F_SIGN_MASK) == 0)
- return true;
- else
- return value == f.value;
- }
- D3DX10INLINE BOOL
- D3DXFLOAT16::operator != ( CONST D3DXFLOAT16& f ) const
- {
- // At least one is NaN
- if(((value & D3DX_16F_EXP_MASK) == D3DX_16F_EXP_MASK && (value & D3DX_16F_FRAC_MASK))
- || ((f.value & D3DX_16F_EXP_MASK) == D3DX_16F_EXP_MASK && (f.value & D3DX_16F_FRAC_MASK)))
- return true;
- // +/- Zero
- else if((value & ~D3DX_16F_SIGN_MASK) == 0 && (f.value & ~D3DX_16F_SIGN_MASK) == 0)
- return false;
- else
- return value != f.value;
- }
- //--------------------------
- // 2D Vector
- //--------------------------
- D3DX10INLINE
- D3DXVECTOR2::D3DXVECTOR2( CONST FLOAT *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- x = pf[0];
- y = pf[1];
- }
- D3DX10INLINE
- D3DXVECTOR2::D3DXVECTOR2( CONST D3DXFLOAT16 *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&x, pf, 2);
- }
- D3DX10INLINE
- D3DXVECTOR2::D3DXVECTOR2( FLOAT fx, FLOAT fy )
- {
- x = fx;
- y = fy;
- }
- // casting
- D3DX10INLINE
- D3DXVECTOR2::operator FLOAT* ()
- {
- return (FLOAT *) &x;
- }
- D3DX10INLINE
- D3DXVECTOR2::operator CONST FLOAT* () const
- {
- return (CONST FLOAT *) &x;
- }
- // assignment operators
- D3DX10INLINE D3DXVECTOR2&
- D3DXVECTOR2::operator += ( CONST D3DXVECTOR2& v )
- {
- x += v.x;
- y += v.y;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR2&
- D3DXVECTOR2::operator -= ( CONST D3DXVECTOR2& v )
- {
- x -= v.x;
- y -= v.y;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR2&
- D3DXVECTOR2::operator *= ( FLOAT f )
- {
- x *= f;
- y *= f;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR2&
- D3DXVECTOR2::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- x *= fInv;
- y *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXVECTOR2
- D3DXVECTOR2::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXVECTOR2
- D3DXVECTOR2::operator - () const
- {
- return D3DXVECTOR2(-x, -y);
- }
- // binary operators
- D3DX10INLINE D3DXVECTOR2
- D3DXVECTOR2::operator + ( CONST D3DXVECTOR2& v ) const
- {
- return D3DXVECTOR2(x + v.x, y + v.y);
- }
- D3DX10INLINE D3DXVECTOR2
- D3DXVECTOR2::operator - ( CONST D3DXVECTOR2& v ) const
- {
- return D3DXVECTOR2(x - v.x, y - v.y);
- }
- D3DX10INLINE D3DXVECTOR2
- D3DXVECTOR2::operator * ( FLOAT f ) const
- {
- return D3DXVECTOR2(x * f, y * f);
- }
- D3DX10INLINE D3DXVECTOR2
- D3DXVECTOR2::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXVECTOR2(x * fInv, y * fInv);
- }
- D3DX10INLINE D3DXVECTOR2
- operator * ( FLOAT f, CONST D3DXVECTOR2& v )
- {
- return D3DXVECTOR2(f * v.x, f * v.y);
- }
- D3DX10INLINE BOOL
- D3DXVECTOR2::operator == ( CONST D3DXVECTOR2& v ) const
- {
- return x == v.x && y == v.y;
- }
- D3DX10INLINE BOOL
- D3DXVECTOR2::operator != ( CONST D3DXVECTOR2& v ) const
- {
- return x != v.x || y != v.y;
- }
- //--------------------------
- // 2D Vector (16 bit)
- //--------------------------
- D3DX10INLINE
- D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST FLOAT *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat32To16Array(&x, pf, 2);
- }
- D3DX10INLINE
- D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- *((UINT *) &x) = *((UINT *) &pf[0]);
- }
- D3DX10INLINE
- D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy )
- {
- x = fx;
- y = fy;
- }
- // casting
- D3DX10INLINE
- D3DXVECTOR2_16F::operator D3DXFLOAT16* ()
- {
- return (D3DXFLOAT16*) &x;
- }
- D3DX10INLINE
- D3DXVECTOR2_16F::operator CONST D3DXFLOAT16* () const
- {
- return (CONST D3DXFLOAT16*) &x;
- }
- // binary operators
- D3DX10INLINE BOOL
- D3DXVECTOR2_16F::operator == ( CONST D3DXVECTOR2_16F &v ) const
- {
- return x == v.x && y == v.y;
- }
- D3DX10INLINE BOOL
- D3DXVECTOR2_16F::operator != ( CONST D3DXVECTOR2_16F &v ) const
- {
- return x != v.x || y != v.y;
- }
- //--------------------------
- // 3D Vector
- //--------------------------
- D3DX10INLINE
- D3DXVECTOR3::D3DXVECTOR3( CONST FLOAT *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- x = pf[0];
- y = pf[1];
- z = pf[2];
- }
- D3DX10INLINE
- D3DXVECTOR3::D3DXVECTOR3( CONST D3DVECTOR& v )
- {
- x = v.x;
- y = v.y;
- z = v.z;
- }
- D3DX10INLINE
- D3DXVECTOR3::D3DXVECTOR3( CONST D3DXFLOAT16 *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&x, pf, 3);
- }
- D3DX10INLINE
- D3DXVECTOR3::D3DXVECTOR3( FLOAT fx, FLOAT fy, FLOAT fz )
- {
- x = fx;
- y = fy;
- z = fz;
- }
- // casting
- D3DX10INLINE
- D3DXVECTOR3::operator FLOAT* ()
- {
- return (FLOAT *) &x;
- }
- D3DX10INLINE
- D3DXVECTOR3::operator CONST FLOAT* () const
- {
- return (CONST FLOAT *) &x;
- }
- // assignment operators
- D3DX10INLINE D3DXVECTOR3&
- D3DXVECTOR3::operator += ( CONST D3DXVECTOR3& v )
- {
- x += v.x;
- y += v.y;
- z += v.z;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR3&
- D3DXVECTOR3::operator -= ( CONST D3DXVECTOR3& v )
- {
- x -= v.x;
- y -= v.y;
- z -= v.z;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR3&
- D3DXVECTOR3::operator *= ( FLOAT f )
- {
- x *= f;
- y *= f;
- z *= f;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR3&
- D3DXVECTOR3::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- x *= fInv;
- y *= fInv;
- z *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXVECTOR3
- D3DXVECTOR3::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXVECTOR3
- D3DXVECTOR3::operator - () const
- {
- return D3DXVECTOR3(-x, -y, -z);
- }
- // binary operators
- D3DX10INLINE D3DXVECTOR3
- D3DXVECTOR3::operator + ( CONST D3DXVECTOR3& v ) const
- {
- return D3DXVECTOR3(x + v.x, y + v.y, z + v.z);
- }
- D3DX10INLINE D3DXVECTOR3
- D3DXVECTOR3::operator - ( CONST D3DXVECTOR3& v ) const
- {
- return D3DXVECTOR3(x - v.x, y - v.y, z - v.z);
- }
- D3DX10INLINE D3DXVECTOR3
- D3DXVECTOR3::operator * ( FLOAT f ) const
- {
- return D3DXVECTOR3(x * f, y * f, z * f);
- }
- D3DX10INLINE D3DXVECTOR3
- D3DXVECTOR3::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXVECTOR3(x * fInv, y * fInv, z * fInv);
- }
- D3DX10INLINE D3DXVECTOR3
- operator * ( FLOAT f, CONST struct D3DXVECTOR3& v )
- {
- return D3DXVECTOR3(f * v.x, f * v.y, f * v.z);
- }
- D3DX10INLINE BOOL
- D3DXVECTOR3::operator == ( CONST D3DXVECTOR3& v ) const
- {
- return x == v.x && y == v.y && z == v.z;
- }
- D3DX10INLINE BOOL
- D3DXVECTOR3::operator != ( CONST D3DXVECTOR3& v ) const
- {
- return x != v.x || y != v.y || z != v.z;
- }
- //--------------------------
- // 3D Vector (16 bit)
- //--------------------------
- D3DX10INLINE
- D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST FLOAT *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat32To16Array(&x, pf, 3);
- }
- D3DX10INLINE
- D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DVECTOR& v )
- {
- D3DXFloat32To16Array(&x, &v.x, 1);
- D3DXFloat32To16Array(&y, &v.y, 1);
- D3DXFloat32To16Array(&z, &v.z, 1);
- }
- D3DX10INLINE
- D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- *((UINT *) &x) = *((UINT *) &pf[0]);
- *((WORD *) &z) = *((WORD *) &pf[2]);
- }
- D3DX10INLINE
- D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz )
- {
- x = fx;
- y = fy;
- z = fz;
- }
- // casting
- D3DX10INLINE
- D3DXVECTOR3_16F::operator D3DXFLOAT16* ()
- {
- return (D3DXFLOAT16*) &x;
- }
- D3DX10INLINE
- D3DXVECTOR3_16F::operator CONST D3DXFLOAT16* () const
- {
- return (CONST D3DXFLOAT16*) &x;
- }
- // binary operators
- D3DX10INLINE BOOL
- D3DXVECTOR3_16F::operator == ( CONST D3DXVECTOR3_16F &v ) const
- {
- return x == v.x && y == v.y && z == v.z;
- }
- D3DX10INLINE BOOL
- D3DXVECTOR3_16F::operator != ( CONST D3DXVECTOR3_16F &v ) const
- {
- return x != v.x || y != v.y || z != v.z;
- }
- //--------------------------
- // 4D Vector
- //--------------------------
- D3DX10INLINE
- D3DXVECTOR4::D3DXVECTOR4( CONST FLOAT *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- x = pf[0];
- y = pf[1];
- z = pf[2];
- w = pf[3];
- }
- D3DX10INLINE
- D3DXVECTOR4::D3DXVECTOR4( CONST D3DXFLOAT16 *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&x, pf, 4);
- }
- D3DX10INLINE
- D3DXVECTOR4::D3DXVECTOR4( CONST D3DVECTOR& v, FLOAT f )
- {
- x = v.x;
- y = v.y;
- z = v.z;
- w = f;
- }
- D3DX10INLINE
- D3DXVECTOR4::D3DXVECTOR4( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw )
- {
- x = fx;
- y = fy;
- z = fz;
- w = fw;
- }
- // casting
- D3DX10INLINE
- D3DXVECTOR4::operator FLOAT* ()
- {
- return (FLOAT *) &x;
- }
- D3DX10INLINE
- D3DXVECTOR4::operator CONST FLOAT* () const
- {
- return (CONST FLOAT *) &x;
- }
- // assignment operators
- D3DX10INLINE D3DXVECTOR4&
- D3DXVECTOR4::operator += ( CONST D3DXVECTOR4& v )
- {
- x += v.x;
- y += v.y;
- z += v.z;
- w += v.w;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR4&
- D3DXVECTOR4::operator -= ( CONST D3DXVECTOR4& v )
- {
- x -= v.x;
- y -= v.y;
- z -= v.z;
- w -= v.w;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR4&
- D3DXVECTOR4::operator *= ( FLOAT f )
- {
- x *= f;
- y *= f;
- z *= f;
- w *= f;
- return *this;
- }
- D3DX10INLINE D3DXVECTOR4&
- D3DXVECTOR4::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- x *= fInv;
- y *= fInv;
- z *= fInv;
- w *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXVECTOR4
- D3DXVECTOR4::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXVECTOR4
- D3DXVECTOR4::operator - () const
- {
- return D3DXVECTOR4(-x, -y, -z, -w);
- }
- // binary operators
- D3DX10INLINE D3DXVECTOR4
- D3DXVECTOR4::operator + ( CONST D3DXVECTOR4& v ) const
- {
- return D3DXVECTOR4(x + v.x, y + v.y, z + v.z, w + v.w);
- }
- D3DX10INLINE D3DXVECTOR4
- D3DXVECTOR4::operator - ( CONST D3DXVECTOR4& v ) const
- {
- return D3DXVECTOR4(x - v.x, y - v.y, z - v.z, w - v.w);
- }
- D3DX10INLINE D3DXVECTOR4
- D3DXVECTOR4::operator * ( FLOAT f ) const
- {
- return D3DXVECTOR4(x * f, y * f, z * f, w * f);
- }
- D3DX10INLINE D3DXVECTOR4
- D3DXVECTOR4::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXVECTOR4(x * fInv, y * fInv, z * fInv, w * fInv);
- }
- D3DX10INLINE D3DXVECTOR4
- operator * ( FLOAT f, CONST D3DXVECTOR4& v )
- {
- return D3DXVECTOR4(f * v.x, f * v.y, f * v.z, f * v.w);
- }
- D3DX10INLINE BOOL
- D3DXVECTOR4::operator == ( CONST D3DXVECTOR4& v ) const
- {
- return x == v.x && y == v.y && z == v.z && w == v.w;
- }
- D3DX10INLINE BOOL
- D3DXVECTOR4::operator != ( CONST D3DXVECTOR4& v ) const
- {
- return x != v.x || y != v.y || z != v.z || w != v.w;
- }
- //--------------------------
- // 4D Vector (16 bit)
- //--------------------------
- D3DX10INLINE
- D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST FLOAT *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat32To16Array(&x, pf, 4);
- }
- D3DX10INLINE
- D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 *pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- *((UINT *) &x) = *((UINT *) &pf[0]);
- *((UINT *) &z) = *((UINT *) &pf[2]);
- }
- D3DX10INLINE
- D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXVECTOR3_16F& v, CONST D3DXFLOAT16& f )
- {
- x = v.x;
- y = v.y;
- z = v.z;
- w = f;
- }
- D3DX10INLINE
- D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz, CONST D3DXFLOAT16 &fw )
- {
- x = fx;
- y = fy;
- z = fz;
- w = fw;
- }
- // casting
- D3DX10INLINE
- D3DXVECTOR4_16F::operator D3DXFLOAT16* ()
- {
- return (D3DXFLOAT16*) &x;
- }
- D3DX10INLINE
- D3DXVECTOR4_16F::operator CONST D3DXFLOAT16* () const
- {
- return (CONST D3DXFLOAT16*) &x;
- }
- // binary operators
- D3DX10INLINE BOOL
- D3DXVECTOR4_16F::operator == ( CONST D3DXVECTOR4_16F &v ) const
- {
- return x == v.x && y == v.y && z == v.z && w == v.w;
- }
- D3DX10INLINE BOOL
- D3DXVECTOR4_16F::operator != ( CONST D3DXVECTOR4_16F &v ) const
- {
- return x != v.x || y != v.y || z != v.z || w != v.w;
- }
- //--------------------------
- // Matrix
- //--------------------------
- D3DX10INLINE
- D3DXMATRIX::D3DXMATRIX( CONST FLOAT* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- memcpy(&_11, pf, sizeof(D3DXMATRIX));
- }
- D3DX10INLINE
- D3DXMATRIX::D3DXMATRIX( CONST D3DMATRIX& mat )
- {
- memcpy(&_11, &mat, sizeof(D3DXMATRIX));
- }
- D3DX10INLINE
- D3DXMATRIX::D3DXMATRIX( CONST D3DXFLOAT16* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&_11, pf, 16);
- }
- D3DX10INLINE
- D3DXMATRIX::D3DXMATRIX( FLOAT f11, FLOAT f12, FLOAT f13, FLOAT f14,
- FLOAT f21, FLOAT f22, FLOAT f23, FLOAT f24,
- FLOAT f31, FLOAT f32, FLOAT f33, FLOAT f34,
- FLOAT f41, FLOAT f42, FLOAT f43, FLOAT f44 )
- {
- _11 = f11; _12 = f12; _13 = f13; _14 = f14;
- _21 = f21; _22 = f22; _23 = f23; _24 = f24;
- _31 = f31; _32 = f32; _33 = f33; _34 = f34;
- _41 = f41; _42 = f42; _43 = f43; _44 = f44;
- }
- // access grants
- D3DX10INLINE FLOAT&
- D3DXMATRIX::operator () ( UINT iRow, UINT iCol )
- {
- return m[iRow][iCol];
- }
- D3DX10INLINE FLOAT
- D3DXMATRIX::operator () ( UINT iRow, UINT iCol ) const
- {
- return m[iRow][iCol];
- }
- // casting operators
- D3DX10INLINE
- D3DXMATRIX::operator FLOAT* ()
- {
- return (FLOAT *) &_11;
- }
- D3DX10INLINE
- D3DXMATRIX::operator CONST FLOAT* () const
- {
- return (CONST FLOAT *) &_11;
- }
- // assignment operators
- D3DX10INLINE D3DXMATRIX&
- D3DXMATRIX::operator *= ( CONST D3DXMATRIX& mat )
- {
- D3DXMatrixMultiply(this, this, &mat);
- return *this;
- }
- D3DX10INLINE D3DXMATRIX&
- D3DXMATRIX::operator += ( CONST D3DXMATRIX& mat )
- {
- _11 += mat._11; _12 += mat._12; _13 += mat._13; _14 += mat._14;
- _21 += mat._21; _22 += mat._22; _23 += mat._23; _24 += mat._24;
- _31 += mat._31; _32 += mat._32; _33 += mat._33; _34 += mat._34;
- _41 += mat._41; _42 += mat._42; _43 += mat._43; _44 += mat._44;
- return *this;
- }
- D3DX10INLINE D3DXMATRIX&
- D3DXMATRIX::operator -= ( CONST D3DXMATRIX& mat )
- {
- _11 -= mat._11; _12 -= mat._12; _13 -= mat._13; _14 -= mat._14;
- _21 -= mat._21; _22 -= mat._22; _23 -= mat._23; _24 -= mat._24;
- _31 -= mat._31; _32 -= mat._32; _33 -= mat._33; _34 -= mat._34;
- _41 -= mat._41; _42 -= mat._42; _43 -= mat._43; _44 -= mat._44;
- return *this;
- }
- D3DX10INLINE D3DXMATRIX&
- D3DXMATRIX::operator *= ( FLOAT f )
- {
- _11 *= f; _12 *= f; _13 *= f; _14 *= f;
- _21 *= f; _22 *= f; _23 *= f; _24 *= f;
- _31 *= f; _32 *= f; _33 *= f; _34 *= f;
- _41 *= f; _42 *= f; _43 *= f; _44 *= f;
- return *this;
- }
- D3DX10INLINE D3DXMATRIX&
- D3DXMATRIX::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- _11 *= fInv; _12 *= fInv; _13 *= fInv; _14 *= fInv;
- _21 *= fInv; _22 *= fInv; _23 *= fInv; _24 *= fInv;
- _31 *= fInv; _32 *= fInv; _33 *= fInv; _34 *= fInv;
- _41 *= fInv; _42 *= fInv; _43 *= fInv; _44 *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator - () const
- {
- return D3DXMATRIX(-_11, -_12, -_13, -_14,
- -_21, -_22, -_23, -_24,
- -_31, -_32, -_33, -_34,
- -_41, -_42, -_43, -_44);
- }
- // binary operators
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator * ( CONST D3DXMATRIX& mat ) const
- {
- D3DXMATRIX matT;
- D3DXMatrixMultiply(&matT, this, &mat);
- return matT;
- }
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator + ( CONST D3DXMATRIX& mat ) const
- {
- return D3DXMATRIX(_11 + mat._11, _12 + mat._12, _13 + mat._13, _14 + mat._14,
- _21 + mat._21, _22 + mat._22, _23 + mat._23, _24 + mat._24,
- _31 + mat._31, _32 + mat._32, _33 + mat._33, _34 + mat._34,
- _41 + mat._41, _42 + mat._42, _43 + mat._43, _44 + mat._44);
- }
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator - ( CONST D3DXMATRIX& mat ) const
- {
- return D3DXMATRIX(_11 - mat._11, _12 - mat._12, _13 - mat._13, _14 - mat._14,
- _21 - mat._21, _22 - mat._22, _23 - mat._23, _24 - mat._24,
- _31 - mat._31, _32 - mat._32, _33 - mat._33, _34 - mat._34,
- _41 - mat._41, _42 - mat._42, _43 - mat._43, _44 - mat._44);
- }
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator * ( FLOAT f ) const
- {
- return D3DXMATRIX(_11 * f, _12 * f, _13 * f, _14 * f,
- _21 * f, _22 * f, _23 * f, _24 * f,
- _31 * f, _32 * f, _33 * f, _34 * f,
- _41 * f, _42 * f, _43 * f, _44 * f);
- }
- D3DX10INLINE D3DXMATRIX
- D3DXMATRIX::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXMATRIX(_11 * fInv, _12 * fInv, _13 * fInv, _14 * fInv,
- _21 * fInv, _22 * fInv, _23 * fInv, _24 * fInv,
- _31 * fInv, _32 * fInv, _33 * fInv, _34 * fInv,
- _41 * fInv, _42 * fInv, _43 * fInv, _44 * fInv);
- }
- D3DX10INLINE D3DXMATRIX
- operator * ( FLOAT f, CONST D3DXMATRIX& mat )
- {
- return D3DXMATRIX(f * mat._11, f * mat._12, f * mat._13, f * mat._14,
- f * mat._21, f * mat._22, f * mat._23, f * mat._24,
- f * mat._31, f * mat._32, f * mat._33, f * mat._34,
- f * mat._41, f * mat._42, f * mat._43, f * mat._44);
- }
- D3DX10INLINE BOOL
- D3DXMATRIX::operator == ( CONST D3DXMATRIX& mat ) const
- {
- return 0 == memcmp(this, &mat, sizeof(D3DXMATRIX));
- }
- D3DX10INLINE BOOL
- D3DXMATRIX::operator != ( CONST D3DXMATRIX& mat ) const
- {
- return 0 != memcmp(this, &mat, sizeof(D3DXMATRIX));
- }
- //--------------------------
- // Aligned Matrices
- //--------------------------
- D3DX10INLINE
- _D3DXMATRIXA16::_D3DXMATRIXA16( CONST FLOAT* f ) :
- D3DXMATRIX( f )
- {
- }
- D3DX10INLINE
- _D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DMATRIX& m ) :
- D3DXMATRIX( m )
- {
- }
- D3DX10INLINE
- _D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DXFLOAT16* f ) :
- D3DXMATRIX( f )
- {
- }
- D3DX10INLINE
- _D3DXMATRIXA16::_D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
- FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
- FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
- FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ) :
- D3DXMATRIX(_11, _12, _13, _14,
- _21, _22, _23, _24,
- _31, _32, _33, _34,
- _41, _42, _43, _44)
- {
- }
- #ifndef SIZE_MAX
- #define SIZE_MAX ((SIZE_T)-1)
- #endif
- D3DX10INLINE void*
- _D3DXMATRIXA16::operator new( size_t s )
- {
- if (s > (SIZE_MAX-16))
- return NULL;
- LPBYTE p = ::new BYTE[s + 16];
- if (p)
- {
- BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
- p += offset;
- p[-1] = offset;
- }
- return p;
- }
- D3DX10INLINE void*
- _D3DXMATRIXA16::operator new[]( size_t s )
- {
- if (s > (SIZE_MAX-16))
- return NULL;
- LPBYTE p = ::new BYTE[s + 16];
- if (p)
- {
- BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
- p += offset;
- p[-1] = offset;
- }
- return p;
- }
- D3DX10INLINE void
- _D3DXMATRIXA16::operator delete(void* p)
- {
- if(p)
- {
- BYTE* pb = static_cast<BYTE*>(p);
- pb -= pb[-1];
- ::delete [] pb;
- }
- }
- D3DX10INLINE void
- _D3DXMATRIXA16::operator delete[](void* p)
- {
- if(p)
- {
- BYTE* pb = static_cast<BYTE*>(p);
- pb -= pb[-1];
- ::delete [] pb;
- }
- }
- D3DX10INLINE _D3DXMATRIXA16&
- _D3DXMATRIXA16::operator=(CONST D3DXMATRIX& rhs)
- {
- memcpy(&_11, &rhs, sizeof(D3DXMATRIX));
- return *this;
- }
- //--------------------------
- // Quaternion
- //--------------------------
- D3DX10INLINE
- D3DXQUATERNION::D3DXQUATERNION( CONST FLOAT* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- x = pf[0];
- y = pf[1];
- z = pf[2];
- w = pf[3];
- }
- D3DX10INLINE
- D3DXQUATERNION::D3DXQUATERNION( CONST D3DXFLOAT16* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&x, pf, 4);
- }
- D3DX10INLINE
- D3DXQUATERNION::D3DXQUATERNION( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw )
- {
- x = fx;
- y = fy;
- z = fz;
- w = fw;
- }
- // casting
- D3DX10INLINE
- D3DXQUATERNION::operator FLOAT* ()
- {
- return (FLOAT *) &x;
- }
- D3DX10INLINE
- D3DXQUATERNION::operator CONST FLOAT* () const
- {
- return (CONST FLOAT *) &x;
- }
- // assignment operators
- D3DX10INLINE D3DXQUATERNION&
- D3DXQUATERNION::operator += ( CONST D3DXQUATERNION& q )
- {
- x += q.x;
- y += q.y;
- z += q.z;
- w += q.w;
- return *this;
- }
- D3DX10INLINE D3DXQUATERNION&
- D3DXQUATERNION::operator -= ( CONST D3DXQUATERNION& q )
- {
- x -= q.x;
- y -= q.y;
- z -= q.z;
- w -= q.w;
- return *this;
- }
- D3DX10INLINE D3DXQUATERNION&
- D3DXQUATERNION::operator *= ( CONST D3DXQUATERNION& q )
- {
- D3DXQuaternionMultiply(this, this, &q);
- return *this;
- }
- D3DX10INLINE D3DXQUATERNION&
- D3DXQUATERNION::operator *= ( FLOAT f )
- {
- x *= f;
- y *= f;
- z *= f;
- w *= f;
- return *this;
- }
- D3DX10INLINE D3DXQUATERNION&
- D3DXQUATERNION::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- x *= fInv;
- y *= fInv;
- z *= fInv;
- w *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator - () const
- {
- return D3DXQUATERNION(-x, -y, -z, -w);
- }
- // binary operators
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator + ( CONST D3DXQUATERNION& q ) const
- {
- return D3DXQUATERNION(x + q.x, y + q.y, z + q.z, w + q.w);
- }
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator - ( CONST D3DXQUATERNION& q ) const
- {
- return D3DXQUATERNION(x - q.x, y - q.y, z - q.z, w - q.w);
- }
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator * ( CONST D3DXQUATERNION& q ) const
- {
- D3DXQUATERNION qT;
- D3DXQuaternionMultiply(&qT, this, &q);
- return qT;
- }
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator * ( FLOAT f ) const
- {
- return D3DXQUATERNION(x * f, y * f, z * f, w * f);
- }
- D3DX10INLINE D3DXQUATERNION
- D3DXQUATERNION::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXQUATERNION(x * fInv, y * fInv, z * fInv, w * fInv);
- }
- D3DX10INLINE D3DXQUATERNION
- operator * (FLOAT f, CONST D3DXQUATERNION& q )
- {
- return D3DXQUATERNION(f * q.x, f * q.y, f * q.z, f * q.w);
- }
- D3DX10INLINE BOOL
- D3DXQUATERNION::operator == ( CONST D3DXQUATERNION& q ) const
- {
- return x == q.x && y == q.y && z == q.z && w == q.w;
- }
- D3DX10INLINE BOOL
- D3DXQUATERNION::operator != ( CONST D3DXQUATERNION& q ) const
- {
- return x != q.x || y != q.y || z != q.z || w != q.w;
- }
- //--------------------------
- // Plane
- //--------------------------
- D3DX10INLINE
- D3DXPLANE::D3DXPLANE( CONST FLOAT* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- a = pf[0];
- b = pf[1];
- c = pf[2];
- d = pf[3];
- }
- D3DX10INLINE
- D3DXPLANE::D3DXPLANE( CONST D3DXFLOAT16* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&a, pf, 4);
- }
- D3DX10INLINE
- D3DXPLANE::D3DXPLANE( FLOAT fa, FLOAT fb, FLOAT fc, FLOAT fd )
- {
- a = fa;
- b = fb;
- c = fc;
- d = fd;
- }
- // casting
- D3DX10INLINE
- D3DXPLANE::operator FLOAT* ()
- {
- return (FLOAT *) &a;
- }
- D3DX10INLINE
- D3DXPLANE::operator CONST FLOAT* () const
- {
- return (CONST FLOAT *) &a;
- }
- // assignment operators
- D3DX10INLINE D3DXPLANE&
- D3DXPLANE::operator *= ( FLOAT f )
- {
- a *= f;
- b *= f;
- c *= f;
- d *= f;
- return *this;
- }
- D3DX10INLINE D3DXPLANE&
- D3DXPLANE::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- a *= fInv;
- b *= fInv;
- c *= fInv;
- d *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXPLANE
- D3DXPLANE::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXPLANE
- D3DXPLANE::operator - () const
- {
- return D3DXPLANE(-a, -b, -c, -d);
- }
- // binary operators
- D3DX10INLINE D3DXPLANE
- D3DXPLANE::operator * ( FLOAT f ) const
- {
- return D3DXPLANE(a * f, b * f, c * f, d * f);
- }
- D3DX10INLINE D3DXPLANE
- D3DXPLANE::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXPLANE(a * fInv, b * fInv, c * fInv, d * fInv);
- }
- D3DX10INLINE D3DXPLANE
- operator * (FLOAT f, CONST D3DXPLANE& p )
- {
- return D3DXPLANE(f * p.a, f * p.b, f * p.c, f * p.d);
- }
- D3DX10INLINE BOOL
- D3DXPLANE::operator == ( CONST D3DXPLANE& p ) const
- {
- return a == p.a && b == p.b && c == p.c && d == p.d;
- }
- D3DX10INLINE BOOL
- D3DXPLANE::operator != ( CONST D3DXPLANE& p ) const
- {
- return a != p.a || b != p.b || c != p.c || d != p.d;
- }
- //--------------------------
- // Color
- //--------------------------
- D3DX10INLINE
- D3DXCOLOR::D3DXCOLOR( UINT dw )
- {
- CONST FLOAT f = 1.0f / 255.0f;
- r = f * (FLOAT) (unsigned char) (dw >> 16);
- g = f * (FLOAT) (unsigned char) (dw >> 8);
- b = f * (FLOAT) (unsigned char) (dw >> 0);
- a = f * (FLOAT) (unsigned char) (dw >> 24);
- }
- D3DX10INLINE
- D3DXCOLOR::D3DXCOLOR( CONST FLOAT* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- r = pf[0];
- g = pf[1];
- b = pf[2];
- a = pf[3];
- }
- D3DX10INLINE
- D3DXCOLOR::D3DXCOLOR( CONST D3DXFLOAT16* pf )
- {
- #ifdef D3DX10_DEBUG
- if(!pf)
- return;
- #endif
- D3DXFloat16To32Array(&r, pf, 4);
- }
- D3DX10INLINE
- D3DXCOLOR::D3DXCOLOR( FLOAT fr, FLOAT fg, FLOAT fb, FLOAT fa )
- {
- r = fr;
- g = fg;
- b = fb;
- a = fa;
- }
- // casting
- D3DX10INLINE
- D3DXCOLOR::operator UINT () const
- {
- UINT dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (UINT) (r * 255.0f + 0.5f);
- UINT dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (UINT) (g * 255.0f + 0.5f);
- UINT dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (UINT) (b * 255.0f + 0.5f);
- UINT dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (UINT) (a * 255.0f + 0.5f);
- return (dwA << 24) | (dwR << 16) | (dwG << 8) | (dwB << 0);
- }
- D3DX10INLINE
- D3DXCOLOR::operator FLOAT * ()
- {
- return (FLOAT *) &r;
- }
- D3DX10INLINE
- D3DXCOLOR::operator CONST FLOAT * () const
- {
- return (CONST FLOAT *) &r;
- }
- // assignment operators
- D3DX10INLINE D3DXCOLOR&
- D3DXCOLOR::operator += ( CONST D3DXCOLOR& c )
- {
- r += c.r;
- g += c.g;
- b += c.b;
- a += c.a;
- return *this;
- }
- D3DX10INLINE D3DXCOLOR&
- D3DXCOLOR::operator -= ( CONST D3DXCOLOR& c )
- {
- r -= c.r;
- g -= c.g;
- b -= c.b;
- a -= c.a;
- return *this;
- }
- D3DX10INLINE D3DXCOLOR&
- D3DXCOLOR::operator *= ( FLOAT f )
- {
- r *= f;
- g *= f;
- b *= f;
- a *= f;
- return *this;
- }
- D3DX10INLINE D3DXCOLOR&
- D3DXCOLOR::operator /= ( FLOAT f )
- {
- FLOAT fInv = 1.0f / f;
- r *= fInv;
- g *= fInv;
- b *= fInv;
- a *= fInv;
- return *this;
- }
- // unary operators
- D3DX10INLINE D3DXCOLOR
- D3DXCOLOR::operator + () const
- {
- return *this;
- }
- D3DX10INLINE D3DXCOLOR
- D3DXCOLOR::operator - () const
- {
- return D3DXCOLOR(-r, -g, -b, -a);
- }
- // binary operators
- D3DX10INLINE D3DXCOLOR
- D3DXCOLOR::operator + ( CONST D3DXCOLOR& c ) const
- {
- return D3DXCOLOR(r + c.r, g + c.g, b + c.b, a + c.a);
- }
- D3DX10INLINE D3DXCOLOR
- D3DXCOLOR::operator - ( CONST D3DXCOLOR& c ) const
- {
- return D3DXCOLOR(r - c.r, g - c.g, b - c.b, a - c.a);
- }
- D3DX10INLINE D3DXCOLOR
- D3DXCOLOR::operator * ( FLOAT f ) const
- {
- return D3DXCOLOR(r * f, g * f, b * f, a * f);
- }
- D3DX10INLINE D3DXCOLOR
- D3DXCOLOR::operator / ( FLOAT f ) const
- {
- FLOAT fInv = 1.0f / f;
- return D3DXCOLOR(r * fInv, g * fInv, b * fInv, a * fInv);
- }
- D3DX10INLINE D3DXCOLOR
- operator * (FLOAT f, CONST D3DXCOLOR& c )
- {
- return D3DXCOLOR(f * c.r, f * c.g, f * c.b, f * c.a);
- }
- D3DX10INLINE BOOL
- D3DXCOLOR::operator == ( CONST D3DXCOLOR& c ) const
- {
- return r == c.r && g == c.g && b == c.b && a == c.a;
- }
- D3DX10INLINE BOOL
- D3DXCOLOR::operator != ( CONST D3DXCOLOR& c ) const
- {
- return r != c.r || g != c.g || b != c.b || a != c.a;
- }
- #endif //__cplusplus
- //===========================================================================
- //
- // Inline functions
- //
- //===========================================================================
- //--------------------------
- // 2D Vector
- //--------------------------
- D3DX10INLINE FLOAT D3DXVec2Length
- ( CONST D3DXVECTOR2 *pV )
- {
- #ifdef D3DX10_DEBUG
- if(!pV)
- return 0.0f;
- #endif
- #ifdef __cplusplus
- return sqrtf(pV->x * pV->x + pV->y * pV->y);
- #else
- return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y);
- #endif
- }
- D3DX10INLINE FLOAT D3DXVec2LengthSq
- ( CONST D3DXVECTOR2 *pV )
- {
- #ifdef D3DX10_DEBUG
- if(!pV)
- return 0.0f;
- #endif
- return pV->x * pV->x + pV->y * pV->y;
- }
- D3DX10INLINE FLOAT D3DXVec2Dot
- ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pV1 || !pV2)
- return 0.0f;
- #endif
- return pV1->x * pV2->x + pV1->y * pV2->y;
- }
- D3DX10INLINE FLOAT D3DXVec2CCW
- ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pV1 || !pV2)
- return 0.0f;
- #endif
- return pV1->x * pV2->y - pV1->y * pV2->x;
- }
- D3DX10INLINE D3DXVECTOR2* D3DXVec2Add
- ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x + pV2->x;
- pOut->y = pV1->y + pV2->y;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR2* D3DXVec2Subtract
- ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x - pV2->x;
- pOut->y = pV1->y - pV2->y;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR2* D3DXVec2Minimize
- ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
- pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR2* D3DXVec2Maximize
- ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
- pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR2* D3DXVec2Scale
- ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV)
- return NULL;
- #endif
- pOut->x = pV->x * s;
- pOut->y = pV->y * s;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR2* D3DXVec2Lerp
- ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
- FLOAT s )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x + s * (pV2->x - pV1->x);
- pOut->y = pV1->y + s * (pV2->y - pV1->y);
- return pOut;
- }
- //--------------------------
- // 3D Vector
- //--------------------------
- D3DX10INLINE FLOAT D3DXVec3Length
- ( CONST D3DXVECTOR3 *pV )
- {
- #ifdef D3DX10_DEBUG
- if(!pV)
- return 0.0f;
- #endif
- #ifdef __cplusplus
- return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
- #else
- return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
- #endif
- }
- D3DX10INLINE FLOAT D3DXVec3LengthSq
- ( CONST D3DXVECTOR3 *pV )
- {
- #ifdef D3DX10_DEBUG
- if(!pV)
- return 0.0f;
- #endif
- return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z;
- }
- D3DX10INLINE FLOAT D3DXVec3Dot
- ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pV1 || !pV2)
- return 0.0f;
- #endif
- return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Cross
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
- {
- D3DXVECTOR3 v;
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- v.x = pV1->y * pV2->z - pV1->z * pV2->y;
- v.y = pV1->z * pV2->x - pV1->x * pV2->z;
- v.z = pV1->x * pV2->y - pV1->y * pV2->x;
- *pOut = v;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Add
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x + pV2->x;
- pOut->y = pV1->y + pV2->y;
- pOut->z = pV1->z + pV2->z;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Subtract
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x - pV2->x;
- pOut->y = pV1->y - pV2->y;
- pOut->z = pV1->z - pV2->z;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Minimize
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
- pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
- pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Maximize
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
- pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
- pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Scale
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV)
- return NULL;
- #endif
- pOut->x = pV->x * s;
- pOut->y = pV->y * s;
- pOut->z = pV->z * s;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR3* D3DXVec3Lerp
- ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
- FLOAT s )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x + s * (pV2->x - pV1->x);
- pOut->y = pV1->y + s * (pV2->y - pV1->y);
- pOut->z = pV1->z + s * (pV2->z - pV1->z);
- return pOut;
- }
- //--------------------------
- // 4D Vector
- //--------------------------
- D3DX10INLINE FLOAT D3DXVec4Length
- ( CONST D3DXVECTOR4 *pV )
- {
- #ifdef D3DX10_DEBUG
- if(!pV)
- return 0.0f;
- #endif
- #ifdef __cplusplus
- return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
- #else
- return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
- #endif
- }
- D3DX10INLINE FLOAT D3DXVec4LengthSq
- ( CONST D3DXVECTOR4 *pV )
- {
- #ifdef D3DX10_DEBUG
- if(!pV)
- return 0.0f;
- #endif
- return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w;
- }
- D3DX10INLINE FLOAT D3DXVec4Dot
- ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pV1 || !pV2)
- return 0.0f;
- #endif
- return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z + pV1->w * pV2->w;
- }
- D3DX10INLINE D3DXVECTOR4* D3DXVec4Add
- ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x + pV2->x;
- pOut->y = pV1->y + pV2->y;
- pOut->z = pV1->z + pV2->z;
- pOut->w = pV1->w + pV2->w;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR4* D3DXVec4Subtract
- ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x - pV2->x;
- pOut->y = pV1->y - pV2->y;
- pOut->z = pV1->z - pV2->z;
- pOut->w = pV1->w - pV2->w;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR4* D3DXVec4Minimize
- ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
- pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
- pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
- pOut->w = pV1->w < pV2->w ? pV1->w : pV2->w;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR4* D3DXVec4Maximize
- ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
- pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
- pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
- pOut->w = pV1->w > pV2->w ? pV1->w : pV2->w;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR4* D3DXVec4Scale
- ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV)
- return NULL;
- #endif
- pOut->x = pV->x * s;
- pOut->y = pV->y * s;
- pOut->z = pV->z * s;
- pOut->w = pV->w * s;
- return pOut;
- }
- D3DX10INLINE D3DXVECTOR4* D3DXVec4Lerp
- ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
- FLOAT s )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pV1 || !pV2)
- return NULL;
- #endif
- pOut->x = pV1->x + s * (pV2->x - pV1->x);
- pOut->y = pV1->y + s * (pV2->y - pV1->y);
- pOut->z = pV1->z + s * (pV2->z - pV1->z);
- pOut->w = pV1->w + s * (pV2->w - pV1->w);
- return pOut;
- }
- //--------------------------
- // 4D Matrix
- //--------------------------
- D3DX10INLINE D3DXMATRIX* D3DXMatrixIdentity
- ( D3DXMATRIX *pOut )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut)
- return NULL;
- #endif
- pOut->m[0][1] = pOut->m[0][2] = pOut->m[0][3] =
- pOut->m[1][0] = pOut->m[1][2] = pOut->m[1][3] =
- pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
- pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
- pOut->m[0][0] = pOut->m[1][1] = pOut->m[2][2] = pOut->m[3][3] = 1.0f;
- return pOut;
- }
- D3DX10INLINE BOOL D3DXMatrixIsIdentity
- ( CONST D3DXMATRIX *pM )
- {
- #ifdef D3DX10_DEBUG
- if(!pM)
- return FALSE;
- #endif
- return pM->m[0][0] == 1.0f && pM->m[0][1] == 0.0f && pM->m[0][2] == 0.0f && pM->m[0][3] == 0.0f &&
- pM->m[1][0] == 0.0f && pM->m[1][1] == 1.0f && pM->m[1][2] == 0.0f && pM->m[1][3] == 0.0f &&
- pM->m[2][0] == 0.0f && pM->m[2][1] == 0.0f && pM->m[2][2] == 1.0f && pM->m[2][3] == 0.0f &&
- pM->m[3][0] == 0.0f && pM->m[3][1] == 0.0f && pM->m[3][2] == 0.0f && pM->m[3][3] == 1.0f;
- }
- //--------------------------
- // Quaternion
- //--------------------------
- D3DX10INLINE FLOAT D3DXQuaternionLength
- ( CONST D3DXQUATERNION *pQ )
- {
- #ifdef D3DX10_DEBUG
- if(!pQ)
- return 0.0f;
- #endif
- #ifdef __cplusplus
- return sqrtf(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
- #else
- return (FLOAT) sqrt(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
- #endif
- }
- D3DX10INLINE FLOAT D3DXQuaternionLengthSq
- ( CONST D3DXQUATERNION *pQ )
- {
- #ifdef D3DX10_DEBUG
- if(!pQ)
- return 0.0f;
- #endif
- return pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w;
- }
- D3DX10INLINE FLOAT D3DXQuaternionDot
- ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 )
- {
- #ifdef D3DX10_DEBUG
- if(!pQ1 || !pQ2)
- return 0.0f;
- #endif
- return pQ1->x * pQ2->x + pQ1->y * pQ2->y + pQ1->z * pQ2->z + pQ1->w * pQ2->w;
- }
- D3DX10INLINE D3DXQUATERNION* D3DXQuaternionIdentity
- ( D3DXQUATERNION *pOut )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut)
- return NULL;
- #endif
- pOut->x = pOut->y = pOut->z = 0.0f;
- pOut->w = 1.0f;
- return pOut;
- }
- D3DX10INLINE BOOL D3DXQuaternionIsIdentity
- ( CONST D3DXQUATERNION *pQ )
- {
- #ifdef D3DX10_DEBUG
- if(!pQ)
- return FALSE;
- #endif
- return pQ->x == 0.0f && pQ->y == 0.0f && pQ->z == 0.0f && pQ->w == 1.0f;
- }
- D3DX10INLINE D3DXQUATERNION* D3DXQuaternionConjugate
- ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ )
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pQ)
- return NULL;
- #endif
- pOut->x = -pQ->x;
- pOut->y = -pQ->y;
- pOut->z = -pQ->z;
- pOut->w = pQ->w;
- return pOut;
- }
- //--------------------------
- // Plane
- //--------------------------
- D3DX10INLINE FLOAT D3DXPlaneDot
- ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV)
- {
- #ifdef D3DX10_DEBUG
- if(!pP || !pV)
- return 0.0f;
- #endif
- return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d * pV->w;
- }
- D3DX10INLINE FLOAT D3DXPlaneDotCoord
- ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV)
- {
- #ifdef D3DX10_DEBUG
- if(!pP || !pV)
- return 0.0f;
- #endif
- return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d;
- }
- D3DX10INLINE FLOAT D3DXPlaneDotNormal
- ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV)
- {
- #ifdef D3DX10_DEBUG
- if(!pP || !pV)
- return 0.0f;
- #endif
- return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z;
- }
- D3DX10INLINE D3DXPLANE* D3DXPlaneScale
- (D3DXPLANE *pOut, CONST D3DXPLANE *pP, FLOAT s)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pP)
- return NULL;
- #endif
- pOut->a = pP->a * s;
- pOut->b = pP->b * s;
- pOut->c = pP->c * s;
- pOut->d = pP->d * s;
- return pOut;
- }
- //--------------------------
- // Color
- //--------------------------
- D3DX10INLINE D3DXCOLOR* D3DXColorNegative
- (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pC)
- return NULL;
- #endif
- pOut->r = 1.0f - pC->r;
- pOut->g = 1.0f - pC->g;
- pOut->b = 1.0f - pC->b;
- pOut->a = pC->a;
- return pOut;
- }
- D3DX10INLINE D3DXCOLOR* D3DXColorAdd
- (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pC1 || !pC2)
- return NULL;
- #endif
- pOut->r = pC1->r + pC2->r;
- pOut->g = pC1->g + pC2->g;
- pOut->b = pC1->b + pC2->b;
- pOut->a = pC1->a + pC2->a;
- return pOut;
- }
- D3DX10INLINE D3DXCOLOR* D3DXColorSubtract
- (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pC1 || !pC2)
- return NULL;
- #endif
- pOut->r = pC1->r - pC2->r;
- pOut->g = pC1->g - pC2->g;
- pOut->b = pC1->b - pC2->b;
- pOut->a = pC1->a - pC2->a;
- return pOut;
- }
- D3DX10INLINE D3DXCOLOR* D3DXColorScale
- (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pC)
- return NULL;
- #endif
- pOut->r = pC->r * s;
- pOut->g = pC->g * s;
- pOut->b = pC->b * s;
- pOut->a = pC->a * s;
- return pOut;
- }
- D3DX10INLINE D3DXCOLOR* D3DXColorModulate
- (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pC1 || !pC2)
- return NULL;
- #endif
- pOut->r = pC1->r * pC2->r;
- pOut->g = pC1->g * pC2->g;
- pOut->b = pC1->b * pC2->b;
- pOut->a = pC1->a * pC2->a;
- return pOut;
- }
- D3DX10INLINE D3DXCOLOR* D3DXColorLerp
- (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s)
- {
- #ifdef D3DX10_DEBUG
- if(!pOut || !pC1 || !pC2)
- return NULL;
- #endif
- pOut->r = pC1->r + s * (pC2->r - pC1->r);
- pOut->g = pC1->g + s * (pC2->g - pC1->g);
- pOut->b = pC1->b + s * (pC2->b - pC1->b);
- pOut->a = pC1->a + s * (pC2->a - pC1->a);
- return pOut;
- }
- #endif // __D3DXMATH_INL__
|