Verwenden von D3DXMath
D3DXMath ist eine Mathematische Hilfsbibliothek für Direct3D-Anwendungen. D3DXMath ist ein langjähriges Unternehmen, ist in D3DX 9 und D3DX 10 enthalten und geht auch auf ältere Versionen von DirectX zurück.
Hinweis
Die D3DX-Hilfsbibliothek (D3DX 9, D3DX 10 und D3DX 11) ist für Windows 8 veraltet. Daher wird dringend empfohlen, dass Sie zu DirectXMath migrieren und nicht D3DXMath verwenden.
DirectXMath hat einen Großteil der gleichen Funktionen in D3DXMath, und intern enthält D3DXMath eine Reihe von prozessorspezifischen Optimierungen. Der Hauptunterschied besteht darin, dass D3DXMath im D3DX9* gehostet wird. DLLs und D3DX10*. DLLs und nur sehr wenige Funktionen sind inlined. Die Aufrufkonvention der DirectXMath-Bibliothek ist explizit SIMD-freundlich, während D3DXMath Lade- und Speicherkonvertierungen durchführen muss, um die SIMD-Optimierung zu implementieren.
Mischen von DirectXMath und D3DXMath
D3DX11 enthält nicht D3DXMath, und im Allgemeinen wird stattdessen die Verwendung von DirectXMath empfohlen. Sie können jedoch weiterhin mit D3DX9 und/oder D3DX10 in Ihrer Anwendung verknüpfen. Daher können Sie D3DXMath weiterhin verwenden oder D3DXMath und DirectXMath gleichzeitig in Ihrer Anwendung verwenden.
Im Allgemeinen ist es sicher, einen XMVECTOR* in eine Funktion zu umwandeln, die D3DXVECTOR4* verwendet, oder eine XMMATRIX* in eine Funktion zu umwandeln, die D3DXMATRIX* akzeptiert. Die Inverse ist jedoch nicht allgemein sicher, da XMVECTOR und XMMATRIX 16 Byte ausgerichtet sein müssen, während D3DXVECTOR4 und D3DXMATRIX keine solche Anforderung haben. Wenn diese Anforderung nicht eingehalten wird, kann dies zur Laufzeit zu ungültigen Ausrichtungsausnahmen führen.
Es ist sicher, einen XMVECTOR* in eine Funktion zu umwandeln, die D3DXVECTOR2* oder D3DXVECTOR3* akzeptiert, aber nicht umgekehrt. Sowohl Ausrichtungsprobleme als auch die Tatsache, dass D3DXVECTOR2 und D3DXVECTOR3 kleinere Strukturen sind, machen dies zu einem unsicheren Vorgang.
Hinweis
D3DX (und damit D3DXMath) gilt als Legacy und ist für Windows Store-Apps, die unter Windows 8 ausgeführt werden, nicht verfügbar und nicht im Windows 8 SDK für Desktop-Apps enthalten.
Verwenden von DirectXMath mit Direct3D
Sowohl DirectXMath als auch D3DXMath sind optional, wenn Sie mit Direct3D arbeiten. Direct3D 9 hat D3DMATRIX und D3DCOLOR als Teil der Direct3D-API zur Unterstützung der (jetzt legacy) Fixed-Function-Pipeline definiert. D3DXMath in D3DX9 erweitert diese Direct3D 9-Typen um gängige mathematische Grafikvorgänge. Für Direct3D 10.x und Direct3D 11 verwendet die API nur die programmierbare Pipeline, sodass es keine API-spezifische Struktur für Matrizen oder Farbwerte gibt. Wenn die neueren APIs einen Farbwert benötigen, verwenden sie ein explizites Array von Floatwerten oder einen generischen Puffer von Konstantendaten, der vom HLSL-Shader interpretiert wird. HLSL selbst kann entweder Zeilen-Haupt- oder Spalten-Hauptmatrixformate unterstützen. Daher liegt das Layout ganz bei Ihnen (weitere Informationen finden Sie unter HLSL, Matrixreihenfolge. Wenn Sie Spalten-Hauptmatrixformate in Ihren Shadern verwenden, müssen Sie die DirectXMath-Matrixdaten transponieren, wenn Sie sie in Ihre konstanten Pufferstrukturen platzieren). Die Bibliotheken DirectXMath und D3DXMath sind zwar optional, bieten jedoch beide allgemeine grafikbezogene Funktionen und sind daher bei der Direct3D-Programmierung äußerst praktisch.
Es ist sicher, einen XMVECTOR* in einen D3DVECTOR* oder XMMATRIX* in D3DMATRIX* zu umwandeln, da Direct3D 9 keine Ausrichtungsannahmen über die eingehende Datenstruktur trifft. Es ist auch sicher, XMCOLOR in D3DCOLOR zu umwandeln. Sie können eine 4-Float-Darstellung von Farbe über XMStoreColor() in XMCOLOR konvertieren, um das 8:8:8:8:8 32-Bit-DWORD abzurufen, das D3DCOLOR entspricht.
Wenn Sie mit Direct3D 10.x oder Direct3D 11 arbeiten, verwenden Sie in der Regel DirectXMath-Typen, um eine Struktur für jeden Ihrer Konstantenpuffer zu erstellen. In diesen Fällen hängt dies hauptsächlich von Ihrer Fähigkeit ab, die Ausrichtung zu steuern, um diese effizient zu gestalten, oder XMStore*()-Vorgänge zum Konvertieren von XMVECTOR- und XMMATRIX-Daten in die richtigen Datentypen. Beim Aufrufen von Direct3D 10.x- oder Direct3D 11-APIs, die ein float[4]-Array von Farbwerten erfordern, können Sie einen XMVECTOR* oder XMFLOAT4* mit den Farbdaten umwandeln.
Portieren von D3DXMath
D3DXMath-Typ | DirectXMath-Entsprechung |
---|---|
D3DXFLOAT16 | HÄLFTE |
D3DXMATRIX | XMFLOAT4X4 |
D3DXMATRIXA16 | XMMATRIX oder XMFLOAT4X4A |
D3DXQUATERNION D3DXPLANE D3DXCOLOR |
XMVECTOR wird anstelle eindeutiger Typen verwendet. Daher müssen Sie wahrscheinlich einen XMFLOAT4-Hinweisverwenden:**D3DXQUATERNION::operator *** ruft die D3DXQuaternionMultiply-Funktion auf, die zwei Quaternionen multipliziert. Wenn Sie jedoch nicht explizit die XMQuaternionMultiply-Funktion verwenden, erhalten Sie eine falsche Antwort, wenn Sie **XMVECTOR::operator *** für ein Quaternion verwenden. |
D3DXVECTOR2 | XMFLOAT2 |
D3DXVECTOR2_16F | XMHALF2 |
D3DXVECTOR3 | XMFLOAT3 |
D3DXVECTOR4 | XMFLOAT4 (oder, wenn Sie garantieren können, dass die Daten 16-Byte-ausgerichtet sind, XMVECTOR oder XMFLOAT4A ) |
D3DXVECTOR4_16F | XMHALF4 |
Hinweis
Es gibt keine direkte Entsprechung zu D3DXVECTOR3_16F in XNAMath.
D3DXMath-Makro | DirectXMath-Entsprechung |
---|---|
D3DX_PI | XM_PI |
D3DX_1BYPI | XM_1DIVPI |
D3DXToRadian | XMConvertToRadians |
D3DXToDegree | XMConvertToDegrees |
D3DXMath-Funktion | DirectXMath-Entsprechung |
---|---|
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 oder XMVector2LengthEst |
D3DXVec2LengthSq | XMVector2LengthSq |
D3DXVec2Dot | XMVector2Dot |
D3DXVec2CCW | XMVector2Cross |
D3DXVec2Add | XMVectorAdd |
D3DXVec2Subtract | XMVectorSubtract |
D3DXVec2Minimize | XMVectorMin |
D3DXVec2Maximize | XMVectorMax |
D3DXVec2Scale | XMVectorScale |
D3DXVec2Lerp | XMVectorLerp oder XMVectorLerpV |
D3DXVec2Normalize | XMVector2Normalize oder XMVector2NormalizeEst |
D3DXVec2Hermite | XMVectorHermite oder XMVectorHermiteV |
D3DXVec2CatmullRom | XMVectorCatmullRom oder XMVectorCatmullRomV |
D3DXVec2BaryCentric | XMVectorBaryCentric oder XMVectorBaryCentricV |
D3DXVec2Transform | XMVector2Transform |
D3DXVec2TransformCoord | XMVector2TransformCoord |
D3DXVec2TransformNormal | XMVector2TransformNormal |
D3DXVec2TransformArray | XMVector2TransformStream |
D3DXVec2TransformCoordArray | XMVector2TransformCoordStream |
D3DXVec2TransformNormalArray | XMVector2TransformNormalStream |
D3DXVec3Length | XMVector3Length oder XMVector3LengthEst |
D3DXVec3LengthSq | XMVector3LengthSq |
D3DXVec3Dot | XMVector3Dot |
D3DXVec3Cross | XMVector3Cross |
D3DXVec3Add | XMVectorAdd |
D3DXVec3Subtract | XMVectorSubtract |
D3DXVec3Minimize | XMVectorMin |
D3DXVec3Maximize | XMVectorMax |
D3DXVec3Scale | XMVectorScale |
D3DXVec3Lerp | XMVectorLerp oder XMVectorLerpV |
D3DXVec3Normalize | XMVector3Normalize oder XMVector3NormalizeEst |
D3DXVec3Hermite | XMVectorHermite oder XMVectorHermiteV |
D3DXVec3CatmullRom | XMVectorCatmullRom oder XMVectorCatmullRomV |
D3DXVec3BaryCentric | XMVectorBaryCentric oder XMVectorBaryCentricV |
D3DXVec3Transform | XMVector3Transform |
D3DXVec3TransformCoord | XMVector3TransformCoord |
D3DXVec3TransformNormal | XMVector3TransformNormal |
D3DXVec3TransformArray | XMVector3TransformStream |
D3DXVec3TransformCoordArray | XMVector3TransformCoordStream |
D3DXVec3TransformNormalArray | XMVector3TransformNormalStream |
D3DXVec3Project | XMVector3Project |
D3DXVec3Unproject | XMVector3Unproject |
D3DXVec3ProjectArray | XMVector3ProjectStream |
D3DXVec3UnprojectArray | XMVector3UnprojectStream |
D3DXVec4Length | XMVector4Length oder XMVector4LengthEst |
D3DXVec4LengthSq | XMVector4LengthSq |
D3DXVec4Dot | XMVector4Dot |
D3DXVec4Add | XMVectorAdd |
D3DXVec4Subtract | XMVectorSubtract |
D3DXVec4Minimize | XMVectorMin |
D3DXVec4Maximize | XMVectorMax |
D3DXVec4Scale | XMVectorScale |
D3DXVec4Lerp | XMVectorLerp oder XMVectorLerpV |
D3DXVec4Cross | XMVector4Cross |
D3DXVec4Normalize | XMVector4Normalize oder XMVector4NormalizeEst |
D3DXVec4Hermite | XMVectorHermite oder XMVectorHermiteV |
D3DXVec4CatmullRom | XMVectorCatmullRom oder XMVectorCatmullRomV |
D3DXVec4BaryCentric | XMVectorBaryCentric oder 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 (Beachten Sie, dass die Reihenfolge der Parameter unterschiedlich ist: D3DXMatrixRotationYawPitchRoll takes yaw, pitch, roll, XMMatrixRotationRollPitchYaw takes 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 (Beachten Sie, dass die Reihenfolge der Parameter unterschiedlich ist: D3DXQuaternionRotationYawPitchRoll takes yaw, pitch, roll, XMQuaternionRotationRollPitchYaw takes pitch, yaw, roll) |
D3DXQuaternionMultiply | XMQuaternionMultiply |
D3DXQuaternionNormalize | XMQuaternionNormalize oder XMQuaternionNormalizeEst |
D3DXQuaternionInverse | XMQuaternionInverse |
D3DXQuaternionLn | XMQuaternionLn |
D3DXQuaternionExp | XMQuaternionExp |
D3DXQuaternionSlerp | XMQuaternionSlerp oder XMQuaternionSlerpV |
D3DXQuaternionSquad | XMQuaternionSquad oder XMQuaternionSquadV |
D3DXQuaternionSquadSetup | XMQuaternionSquadSetup |
D3DXQuaternionBaryCentric | XMQuaternionBaryCentric oder XMQuaternionBaryCentricV |
D3DXPlaneDot | XMPlaneDot |
D3DXPlaneDotCoord | XMPlaneDotCoord |
D3DXPlaneDotNormal | XMPlaneDotNormal |
D3DXPlaneScale | XMVectorScale |
D3DXPlaneNormalize | XMPlaneNormalize oder XMPlaneNormalizeEst |
D3DXPlaneIntersectLine | XMPlaneIntersectLine |
D3DXPlaneFromPointNormal | XMPlaneFromPointNormal |
D3DXPlaneFromPoints | XMPlaneFromPoints |
D3DXPlaneTransform | XMPlaneTransform |
D3DXPlaneTransformArray | XMPlaneTransformStream |
D3DXColorNegative | XMColorNegative |
D3DXColorAdd | XMVectorAdd |
D3DXColorSubtract | XMVectorSubtract |
D3DXColorScale | XMVectorScale |
D3DXColorModulate | XMColorModulate |
D3DXColorLerp | XMVectorLerp oder XMVectorLerpV |
D3DXColorAdjustSaturation | XMColorAdjustSaturation |
D3DXColorAdjustContrast | XMColorAdjustContrast |
D3DXFresnelTerm | XMFresnelTerm |
Hinweis
Sphärische Harmoniefunktionen für DirectXMath sind separat verfügbar. Ein DirectXMath-Äquivalent zu ID3DXMatrixStack ist ebenfalls verfügbar.
Zugehörige Themen
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für