Utilisation de D3DXMath
D3DXMath est une bibliothèque d’assistance mathématique pour les applications Direct3D. D3DXMath est de longue date, est inclus dans D3DX 9 et D3DX 10, et remonte également aux versions antérieures de DirectX.
Notes
La bibliothèque d’utilitaireS D3DX (D3DX 9, D3DX 10 et D3DX 11) étant déconseillée pour Windows 8, nous vous recommandons vivement de migrer vers DirectXMath plutôt que d’utiliser D3DXMath.
DirectXMath partage une grande partie des mêmes fonctionnalités dans D3DXMath, et D3DXMath inclut en interne 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 incluses. La convention d’appel de la bibliothèque DirectXMath est explicitement compatible AVEC SIMD, 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 à lier 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 généralement sûr de caster un XMVECTOR* en fonction qui prend D3DXVECTOR4* ou de caster un XMMATRIX* en fonction qui prend D3DXMATRIX*. L’inverse n’est toutefois pas généralement sûr, car XMVECTOR et XMMATRIX doivent être alignés sur 16 octets, tandis que D3DXVECTOR4 et D3DXMATRIX n’ont aucune exigence de ce type. Le non-respect de cette exigence peut entraîner des exceptions d’alignement non valides au moment de l’exécution.
Il est sûr de caster un XMVECTOR* vers une fonction qui prend D3DXVECTOR2* ou D3DXVECTOR3*, mais pas inversement. Les deux problèmes d’alignement et le fait que D3DXVECTOR2 et D3DXVECTOR3 sont des structures plus petites font de cette opération une opération non sécurisée.
Notes
D3DX (et donc 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 n’est pas inclus 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 à fonction fixe (maintenant hérité). 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, de sorte 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 principale, de sorte que la disposition vous appartient entièrement (pour plus d’informations, consultez HLSL, Classement des matrices ; si vous utilisez des formats de matrice de colonne principale dans vos nuanceurs, vous devez transposer les données de matrice DirectXMath lorsque 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 graphiques courantes 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 n’émet aucune hypothèse d’alignement sur la structure de données entrante. Il est également sûr de caster XMCOLOR en D3DCOLOR. Vous pouvez convertir une représentation 4-float de couleur en XMCOLOR via XMStoreColor() pour obtenir le DWORD 8:8:8:8:8 32 bits équivalent à D3DCOLOR.
Lorsque vous utilisez Direct3D 10.x ou Direct3D 11, vous utilisez généralement 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 à utiliser les opérations XMStore*() pour convertir les données XMVECTOR et XMMATRIX vers les types de données appropriés. 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 donc probablement utiliser un XMFLOAT4Remarque :**D3DXQUATERNION::operator *** appelle la fonction D3DXQuaternionMultiply , qui multiplie deux quaternions. Toutefois, à moins d’utiliser explicitement la fonction XMQuaternionMultiply , vous obtenez une réponse incorrecte lorsque vous utilisez **XMVECTOR::operator *** sur un quaternion. |
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 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
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour