Uso di D3DXMath

D3DXMath è una libreria di supporto matematico per le applicazioni Direct3D. D3DXMath è di lunga durata, è incluso anche in D3DX 9 e D3DX 10 e risale alle versioni precedenti di DirectX.

Nota

La libreria di utilità D3DX (D3DX 9, D3DX 10 e D3DX 11) è deprecata per Windows 8, quindi è consigliabile eseguire la migrazione a DirectXMath anziché usare D3DXMath.

 

DirectXMath condivide gran parte delle stesse funzionalità in D3DXMath e internamente D3DXMath include una serie di ottimizzazioni specifiche del processore. La differenza principale è che D3DXMath è ospitato in D3DX9*. DLL e D3DX10*. Le DLL e pochissime funzioni sono inlining. La convenzione di chiamata della libreria DirectXMath è esplicitamente compatibile con SIMD, mentre D3DXMath deve eseguire conversioni di caricamento e archiviazione per implementare l'ottimizzazione SIMD.

Combinazione di DirectXMath e D3DXMath

D3DX11 non contiene D3DXMath e in generale è consigliabile usare DirectXMath. Tuttavia, è possibile continuare a collegarsi a D3DX9 e/o D3DX10 nell'applicazione e quindi continuare a usare D3DXMath o usare sia D3DXMath che DirectXMath nell'applicazione contemporaneamente.

In generale, è possibile eseguire il cast di un XMVECTOR* a una funzione che accetta D3DXVECTOR4* o di eseguire il cast di una XMMATRIX* a una funzione che accetta D3DXMATRIX*. L'inverso, tuttavia, non è generalmente sicuro perché XMVECTOR e XMMATRIX devono essere allineati a 16 byte, mentre D3DXVECTOR4 e D3DXMATRIX non hanno tali requisiti. Il mancato rispetto di questo requisito può comportare eccezioni di allineamento non valide in fase di esecuzione.

È possibile eseguire il cast di un XMVECTOR* a una funzione che accetta D3DXVECTOR2* o D3DXVECTOR3*, ma non viceversa. Sia i problemi di allineamento che il fatto che D3DXVECTOR2 e D3DXVECTOR3 siano strutture più piccole rendono questa operazione non sicura.

Nota

D3DX (e quindi D3DXMath) è considerato legacy e non è disponibile per le app di Windows Store eseguite in Windows 8 e non è incluso in Windows 8 SDK per le app desktop.

 

Uso di DirectXMath con Direct3D

Sia DirectXMath che D3DXMath sono facoltativi quando si usa Direct3D. Direct3D 9 ha definito D3DMATRIX e D3DCOLOR come parte dell'API Direct3D in supporto della pipeline a funzione fissa (ora legacy). D3DXMath in D3DX9 estende questi tipi Direct3D 9 con operazioni matematiche grafiche comuni. Per Direct3D 10.x e Direct3D 11, l'API usa solo la pipeline programmabile, quindi non esiste una struttura specifica dell'API per matrici o valori di colore. Quando le API più recenti richiedono un valore di colore, accettano una matrice esplicita di valori float o un buffer generico di dati costanti interpretati dallo shader HLSL. HLSL stesso può supportare formati di matrice principale o principale di riga o colonna, quindi il layout dipende interamente dall'utente (per altre informazioni, vedere HLSL, Matrix Ordering; se si usano formati di matrice principale della colonna negli shader, è necessario trasporre i dati della matrice DirectXMath mentre li si inserisce nelle strutture di buffer costanti). Anche se facoltativo, le librerie DirectXMath e D3DXMath forniscono entrambe funzionalità comuni correlate alla grafica e sono quindi estremamente utili quando si esegue la programmazione Direct3D.

È possibile eseguire il cast di un XMVECTOR* in un D3DVECTOR* o XMMATRIX* per D3DMATRIX* poiché Direct3D 9 non presuppone alcun allineamento sulla struttura dei dati in ingresso. È anche possibile eseguire il cast di XMCOLOR in D3DCOLOR. È possibile convertire una rappresentazione a 4 float di colore in XMCOLOR tramite XMStoreColor() per ottenere la DWORD a 8:8:8:8 a 32 bit equivalente a D3DCOLOR.

