Utilisation de D3DXMath
D3DXMath est une bibliothèque d’assistance mathématique pour les applications Direct3D. D3DXMath est à long terme, est inclus dans D3DX 9 et D3DX 10, et les dates renvoient également aux versions antérieures de DirectX.
Notes
la bibliothèque de l’utilitaire d3dx (d3dx 9, d3dx 10 et d3dx 11) est dépréciée pour Windows 8. nous vous recommandons donc vivement de migrer vers DirectXMath au lieu d’utiliser D3DXMath.
DirectXMath partage une grande partie des mêmes fonctionnalités dans D3DXMath, et D3DXMath en interne comprend un certain nombre d’optimisations spécifiques au processeur. La principale différence réside dans le fait que D3DXMath est hébergé dans le D3DX9 * . Dll et D3DX10 * . Les dll et très peu de fonctions sont Inline. La Convention d’appel de la bibliothèque DirectXMath est explicitement SIMD, tandis que D3DXMath doit effectuer des conversions de charge et de stockage pour implémenter l’optimisation SIMD.
Combinaison de DirectXMath et de D3DXMath
D3DX11 ne contient pas D3DXMath et, en général, nous vous recommandons d’utiliser DirectXMath à la place. Toutefois, vous êtes libre de continuer à créer des liens vers D3DX9 et/ou D3DX10 dans votre application. par conséquent, vous pouvez continuer à utiliser D3DXMath ou utiliser D3DXMath et DirectXMath dans votre application en même temps.
Il est en général sécurisé d’effectuer un cast d’un XMVECTOR * en une fonction qui prend D3DXVECTOR4 * ou d’effectuer un cast d’un XMMATRIX * en une fonction qui prend D3DXMATRIX * . L’inverse n’est cependant pas sécurisé, car XMVECTOR et XMMATRIX doivent être alignés sur 16 octets, tandis que D3DXVECTOR4 et D3DXMATRIX n’ont pas cette exigence. Si vous ne respectez pas cette exigence, vous risquez d’obtenir des exceptions d’alignement non valides au moment de l’exécution.
Il est possible de convertir en toute sécurité un XMVECTOR * en une fonction qui prend D3DXVECTOR2 * ou D3DXVECTOR3 * , mais pas l’inverse. Les deux problèmes d’alignement et le fait que D3DXVECTOR2 et D3DXVECTOR3 sont des structures plus petites rendent cela une opération risquée.
Notes
D3DX (et par conséquent D3DXMath) est considéré comme hérité et n’est pas disponible pour Windows les applications du windows Store qui s’exécutent sur Windows 8 et qui ne sont pas incluses dans le kit de développement logiciel (SDK) Windows 8 pour les applications de bureau.
Utilisation de DirectXMath avec Direct3D
DirectXMath et D3DXMath sont facultatifs lorsque vous travaillez avec Direct3D. Direct3D 9 a défini D3DMATRIX et D3DCOLOR dans le cadre de l’API Direct3D pour la prise en charge du pipeline de fonction fixe (désormais hérité). D3DXMath dans D3DX9 étend ces types Direct3D 9 avec les opérations mathématiques graphiques courantes. Pour Direct3D 10. x et Direct3D 11, l’API utilise uniquement le pipeline programmable, de sorte qu’il n’existe aucune structure spécifique à l’API pour les matrices ou les valeurs de couleur. Lorsque les API plus récentes requièrent une valeur de couleur, elles prennent un tableau explicite de valeurs float ou une mémoire tampon générique de données constantes interprétées par le nuanceur HLSL. Le langage HLSL lui-même peut prendre en charge des formats de matrices de lignes majeures ou de colonnes majeures, de sorte que la disposition dépend entièrement de vous (pour plus d’informations, consultez l’article sur le langage HLSL). Si vous utilisez des formats de matrices principaux dans vos nuanceurs, vous devez transposer les données de la matrice DirectXMath au fur et àmesure. Bien que facultative, les bibliothèques DirectXMath et D3DXMath fournissent des fonctionnalités graphiques communes et sont donc extrêmement pratiques lors de la programmation Direct3D.
Il est possible de convertir en toute sécurité un XMVECTOR * en D3DVECTOR * ou XMMATRIX * en D3DMATRIX, * car Direct3D 9 ne fait aucune supposition d’alignement sur la structure de données entrante. Il est également possible de convertir XMCOLOR en D3DCOLOR. Vous pouvez convertir une représentation 4-float de Color en XMCOLOR via XMStoreColor () pour obtenir la valeur DWORD 8:8:8:8 32 bits équivalente à D3DCOLOR.
Lorsque vous travaillez avec Direct3D 10. x ou Direct3D 11, vous utilisez généralement des types DirectXMath pour créer une structure pour chacune de vos mémoires tampons constantes, et dans ce cas, cela dépend en grande partie de votre capacité à contrôler l’alignement afin de rendre ces opérations efficaces ou d’utilisation de XMStore * () pour convertir les données XMVECTOR et XMMATRIX en types de données corrects. Lors de l’appel d’API Direct3D 10. x ou Direct3D 11 qui requièrent un [ ] tableau de valeurs de couleur à virgule flottante 4, vous pouvez effectuer un cast d’un XMVECTOR ou d’un * XMFLOAT4 * contenant les données de couleur.
Portage à partir de D3DXMath
| Type D3DXMath | DirectXMath équivalent |
|---|---|
| D3DXFLOAT16 | CARACTÈRES |
| D3DXMATRIX | XMFLOAT4X4 |
| D3DXMATRIXA16 | XMMATRIX ou XMFLOAT4X4A |
| D3DXQUATERNION D3DXPLANE D3DXCOLOR |
XMVECTOR est utilisé au lieu d’avoir des types uniques. vous devrez probablement utiliser un XMFLOAT4[!Note] |
| D3DXVECTOR2 | XMFLOAT2 |
| D3DXVECTOR2_16F | XMHALF2 |
| D3DXVECTOR3 | XMFLOAT3 |
| D3DXVECTOR4 | XMFLOAT4(ou si vous pouvez garantir que les données sont alignées sur 16 octets, XMVECTOR ou XMFLOAT4A ) |
| D3DXVECTOR4_16F | XMHALF4 |
Notes
Il n’existe aucun équivalent direct à D3DXVECTOR3 _ 16F dans XNAMath.
| D3DXMath macro) | DirectXMath équivalent |
|---|---|
| D3DX _ pi | XM _ pi |
| D3DX _ 1BYPI | XM _ 1DIVPI |
| D3DXToRadian | XMConvertToRadians |
| D3DXToDegree | XMConvertToDegrees |
| D3DXMath fonction) | DirectXMath équivalent |
|---|---|
| D3DXBoxBoundProbe | BoundingBox :: intersections (XMVECTOR, XMVECTOR, float&) |
| D3DXComputeBoundingBox | BoundingBox :: CreateFromPoints |
| D3DXComputeBoundingSphere | BoundingSphere::CreateFromPoints |
| D3DXSphereBoundProbe | BoundingSphere :: croisements (XMVECTOR, XMVECTOR, float&) |
| D3DXIntersectTriFunction | TriangleTests :: croisements |
| D3DXFloat32To16Array | XMConvertFloatToHalfStream |
| D3DXFloat16To32Array | XMConvertHalfToFloatStream |
| D3DXVec2Length | XMVector2Length ou XMVector2LengthEst |
| D3DXVec2LengthSq | XMVector2LengthSq |
| D3DXVec2Dot | XMVector2Dot |
| D3DXVec2CCW | XMVector2Cross |
| D3DXVec2Add | XMVectorAdd |
| D3DXVec2Subtract | XMVectorSubtract |
| D3DXVec2Minimize | XMVectorMin |
| D3DXVec2Maximize | XMVectorMax |
| D3DXVec2Scale | XMVectorScale |
| D3DXVec2Lerp | XMVectorLerp ou XMVectorLerpV |
| D3DXVec2Normalize | XMVector2Normalize ou XMVector2NormalizeEst |
| D3DXVec2Hermite | XMVectorHermite ou XMVectorHermiteV |
| D3DXVec2CatmullRom | XMVectorCatmullRom ou XMVectorCatmullRomV |
| D3DXVec2BaryCentric | XMVectorBaryCentric ou XMVectorBaryCentricV |
| D3DXVec2Transform | XMVector2Transform |
| D3DXVec2TransformCoord | XMVector2TransformCoord |
| D3DXVec2TransformNormal | XMVector2TransformNormal |
| D3DXVec2TransformArray | XMVector2TransformStream |
| D3DXVec2TransformCoordArray | XMVector2TransformCoordStream |
| D3DXVec2TransformNormalArray | XMVector2TransformNormalStream |
| D3DXVec3Length | XMVector3Length ou XMVector3LengthEst |
| D3DXVec3LengthSq | XMVector3LengthSq |
| D3DXVec3Dot | XMVector3Dot |
| D3DXVec3Cross | XMVector3Cross |
| D3DXVec3Add | XMVectorAdd |
| D3DXVec3Subtract | XMVectorSubtract |
| D3DXVec3Minimize | XMVectorMin |
| D3DXVec3Maximize | XMVectorMax |
| D3DXVec3Scale | XMVectorScale |
| D3DXVec3Lerp | XMVectorLerp ou XMVectorLerpV |
| D3DXVec3Normalize | XMVector3Normalize ou XMVector3NormalizeEst |
| D3DXVec3Hermite | XMVectorHermite ou XMVectorHermiteV |
| D3DXVec3CatmullRom | XMVectorCatmullRom ou XMVectorCatmullRomV |
| D3DXVec3BaryCentric | XMVectorBaryCentric ou XMVectorBaryCentricV |
| D3DXVec3Transform | XMVector3Transform |
| D3DXVec3TransformCoord | XMVector3TransformCoord |
| D3DXVec3TransformNormal | XMVector3TransformNormal |
| D3DXVec3TransformArray | XMVector3TransformStream |
| D3DXVec3TransformCoordArray | XMVector3TransformCoordStream |
| D3DXVec3TransformNormalArray | XMVector3TransformNormalStream |
| D3DXVec3Project | XMVector3Project |
| D3DXVec3Unproject | XMVector3Unproject |
| D3DXVec3ProjectArray | XMVector3ProjectStream |
| D3DXVec3UnprojectArray | XMVector3UnprojectStream |
| D3DXVec4Length | XMVector4Length ou XMVector4LengthEst |
| D3DXVec4LengthSq | XMVector4LengthSq |
| D3DXVec4Dot | XMVector4Dot |
| D3DXVec4Add | XMVectorAdd |
| D3DXVec4Subtract | XMVectorSubtract |
| D3DXVec4Minimize | XMVectorMin |
| D3DXVec4Maximize | XMVectorMax |
| D3DXVec4Scale | XMVectorScale |
| D3DXVec4Lerp | XMVectorLerp ou XMVectorLerpV |
| D3DXVec4Cross | XMVector4Cross |
| D3DXVec4Normalize | XMVector4Normalize ou XMVector4NormalizeEst |
| D3DXVec4Hermite | XMVectorHermite ou XMVectorHermiteV |
| D3DXVec4CatmullRom | XMVectorCatmullRom ou XMVectorCatmullRomV |
| D3DXVec4BaryCentric | XMVectorBaryCentric ou 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 (Notez que l’ordre des paramètres est différent : D3DXMatrixRotationYawPitchRoll prend le lacet, le tangage, le rouleau, le XMMatrixRotationRollPitchYaw prend le pas, le lacet, le rouleau) |
| 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 (Notez que l’ordre des paramètres est différent : D3DXQuaternionRotationYawPitchRoll prend le lacet, le tangage, le rouleau, le XMQuaternionRotationRollPitchYaw prend le pas, le lacet, le rouleau) |
| D3DXQuaternionMultiply | XMQuaternionMultiply |
| D3DXQuaternionNormalize | XMQuaternionNormalize ou XMQuaternionNormalizeEst |
| D3DXQuaternionInverse | XMQuaternionInverse |
| D3DXQuaternionLn | XMQuaternionLn |
| D3DXQuaternionExp | XMQuaternionExp |
| D3DXQuaternionSlerp | XMQuaternionSlerp ou XMQuaternionSlerpV |
| D3DXQuaternionSquad | XMQuaternionSquad ou XMQuaternionSquadV |
| D3DXQuaternionSquadSetup | XMQuaternionSquadSetup |
| D3DXQuaternionBaryCentric | XMQuaternionBaryCentric ou XMQuaternionBaryCentricV |
| D3DXPlaneDot | XMPlaneDot |
| D3DXPlaneDotCoord | XMPlaneDotCoord |
| D3DXPlaneDotNormal | XMPlaneDotNormal |
| D3DXPlaneScale | XMVectorScale |
| D3DXPlaneNormalize | XMPlaneNormalize ou XMPlaneNormalizeEst |
| D3DXPlaneIntersectLine | XMPlaneIntersectLine |
| D3DXPlaneFromPointNormal | XMPlaneFromPointNormal |
| D3DXPlaneFromPoints | XMPlaneFromPoints |
| D3DXPlaneTransform | XMPlaneTransform |
| D3DXPlaneTransformArray | XMPlaneTransformStream |
| D3DXColorNegative | XMColorNegative |
| D3DXColorAdd | XMVectorAdd |
| D3DXColorSubtract | XMVectorSubtract |
| D3DXColorScale | XMVectorScale |
| D3DXColorModulate | XMColorModulate |
| D3DXColorLerp | XMVectorLerp ou XMVectorLerpV |
| D3DXColorAdjustSaturation | XMColorAdjustSaturation |
| D3DXColorAdjustContrast | XMColorAdjustContrast |
| D3DXFresnelTerm | XMFresnelTerm |
Notes
Les fonctions d' harmoniques sphériques pour DirectXMath sont disponibles séparément. Un DirectXMath équivalent à ID3DXMatrixStack est également disponible.