Trabalhando com D3DXMath
D3DXMath é uma biblioteca auxiliar matemática para aplicativos Direct3D. O D3DXMath é de longa data, está incluído no D3DX 9 e no D3DX 10 e também remonta a versões mais antigas do DirectX.
Observação
A biblioteca de utilitários D3DX (D3DX 9, D3DX 10 e D3DX 11) foi preterida para o Windows 8, portanto, é altamente recomendável migrar para o DirectXMath em vez de usar D3DXMath.
O DirectXMath compartilha grande parte da mesma funcionalidade no D3DXMath e, internamente, o D3DXMath inclui várias otimizações específicas do processador. A principal diferença é que D3DXMath está hospedado no D3DX9*. DLLs e D3DX10*. As DLLs e muito poucas das funções estão embutidas. A convenção de chamada da Biblioteca DirectXMath é explicitamente amigável ao SIMD, enquanto o D3DXMath precisa executar conversões de carregamento e armazenamento para implementar a otimização do SIMD.
Misturando DirectXMath e D3DXMath
D3DX11 não contém D3DXMath e, em geral, recomendamos usar DirectXMath. No entanto, você está livre para continuar a vincular a D3DX9 e/ou D3DX10 em seu aplicativo e, portanto, pode continuar a usar D3DXMath ou usar D3DXMath e DirectXMath em seu aplicativo ao mesmo tempo.
Em geral, é seguro converter um XMVECTOR* em uma função que usa D3DXVECTOR4* ou converter um XMMATRIX* em uma função que usa D3DXMATRIX*. No entanto, o inverso não é geralmente seguro porque XMVECTOR e XMMATRIX devem estar alinhados a 16 bytes, enquanto D3DXVECTOR4 e D3DXMATRIX não têm esse requisito. A falha ao aderir a esse requisito pode resultar em exceções de alinhamento inválidas no runtime.
É seguro converter um XMVECTOR* em uma função que usa D3DXVECTOR2* ou D3DXVECTOR3*, mas não vice-versa. Tanto as preocupações de alinhamento quanto o fato de que D3DXVECTOR2 e D3DXVECTOR3 são estruturas menores tornam essa uma operação não segura.
Observação
D3DX (e, portanto, D3DXMath) é considerado herdado e não está disponível para aplicativos da Windows Store que são executados no Windows 8 e não estão incluídos no SDK do Windows 8 para aplicativos da área de trabalho.
Usando DirectXMath com Direct3D
DirectXMath e D3DXMath são opcionais ao trabalhar com Direct3D. O Direct3D 9 definiu D3DMATRIX e D3DCOLOR como parte da API do Direct3D para dar suporte ao pipeline de funções fixas (agora herdado). O D3DXMath em D3DX9 estende esses tipos do Direct3D 9 com operações matemáticas gráficas comuns. Para Direct3D 10.x e Direct3D 11, a API usa apenas o pipeline programável para que não haja nenhuma estrutura específica da API para matrizes ou valores de cor. Quando as APIs mais recentes exigem um valor de cor, elas assumem uma matriz explícita de valores float ou um buffer genérico de dados constantes que é interpretado pelo sombreador HLSL. O próprio HLSL pode dar suporte a formatos de matriz principal de linha ou coluna principal, portanto, o layout cabe inteiramente a você (para obter mais informações, consulte HLSL, Ordenação de Matriz; se você usar formatos de matriz de coluna principal em seus sombreadores, precisará transpor os dados da matriz DirectXMath à medida que os coloca em suas estruturas de buffer constantes). Embora sejam opcionais, as bibliotecas DirectXMath e D3DXMath fornecem funcionalidades comuns relacionadas a elementos gráficos e, portanto, são extremamente convenientes ao fazer programação Direct3D.
É seguro converter um XMVECTOR* em um D3DVECTOR* ou XMMATRIX* para D3DMATRIX* já que o Direct3D 9 não faz suposições de alinhamento sobre a estrutura de dados de entrada. Também é seguro converter XMCOLOR em D3DCOLOR. Você pode converter uma representação de cor de 4 float em XMCOLOR via XMStoreColor() para obter o DWORD de 8:8:8:8 de 32 bits equivalente a D3DCOLOR.
Ao trabalhar com Direct3D 10.x ou Direct3D 11, você normalmente usará tipos DirectXMath para criar uma estrutura para cada um de seus buffers constantes e, nesses casos, depende em grande parte da sua capacidade de controlar o alinhamento para torná-los eficientes ou usar operações XMStore*() para converter dados XMVECTOR e XMMATRIX para os tipos de dados corretos. Ao chamar APIs direct3D 10.x ou Direct3D 11 que exigem uma matriz float[4] de valores de cor, você pode converter um XMVECTOR* ou XMFLOAT4* contendo os dados de cor.
Portabilidade de D3DXMath
Tipo D3DXMath | Equivalente a DirectXMath |
---|---|
D3DXFLOAT16 | METADE |
D3DXMATRIX | XMFLOAT4X4 |
D3DXMATRIXA16 | XMMATRIX ou XMFLOAT4X4A |
D3DXQUATERNION D3DXPLANE D3DXCOLOR |
XMVECTOR é usado em vez de ter tipos exclusivos, portanto, você provavelmente precisará usar uma nota XMFLOAT4:**D3DXQUATERNION::operator *** chama a função D3DXQuaternionMultiply , que multiplica dois quatérnions. Mas, a menos que você use explicitamente a função XMQuaternionMultiply , você receberá uma resposta incorreta ao usar **XMVECTOR::operator *** em um quatérnion. |
D3DXVECTOR2 | XMFLOAT2 |
D3DXVECTOR2_16F | XMHALF2 |
D3DXVECTOR3 | XMFLOAT3 |
D3DXVECTOR4 | XMFLOAT4(ou se você puder garantir que os dados estejam alinhados em 16 bytes, XMVECTOR ou XMFLOAT4A ) |
D3DXVECTOR4_16F | XMHALF4 |
Observação
Não há equivalente direto a D3DXVECTOR3_16F no XNAMath.
D3DXMath Macro | Equivalente a DirectXMath |
---|---|
D3DX_PI | XM_PI |
D3DX_1BYPI | XM_1DIVPI |
D3DXToRadian | XMConvertToRadians |
D3DXToDegree | XMConvertToDegrees |
Função D3DXMath | Equivalente a 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 |
D3DXVec2Adicionar | 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 (Observe que a ordem dos parâmetros é diferente: D3DXMatrixRotationYawPitchRoll leva yaw, pitch, roll, XMMatrixRotationRollPitchYaw leva 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 (Observe que a ordem dos parâmetros é diferente: D3DXQuaternionRotationYawPitchRoll leva yaw, pitch, roll, XMQuaternionRotationRollPitchYaw leva 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 |
Observação
As funções harmônicas esféricas para DirectXMath estão disponíveis separadamente. Um DirectXMath equivalente a ID3DXMatrixStack também está disponível.
Tópicos relacionados
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de