Quando si usano i tipi Direct3D 10.x o Direct3D 11, in genere si useranno i tipi DirectXMath per compilare una struttura per ognuno dei buffer costanti e in questi casi dipende in gran parte dalla possibilità di controllare l'allineamento per rendere efficienti queste operazioni o per usare le operazioni XMStore*() per convertire i dati XMVECTOR e XMMATRIX nei tipi di dati corretti. Quando si chiamano API Direct3D 10.x o Direct3D 11 che richiedono una matrice float[4] di valori di colore, è possibile eseguire il cast di un XMVECTOR* o XMFLOAT4* contenente i dati sul colore.

Conversione da D3DXMath

Tipo D3DXMath Equivalente DirectXMath
D3DXFLOAT16 METÀ
D3DXMATRIX XMFLOAT4X4
D3DXMATRIXA16 XMMATRIX o XMFLOAT4X4A
D3DXQUATERNION
D3DXPLANE
D3DXCOLOR
XMVECTOR viene usato anziché avere tipi univoci, pertanto è probabile che sia necessario usare un XMFLOAT4Nota:**D3DXQUATERNION::operator ** chiama la funzione D3DXQuaternionMultiply, che moltiplica due quaternioni. Tuttavia, a meno che non si usi in modo esplicito la funzione XMQuaternionMultiply, si ottiene una risposta errata quando si usa **XMVECTOR::operator ** su un quaternione.
D3DXVECTOR2 XMFLOAT2
D3DXVECTOR2_16F XMHALF2
D3DXVECTOR3 XMFLOAT3
D3DXVECTOR4 XMFLOAT4(o se è possibile garantire che i dati sono allineati a 16 byte, XMVECTOR o XMFLOAT4A )
D3DXVECTOR4_16F XMHALF4

 

Nota

Non esiste un equivalente diretto a D3DXVECTOR3_16F in XNAMath.

 

D3DXMath Macro Equivalente DirectXMath
D3DX_PI XM_PI
D3DX_1BYPI XM_1DIVPI
D3DXToRadian XMConvertToRadians
D3DXToDegree XMConvertToDegrees

 

