Werken met D3DXMath
D3DXMath is een wiskundige helperbibliotheek voor Direct3D-toepassingen. D3DXMath is langstaand, is opgenomen in D3DX 9 en D3DX 10 en dateert ook terug naar oudere versies van DirectX.
Notitie
De D3DX-hulpprogrammabibliotheek (D3DX 9, D3DX 10 en D3DX 11) is afgeschaft voor Windows 8, dus we raden u ten zeerste aan om te migreren naar DirectXMath in plaats van D3DXMath te gebruiken.
DirectXMath deelt veel van dezelfde functionaliteit in D3DXMath en intern D3DXMath bevat een aantal processorspecifieke optimalisaties. Het belangrijkste verschil is dat D3DXMath wordt gehost in de D3DX9*.DLL's en D3DX10*.DLL's en dat zeer weinig van de functies zijn geïnlineerd. De DirectXMath Library-oproepconventie is expliciet SIMD-vriendelijk, terwijl D3DXMath belasting- en opslagconversies moet uitvoeren om SIMD-optimalisatie te implementeren.
DirectXMath en D3DXMath combineren
D3DX11 bevat geen D3DXMath. Over het algemeen raden we u aan DirectXMath te gebruiken. U kunt echter wel blijven koppelen aan D3DX9 en/of D3DX10 in uw toepassing. Daarom kunt u D3DXMath blijven gebruiken of tegelijkertijd D3DXMath en DirectXMath gebruiken in uw toepassing.
Het is over het algemeen veilig om een XMVECTOR* te casten voor gebruik in een functie die een D3DXVECTOR4* vereist, of om een XMMATRIX* te casten voor een functie die een D3DXMATRIX* vereist. De inverse is echter niet algemeen veilig omdat XMVECTOR en XMMATRIX 16 byte moeten zijn uitgelijnd, terwijl D3DXVECTOR4 en D3DXMATRIX geen dergelijke vereiste hebben. Als u niet aan deze vereiste voldoet, kunnen er tijdens runtime ongeldige uitlijningsuitzonderingen optreden.
Het is veilig om een XMVECTOR* te casten naar een functie die D3DXVECTOR2* of D3DXVECTOR3* gebruikt, maar niet andersom. Zowel uitlijningsproblemen als het feit dat D3DXVECTOR2 en D3DXVECTOR3 kleinere structuren zijn, maken dit een onveilige bewerking.
Notitie
D3DX (en daarom D3DXMath) wordt beschouwd als verouderd en is niet beschikbaar voor Windows Store-apps die worden uitgevoerd op Windows 8 en is niet opgenomen in de Windows 8 SDK voor desktop-apps.
DirectXMath gebruiken met Direct3D
Zowel DirectXMath als D3DXMath zijn optioneel bij het werken met Direct3D. Direct3D 9 gedefinieerde D3DMATRIX en D3DCOLOR als onderdeel van de Direct3D-API ter ondersteuning van de (nu verouderde) pijplijn met vaste functies. D3DXMath in D3DX9 breidt deze Direct3D 9-typen uit met algemene grafische wiskundige bewerkingen. Voor Direct3D 10.x en Direct3D 11 gebruikt de API alleen de programmeerbare pijplijn, zodat er geen API-specifieke structuur is voor matrices of kleurwaarden. Wanneer de nieuwere API's een kleurwaarde vereisen, nemen ze een expliciete matrix met floatwaarden of een algemene buffer met constante gegevens die worden geïnterpreteerd door de HLSL-shader. HLSL zelf kan ondersteuning bieden voor matrixindelingen voor rijen of kolommen, zodat de indeling helemaal aan u is (zie HLSL, Matrixvolgorde; als u kolom-primaire matrixindelingen in uw shaders gebruikt, moet u de DirectXMath-matrixgegevens transponeren terwijl u deze in uw constante bufferstructuren plaatst). Hoewel de DirectXMath- en D3DXMath-bibliotheken optioneel zijn, bieden beide algemene grafische functionaliteit en zijn ze daarom zeer handig bij het programmeren van Direct3D.
Het is veilig om een XMVECTOR* naar een D3DVECTOR* of XMMATRIX* te casten naar D3DMATRIX* omdat Direct3D 9 geen uitlijningsveronderstellingen over de binnenkomende gegevensstructuur maakt. Het is ook veilig om XMCOLOR naar D3DCOLOR te casten. U kunt een 4-floatweergave van kleur converteren naar XMCOLOR via XMStoreColor() om de 8:8:8:8:8 32-bits DWORD te verkrijgen die gelijk is aan D3DCOLOR.
Wanneer u met Direct3D 10.x of Direct3D 11 werkt, gebruikt u doorgaans DirectXMath-typen om een structuur te bouwen voor elk van uw constante buffers. In die gevallen is het grotendeels afhankelijk van uw vermogen om de uitlijning te beheren om deze efficiënt te maken, of om XMStore*() bewerkingen te gebruiken om XMVECTOR- en XMMATRIX-gegevens te converteren naar de juiste gegevenstypen. Wanneer u Direct3D 10.x- of Direct3D 11-API's aanroept waarvoor een float[4]-matrix met kleurwaarden is vereist, kunt u een XMVECTOR* of XMFLOAT4* met de kleurgegevens casten.
Overzetten vanuit D3DXMath
D3DXMath-type | DirectXMath-equivalent |
---|---|
D3DXFLOAT16 | HALF |
D3DXMATRIX | XMFLOAT4X4 |
D3DXMATRIXA16 | XMMATRIX of XMFLOAT4X4A |
D3DXQUATERNION D3DXPLANE D3DXCOLOR |
XMVECTOR- wordt gebruikt in plaats van het gebruik van unieke typen. Daarom moet u waarschijnlijk een XMFLOAT4gebruiken. Opmerking:**D3DXQUATERNION::operator *** roept de D3DXQuaternionMultiply functie aan, waarmee twee quaternionen worden vermenigvuldigd. Maar, tenzij u expliciet de XMQuaternionMultiply functie gebruikt, krijgt u een onjuist antwoord wanneer u **XMVECTOR::operator *** op een quaternion gebruikt. |
D3DXVECTOR2 | XMFLOAT2 |
D3DXVECTOR2_16F | XMHALF2 |
D3DXVECTOR3 | XMFLOAT3 |
D3DXVECTOR4 |
XMFLOAT4(of als u kunt garanderen dat de gegevens zijn uitgelijnd op 16 bytes, XMVECTOR of XMFLOAT4A ) |
D3DXVECTOR4_16F | XMHALF4 |
Notitie
Er is geen direct equivalent aan D3DXVECTOR3_16F in XNAMath.
D3DXMath Macro | DirectXMath-equivalent |
---|---|
D3DX_PI | XM_PI |
D3DX_1BYPI | XM_1DIVPI |
D3DXToRadian | XMConvertToRadians |
D3DXToDegree | XMConvertToDegrees |
D3DXMath-functie | DirectXMath-equivalent |
---|---|
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 of XMVector2LengthEst |
D3DXVec2LengthSq | XMVector2LengthSq |
D3DXVec2Dot | XMVector2Dot |
D3DXVec2CCW | XMVector2Cross |
D3DXVec2Add | XMVectorAdd |
D3DXVec2Subtract | XMVectorSubtract |
D3DXVec2Minimize | XMVectorMin |
D3DXVec2Maximize | XMVectorMax |
D3DXVec2Scale | XMVectorScale |
D3DXVec2Lerp | XMVectorLerp of XMVectorLerpV |
D3DXVec2Normalize | XMVector2Normalize of XMVector2NormalizeEst |
D3DXVec2Hermite | XMVectorHermite of XMVectorHermiteV |
D3DXVec2CatmullRom | XMVectorCatmullRom of XMVectorCatmullRomV |
D3DXVec2BaryCentric | XMVectorBaryCentric of XMVectorBaryCentricV |
D3DXVec2Transform | XMVector2Transform |
D3DXVec2TransformCoord | XMVector2TransformCoord |
D3DXVec2TransformNormal | XMVector2TransformNormal |
D3DXVec2TransformArray | XMVector2TransformStream |
D3DXVec2TransformCoordArray | XMVector2TransformCoordStream |
D3DXVec2TransformNormalArray | XMVector2TransformNormalStream |
D3DXVec3Length | XMVector3Length of XMVector3LengthEst |
D3DXVec3LengthSq | XMVector3LengthSq |
D3DXVec3Dot | XMVector3Dot |
D3DXVec3Cross | XMVector3Cross |
D3DXVec3Add | XMVectorAdd |
D3DXVec3Subtract | XMVectorSubtract |
D3DXVec3Minimize | XMVectorMin |
D3DXVec3Maximize | XMVectorMax |
D3DXVec3Scale | XMVectorScale |
D3DXVec3Lerp | XMVectorLerp of XMVectorLerpV |
D3DXVec3Normalize | XMVector3Normalize of XMVector3NormalizeEst |
D3DXVec3Hermite | XMVectorHermite of XMVectorHermiteV |
D3DXVec3CatmullRom | XMVectorCatmullRom of XMVectorCatmullRomV |
D3DXVec3BaryCentric | XMVectorBaryCentric of XMVectorBaryCentricV |
D3DXVec3Transform | XMVector3Transform |
D3DXVec3TransformCoord | XMVector3TransformCoord |
D3DXVec3TransformNormal | XMVector3TransformNormal |
D3DXVec3TransformArray | XMVector3TransformStream |
D3DXVec3TransformCoordArray | XMVector3TransformCoordStream |
D3DXVec3TransformNormalArray | XMVector3TransformNormalStream |
D3DXVec3Project | XMVector3Project |
D3DXVec3Unproject | XMVector3Unproject |
D3DXVec3ProjectArray | XMVector3ProjectStream |
D3DXVec3UnprojectArray | XMVector3UnprojectStream |
D3DXVec4Length | XMVector4Length of XMVector4LengthEst |
D3DXVec4LengthSq | XMVector4LengthSq |
D3DXVec4Dot | XMVector4Dot |
D3DXVec4Add | XMVectorAdd |
D3DXVec4Subtract | XMVectorSubtract |
D3DXVec4Minimize | XMVectorMin |
D3DXVec4Maximize | XMVectorMax |
D3DXVec4Scale | XMVectorScale |
D3DXVec4Lerp | XMVectorLerp of XMVectorLerpV |
D3DXVec4Cross | XMVector4Cross |
D3DXVec4Normalize | XMVector4Normalize of XMVector4NormalizeEst |
D3DXVec4Hermite | XMVectorHermite of XMVectorHermiteV |
D3DXVec4CatmullRom | XMVectorCatmullRom of XMVectorCatmullRomV |
D3DXVec4BaryCentric | XMVectorBaryCentric of 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 (Let op: de volgorde van de parameters is anders: D3DXMatrixRotationYawPitchRoll neemt yaw, pitch, roll, XMMatrixRotationRollPitchYaw 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 (Let op: de volgorde van parameters is anders: D3DXQuaternionRotationYawPitchRoll neemt yaw, pitch, roll, XMQuaternionRotationRollPitchYaw neemt pitch, yaw, roll) |
D3DXQuaternionMultiply | XMQuaternionMultiply |
D3DXQuaternionNormalize | XMQuaternionNormalize of XMQuaternionNormalizeEst |
D3DXQuaternionInverse | XMQuaternionInverse |
D3DXQuaternionLn | XMQuaternionLn- |
D3DXQuaternionExp | XMQuaternionExp |
D3DXQuaternionSlerp | XMQuaternionSlerp of XMQuaternionSlerpV |
D3DXQuaternionSquad | XMQuaternionSquad of XMQuaternionSquadV |
D3DXQuaternionSquadSetup | XMQuaternionSquadSetup |
D3DXQuaternionBaryCentric | XMQuaternionBaryCentric of XMQuaternionBaryCentricV |
D3DXPlaneDot | XMPlaneDot |
D3DXPlaneDotCoord | XMPlaneDotCoord |
D3DXPlaneDotNormal | XMPlaneDotNormal |
D3DXPlaneScale | XMVectorScale |
D3DXPlaneNormalize | XMPlaneNormalize of XMPlaneNormalizeEst |
D3DXPlaneIntersectLine | XMPlaneIntersectLine |
D3DXPlaneFromPointNormal | XMPlaneFromPointNormal |
D3DXPlaneFromPoints | XMPlaneFromPoints |
D3DXPlaneTransform | XMPlaneTransform |
D3DXPlaneTransformArray | XMPlaneTransformStream |
D3DXColorNegative | XMColorNegative |
D3DXColorAdd | XMVectorAdd |
D3DXColorSubtract | XMVectorSubtract |
D3DXColorScale | XMVectorScale |
D3DXColorModulate | XMColorModulate |
D3DXColorLerp | XMVectorLerp of XMVectorLerpV |
D3DXColorAdjustSaturation | XMColorAdjustSaturation |
D3DXColorAdjustContrast | XMColorAdjustContrast |
D3DXFresnelTerm | XMFresnelTerm |
Notitie
Spherical Harmonics functies voor DirectXMath zijn afzonderlijk beschikbaar. Er is ook een DirectXMath-equivalent aan ID3DXMatrixStack beschikbaar.
Verwante onderwerpen