Utilisation de D3DXMath
D3DXMath est une bibliothèque d’assistance mathématique pour les applications Direct3D. D3DXMath est longuement inclus dans D3DX 9 et D3DX 10 et remonte également aux versions antérieures de DirectX.
Notes
La bibliothèque utilitaire D3DX (D3DX 9, D3DX 10 et D3DX 11) est déconseillée pour Windows 8. Nous vous recommandons donc vivement de migrer vers DirectXMath plutôt que d’utiliser D3DXMath.
DirectXMath partage une grande partie des mêmes fonctionnalités dans D3DXMath, et en interne D3DXMath inclut un certain nombre d’optimisations spécifiques au processeur. La principale différence est que D3DXMath est hébergé dans le D3DX9*. DLL et D3DX10*. Les DLL et très peu de fonctions sont insérées. La convention d’appel de la bibliothèque DirectXMath est explicitement conviviale, tandis que D3DXMath doit effectuer des conversions de charge et de stockage pour implémenter l’optimisation SIMD.
Mélange de DirectXMath et 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 un lien 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ûr de caster un XMVECTOR* en fonction qui prend D3DXVECTOR4* ou de convertir un XMMATRIX* en fonction qui prend D3DXMATRIX*. Toutefois, l’inverse n’est pas généralement sûr, car XMVECTOR et XMMATRIX doivent être alignés sur 16 octets, tandis que D3DXVECTOR4 et D3DXMATRIX n’ont pas de telles exigences. Le fait de ne pas respecter cette exigence peut entraîner des exceptions d’alignement non valides au moment de l’exécution.
Il est sûr de convertir un XMVECTOR* en fonction qui prend D3DXVECTOR2* ou D3DXVECTOR3*, mais pas inversement. Les préoccupations d’alignement et le fait que D3DXVECTOR2 et D3DXVECTOR3 sont des structures plus petites rendent cette opération non sécurisée.
Notes
D3DX (et par conséquent D3DXMath) est considéré comme hérité et n’est pas disponible pour 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 lors de l’utilisation de Direct3D. Direct3D 9 a défini D3DMATRIX et D3DCOLOR dans le cadre de l’API Direct3D pour prendre en charge le pipeline de fonction fixe (maintenant héritée). D3DXMath dans D3DX9 étend ces types Direct3D 9 avec des opérations mathématiques graphiques courantes. Pour Direct3D 10.x et Direct3D 11, l’API utilise uniquement le pipeline programmable afin qu’il n’existe aucune structure spécifique à l’API pour les matrices ou les valeurs de couleur. Lorsque les API les plus récentes nécessitent 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. HLSL lui-même peut prendre en charge les formats de matrice principale de ligne ou de colonne, de sorte que la disposition est entièrement à votre disposition (pour plus d’informations, voir HLSL, Classement des matrices; si vous utilisez des formats de matrice principaux de colonne dans vos nuanceurs, vous devez transposer les données de matrice DirectXMath au fur et à mesure que vous les placez dans vos structures de mémoire tampon constantes). Bien qu’elles soient facultatives, les bibliothèques DirectXMath et D3DXMath fournissent toutes deux des fonctionnalités courantes liées aux graphiques et sont donc extrêmement pratiques lors de la programmation Direct3D.
Il est sûr de convertir un XMVECTOR* en D3DVECTOR* ou XMMATRIX* en D3DMATRIX* car Direct3D 9 ne fait aucune hypothèse d’alignement sur la structure de données entrante. Il est également sûr de convertir XMCOLOR en D3DCOLOR. Vous pouvez convertir une représentation flottante de couleur 4 en XMCOLOR via XMStoreColor() pour obtenir la DWORD 8:8:8 8 32 bits équivalente à D3DCOLOR.
Lorsque vous utilisez Direct3D 10.x ou Direct3D 11, vous allez généralement utiliser les 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 pour rendre ces opérations efficaces, ou pour utiliser les opérations XMStore*() pour convertir les données XMVECTOR et XMMATRIX en types de données corrects. Lorsque vous appelez des API Direct3D 10.x ou Direct3D 11 qui nécessitent un tableau float[4] de valeurs de couleur, vous pouvez caster un XMVECTOR* ou XMFLOAT4* contenant les données de couleur.
Portage à partir de D3DXMath
D3DXMath Type | Équivalent DirectXMath |
---|---|
D3DXFLOAT16 | MOITIÉ |
D3DXMATRIX | XMFLOAT4X4 |
D3DXMATRIXA16 | XMMATRIX ou XMFLOAT4X4A |
D3DXQUATERNION D3DXPLANE D3DXCOLOR |
XMVECTOR est utilisé plutôt que 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 | Équivalent DirectXMath |
---|---|
D3DX_PI | XM_PI |
D3DX_1BYPI | XM_1DIVPI |
D3DXToRadian | XMConvertToRadians |
D3DXToDegree | XMConvertToDegrees |
D3DXMath, fonction | Équivalent 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 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 yaw, pitch, roll, XMMatrixRotationRollPitchYaw prend le 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 (Notez que l’ordre des paramètres est différent : D3DXQuaternionRotationYawPitchRoll prend yaw, pitch, roll, XMQuaternionRotationRollPitchYaw prend pitch, yaw, roll) |
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 harmoniques sphériques pour DirectXMath sont disponibles séparément. Un DirectXMath équivalent à ID3DXMatrixStack est également disponible.
Rubriques connexes