Funzione D3DXMath Equivalente DirectXMath
D3DXBoxBoundProbe BoundingBox::Intersects(XMVECTOR, XMVECTOR, float&)
D3DXComputeBoundingBox BoundingBox::CreateFromPoints
D3DXComputeBoundingSphere BoundingSphere::CreateFromPoints
D3DXSphereBoundProbe BoundingSphere::Intersects(XMVECTOR, XMVECTOR, float&)
D3DXIntersectTriFunction TriangleTests::Intersects
D3DXFloat32To16Array XMConvertFloatToHalfStream
D3DXFloat16To32Array XMConvertHalfToFloatStream
D3DXVec2Length XMVector2Length o XMVector2LengthEst
D3DXVec2LengthSq XMVector2LengthSq
D3DXVec2Dot XMVector2Dot
D3DXVec2CCW XMVector2Cross
D3DXVec2Add XMVectorAdd
D3DXVec2Subtract XMVectorSubtract
D3DXVec2Minimize XMVectorMin
D3DXVec2Maximize XMVectorMax
D3DXVec2Scale XMVectorScale
D3DXVec2Lerp XMVectorLerp o XMVectorLerpV
D3DXVec2Normalize XMVector2Normalize o XMVector2NormalizeEst
D3DXVec2Hermite XMVectorHermite o XMVectorHermiteV
D3DXVec2CatmullRom XMVectorCatmullRom o XMVectorCatmullRomV
D3DXVec2BaryCentric XMVectorBaryCentric o XMVectorBaryCentricV
D3DXVec2Transform XMVector2Transform
D3DXVec2TransformCoord XMVector2TransformCoord
D3DXVec2TransformNormal XMVector2TransformNormal
D3DXVec2TransformArray XMVector2TransformStream
D3DXVec2TransformCoordArray XMVector2TransformCoordStream
D3DXVec2TransformNormalArray XMVector2TransformNormalStream
D3DXVec3Length XMVector3Length o XMVector3LengthEst
D3DXVec3LengthSq XMVector3LengthSq
D3DXVec3Dot XMVector3Dot
D3DXVec3Cross XMVector3Cross
D3DXVec3Add XMVectorAdd
D3DXVec3Subtract XMVectorSubtract
D3DXVec3Minimize XMVectorMin
D3DXVec3Maximize XMVectorMax
D3DXVec3Scale XMVectorScale
D3DXVec3Lerp XMVectorLerp o XMVectorLerpV
D3DXVec3Normalize XMVector3Normalize o XMVector3NormalizeEst
D3DXVec3Hermite XMVectorHermite o XMVectorHermiteV
D3DXVec3CatmullRom XMVectorCatmullRom o XMVectorCatmullRomV
D3DXVec3BaryCentric XMVectorBaryCentric o XMVectorBaryCentricV
D3DXVec3Transform XMVector3Transform
D3DXVec3TransformCoord XMVector3TransformCoord
D3DXVec3TransformNormal XMVector3TransformNormal
D3DXVec3TransformArray XMVector3TransformStream
D3DXVec3TransformCoordArray XMVector3TransformCoordStream
D3DXVec3TransformNormalArray XMVector3TransformNormalStream
D3DXVec3Project XMVector3Project
D3DXVec3Unproject XMVector3Unproject
D3DXVec3ProjectArray XMVector3ProjectStream
D3DXVec3UnprojectArray XMVector3UnprojectStream
D3DXVec4Length XMVector4Length o XMVector4LengthEst
D3DXVec4LengthSq XMVector4LengthSq
D3DXVec4Dot XMVector4Dot
D3DXVec4Add XMVectorAdd
D3DXVec4Subtract XMVectorSubtract
D3DXVec4Minimize XMVectorMin
D3DXVec4Maximize XMVectorMax
D3DXVec4Scale XMVectorScale
D3DXVec4Lerp XMVectorLerp o XMVectorLerpV
D3DXVec4Cross XMVector4Cross
D3DXVec4Normalize XMVector4Normalize o XMVector4NormalizeEst
D3DXVec4Hermite XMVectorHermite o XMVectorHermiteV
D3DXVec4CatmullRom XMVectorCatmullRom o XMVectorCatmullRomV
D3DXVec4BaryCentric XMVectorBaryCentric o XMVectorBaryCentricV
D3DXVec4Transform XMVector4Transform
D3DXVec4TransformArray XMVector4TransformStream
D3DXMatrixIdentity XMMatrixIdentity
D3DXMatrixDeterminant XMMatrixDeterminant
D3DXMatrixDecompose XMMatrixDecompose
D3DXMatrixTranspose XMMatrixTranspose
D3DXMatrixMultiply XMMatrixMultiply
D3DXMatrixMultiplyTranspose XMMatrixMultiplyTranspose
D3DXMatrixInverse XMMatrixInverse
D3DXMatrixScaling XMMatrixScaling
D3DXMatrixTranslation XMMatrixTranslation
D3DXMatrixRotationX XMMatrixRotationX
D3DXMatrixRotationY XMMatrixRotationY
D3DXMatrixRotationZ XMMatrixRotationZ
D3DXMatrixRotationAxis XMMatrixRotationAxis
D3DXMatrixRotationQuaternion XMMatrixRotationQuaternion
D3DXMatrixRotationYawPitchRoll XMMatrixRotationRollPitchYaw (si noti che l'ordine dei parametri è diverso: D3DXMatrixRotationYawPitchRoll accetta yaw, pitch, roll, XMMatrixRotationRollPitchYaw prende pitch, yaw, roll)
D3DXMatrixTransformation XMMatrixTransformation
D3DXMatrixTransformation2D XMMatrixTransformation2D
D3DXMatrixAffineTransformation XMMatrixAffineTransformation
D3DXMatrixAffineTransformation2D XMMatrixAffineTransformation2D
D3DXMatrixLookAtRH XMMatrixLookAtRH
D3DXMatrixLookAtLH XMMatrixLookAtLH
D3DXMatrixPerspectiveRH XMMatrixPerspectiveRH
D3DXMatrixPerspectiveLH XMMatrixPerspectiveLH
D3DXMatrixPerspectiveFovRH XMMatrixPerspectiveFovRH
D3DXMatrixPerspectiveFovLH XMMatrixPerspectiveFovLH
D3DXMatrixPerspectiveOffCenterRH XMMatrixPerspectiveOffCenterRH
D3DXMatrixPerspectiveOffCenterLH XMMatrixPerspectiveOffCenterLH
D3DXMatrixOrthoRH XMMatrixOrthographicRH
D3DXMatrixOrthoLH XMMatrixOrthographicLH
D3DXMatrixOrthoOffCenterRH XMMatrixOrthographicOffCenterRH
D3DXMatrixOrthoOffCenterLH XMMatrixOrthographicOffCenterLH
D3DXMatrixShadow XMMatrixShadow
D3DXMatrixReflect XMMatrixReflect
D3DXQuaternionLength XMQuaternionLength
D3DXQuaternionLengthSq XMQuaternionLengthSq
D3DXQuaternionDot XMQuaternionDot
D3DXQuaternionIdentity XMQuaternionIdentity
D3DXQuaternionIsIdentity XMQuaternionIsIdentity
D3DXQuaternionConjugate XMQuaternionConjugate
D3DXQuaternionToAxisAngle XMQuaternionToAxisAngle
D3DXQuaternionRotationMatrix XMQuaternionRotationMatrix
D3DXQuaternionRotationAxis XMQuaternionRotationAxis
D3DXQuaternionRotationYawPitchRoll XMQuaternionRotationRollPitchYaw (si noti che l'ordine dei parametri è diverso: D3DXQuaternionRotationYawPitchRoll accetta yaw, pitch, roll, XMQuaternionRotationRollPitchYaw accetta pitch, yaw, roll)
D3DXQuaternionMultiply XMQuaternionMultiply
D3DXQuaternionNormalize XMQuaternionNormalize o XMQuaternionNormalizeEst
D3DXQuaternionInverse XMQuaternionInverse
D3DXQuaternionLn XMQuaternionLn
D3DXQuaternionExp XMQuaternionExp
D3DXQuaternionSlerp XMQuaternionSlerp o XMQuaternionSlerpV
D3DXQuaternionSquad XMQuaternionSquad o XMQuaternionSquadV
D3DXQuaternionSquadSetup XMQuaternionSquadSetup
D3DXQuaternionBaryCentric XMQuaternionBaryCentric o XMQuaternionBaryCentricV
D3DXPlaneDot XMPlaneDot
D3DXPlaneDotCoord XMPlaneDotCoord
D3DXPlaneDotNormal XMPlaneDotNormal
D3DXPlaneScale XMVectorScale
D3DXPlaneNormalize XMPlaneNormalize o XMPlaneNormalizeEst
D3DXPlaneIntersectLine XMPlaneIntersectLine
D3DXPlaneFromPointNormal XMPlaneFromPointNormal
D3DXPlaneFromPoints XMPlaneFromPoints
D3DXPlaneTransform XMPlaneTransform
D3DXPlaneTransformArray XMPlaneTransformStream
D3DXColorNegative XMColorNegative
D3DXColorAdd XMVectorAdd
D3DXColorSubtract XMVectorSubtract
D3DXColorScale XMVectorScale
D3DXColorModulate XMColorModulate
D3DXColorLerp XMVectorLerp o XMVectorLerpV
D3DXColorAdjustSaturation XMColorAdjustSaturation
D3DXColorAdjustContrast XMColorAdjustContrast
D3DXFresnelTerm XMFresnelTerm

 

Nota

Le funzioni armoniche sferiche per DirectXMath sono disponibili separatamente. È disponibile anche un oggetto DirectXMath equivalente a ID3DXMatrixStack .

 

Guida per programmatori DirectXMath