Trabajo con D3DXMath

D3DXMath es una biblioteca auxiliar matemática para aplicaciones de Direct3D. D3DXMath es de larga duración, se incluye en D3DX 9 y D3DX 10, y también se remonta a versiones anteriores de DirectX.

Nota:

La biblioteca de utilidades D3DX (D3DX 9, D3DX 10 y D3DX 11) está en desuso para Windows 8, por lo que se recomienda encarecidamente migrar a DirectXMath en lugar de usar D3DXMath.

 

DirectXMath comparte gran parte de la misma funcionalidad en D3DXMath e internamente D3DXMath incluye una serie de optimizaciones específicas del procesador. La diferencia clave es que D3DXMath se hospeda en D3DX9*. DLL y D3DX10*. Los archivos DLL y muy pocas de las funciones están insertadas. La convención de llamada de la biblioteca DirectXMath es explícitamente compatible con SIMD, mientras que D3DXMath tiene que realizar conversiones de carga y almacenamiento para implementar la optimización de SIMD.

Mezcla de DirectXMath y D3DXMath

D3DX11 no contiene D3DXMath y, en general, se recomienda usar DirectXMath en su lugar. Sin embargo, es libre de seguir vinculando a D3DX9 o D3DX10 en la aplicación y, por lo tanto, puede seguir usando D3DXMath o usar D3DXMath y DirectXMath en la aplicación al mismo tiempo.

En general, es seguro convertir un XMVECTOR* en una función que toma D3DXVECTOR4* o convertir un XMMATRIX* en una función que toma D3DXMATRIX*. Sin embargo, el inverso no suele ser seguro porque XMVECTOR y XMMATRIX deben estar alineados con 16 bytes, mientras que D3DXVECTOR4 y D3DXMATRIX no tienen este requisito. Si no se cumple este requisito, se pueden producir excepciones de alineación no válidas en tiempo de ejecución.

Es seguro convertir un XMVECTOR* en una función que toma D3DXVECTOR2* o D3DXVECTOR3*, pero no viceversa. Tanto los problemas de alineación como el hecho de que D3DXVECTOR2 y D3DXVECTOR3 son estructuras más pequeñas hacen que sea una operación no segura.

Nota:

D3DX (y, por lo tanto, D3DXMath) se considera heredado y no está disponible para las aplicaciones de la Tienda Windows que se ejecutan en Windows 8 y no se incluyen en el SDK de Windows 8 para aplicaciones de escritorio.

 

Uso de DirectXMath con Direct3D

Tanto DirectXMath como D3DXMath son opcionales al trabajar con Direct3D. Direct3D 9 definió D3DMATRIX y D3DCOLOR como parte de la API de Direct3D en compatibilidad con la canalización de función fija (ahora heredada). D3DXMath en D3DX9 amplía estos tipos de Direct3D 9 con operaciones matemáticas de gráficos comunes. Para Direct3D 10.x y Direct3D 11, la API usa solo la canalización programable, por lo que no hay ninguna estructura específica de la API para matrices o valores de color. Cuando las API más recientes requieren un valor de color, toman una matriz explícita de valores float o un búfer genérico de datos constantes interpretados por el sombreador HLSL. El propio HLSL puede admitir formatos de matriz de fila principal o de columna, por lo que el diseño está completamente al tanto (para obtener más información, vea HLSL, Matrix Ordering; si usa formatos de matriz principal de columna en los sombreadores, debe transponer los datos de matriz de DirectXMath a medida que lo coloca en las estructuras de búfer constante). Aunque es opcional, las bibliotecas DirectXMath y D3DXMath proporcionan funciones comunes relacionadas con los gráficos y, por tanto, son extremadamente cómodas al realizar la programación de Direct3D.

Es seguro convertir un XMVECTOR* en un D3DVECTOR* o XMMATRIX* en D3DMATRIX*, ya que Direct3D 9 no realiza suposiciones de alineación sobre la estructura de datos entrantes. También es seguro convertir XMCOLOR a D3DCOLOR. Puede convertir una representación flotante de color en XMCOLOR a través de XMStoreColor() para obtener la DWORD de 8:8:8:8 de 32 bits equivalente a D3DCOLOR.

Cuando trabaje con Direct3D 10.x o Direct3D 11, normalmente usará tipos DirectXMath para crear una estructura para cada uno de los búferes de constantes y, en esos casos, depende en gran medida de la capacidad de controlar la alineación para hacer que estas operaciones sean eficaces o usar XMStore*() para convertir datos XMVECTOR y XMMATRIX en los tipos de datos correctos. Al llamar a las API de Direct3D 10.x o Direct3D 11 que requieren una matriz float[4] de valores de color, puede convertir un XMVECTOR* o XMFLOAT4* que contenga los datos de color.

Migración desde D3DXMath

Tipo D3DXMath Equivalente de DirectXMath
D3DXFLOAT16 MITAD
D3DXMATRIX XMFLOAT4X4
D3DXMATRIXA16 XMMATRIX o XMFLOAT4X4A
D3DXQUATERNION
D3DXPLANE
D3DXCOLOR
XMVECTOR se usa en lugar de tener tipos únicos, por lo que es probable que tenga que usar una nota XMFLOAT4:**D3DXQUATERNION::operator *** llama a la función D3DXQuaternionMultiply , que multiplica dos cuaterniones. Pero, a menos que use explícitamente la función XMQuaternionMultiply , obtendrá una respuesta incorrecta cuando use **XMVECTOR::operator *** en un cuaternión.
D3DXVECTOR2 XMFLOAT2
D3DXVECTOR2_16F XMHALF2
D3DXVECTOR3 XMFLOAT3
D3DXVECTOR4 XMFLOAT4(o si puede garantizar que los datos están alineados con 16 bytes, XMVECTOR o XMFLOAT4A )
D3DXVECTOR4_16F XMHALF4

 

Nota

No hay ningún equivalente directo a D3DXVECTOR3_16F en XNAMath.

 

D3DXMath Macro Equivalente de DirectXMath
D3DX_PI XM_PI
D3DX_1BYPI XM_1DIVPI
D3DXToRadian XMConvertToRadians
D3DXToDegree XMConvertToDegrees

 

Función D3DXMath Equivalente de 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 o XMVector2LengthEst
D3DXVec2LengthSq XMVector2LengthSq
D3DXVec2Dot XMVector2Dot
D3DXVec2CCW XMVector2Cross
D3DXVec2Agregar XMVectorAdd
D3DXVec2Subtract XMVectorSubtract
D3DXVec2Minimize XMVectorMin
D3DXVec2Maximize XMVectorMax
D3DXVec2Scale XMVectorScale
D3DXVec2Lerp XMVectorLerp o XMVectorLerpV
D3DXVec2Normalize XMVector2Normalize o XMVector2NormalizeEst
D3DXVec2Hermite XMVectorHermite o XMVectorHermiteV
D3DXVec2CatmullRom XMVectorCatmullRom o XMVectorCatmullRomV
D3DXVec2BaryCentric XMVectorBaryCentric o XMVectorBaryCentricV
D3DXVec2Transform XMVector2Transform
D3DXVec2TransformCoord XMVector2TransformCoord
D3DXVec2TransformNormal XMVector2TransformNormal
D3DXVec2TransformArray XMVector2TransformStream
D3DXVec2TransformCoordArray XMVector2TransformCoordStream
D3DXVec2TransformNormalArray XMVector2TransformNormalStream
D3DXVec3Length XMVector3Length o XMVector3LengthEst
D3DXVec3LengthSq XMVector3LengthSq
D3DXVec3Dot XMVector3Dot
D3DXVec3Cross XMVector3Cross
D3DXVec3Agregar XMVectorAdd
D3DXVec3Subtract XMVectorSubtract
D3DXVec3Minimize XMVectorMin
D3DXVec3Maximize XMVectorMax
D3DXVec3Scale XMVectorScale
D3DXVec3Lerp XMVectorLerp o XMVectorLerpV
D3DXVec3Normalize XMVector3Normalize o XMVector3NormalizeEst
D3DXVec3Hermite XMVectorHermite o XMVectorHermiteV
D3DXVec3CatmullRom XMVectorCatmullRom o XMVectorCatmullRomV
D3DXVec3BaryCentric XMVectorBaryCentric o XMVectorBaryCentricV
D3DXVec3Transform XMVector3Transform
D3DXVec3TransformCoord XMVector3TransformCoord
D3DXVec3TransformNormal XMVector3TransformNormal
D3DXVec3TransformArray XMVector3TransformStream
D3DXVec3TransformCoordArray XMVector3TransformCoordStream
D3DXVec3TransformNormalArray XMVector3TransformNormalStream
D3DXVec3Project XMVector3Project
D3DXVec3Unproject XMVector3Unproject
D3DXVec3ProjectArray XMVector3ProjectStream
D3DXVec3UnprojectArray XMVector3UnprojectStream
D3DXVec4Length XMVector4Length o XMVector4LengthEst
D3DXVec4LengthSq XMVector4LengthSq
D3DXVec4Dot XMVector4Dot
D3DXVec4Add XMVectorAdd
D3DXVec4Subtract XMVectorSubtract
D3DXVec4Minimize XMVectorMin
D3DXVec4Maximize XMVectorMax
D3DXVec4Scale XMVectorScale
D3DXVec4Lerp XMVectorLerp o XMVectorLerpV
D3DXVec4Cross XMVector4Cross
D3DXVec4Normalize XMVector4Normalize o XMVector4NormalizeEst
D3DXVec4Hermite XMVectorHermite o XMVectorHermiteV
D3DXVec4CatmullRom XMVectorCatmullRom o XMVectorCatmullRomV
D3DXVec4BaryCentric XMVectorBaryCéntrico o XMVectorBaryCéntricoV
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 (Tenga en cuenta que el orden de los parámetros es diferente: D3DXMatrixRotationYawPitchRoll toma yaw, pitch, roll, XMMatrixRotationRollPitchYaw toma el tono, 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 (Tenga en cuenta que el orden de los parámetros es diferente: D3DXQuaternionRotationYawPitchRoll toma yaw, pitch, roll, XMQuaternionRotationRollPitchYaw toma pitch, yaw, roll)
D3DXQuaternionMultiply XMQuaternionMultiply
D3DXQuaternionNormalize XMQuaternionNormalize o XMQuaternionNormalizeEst
D3DXQuaternionInverse XMQuaternionInverse
D3DXQuaternionLn XMQuaternionLn
D3DXQuaternionExp XMQuaternionExp
D3DXQuaternionSlerp XMQuaternionSlerp o XMQuaternionSlerpV
D3DXQuaternionSquad XMQuaternionSquad o XMQuaternionSquadV
D3DXQuaternionSquadSetup XMQuaternionSquadSetup
D3DXQuaternionBaryCentric XMQuaternionBaryCentric o XMQuaternionBaryCentricV
D3DXPlaneDot XMPlaneDot
D3DXPlaneDotCoord XMPlaneDotCoord
D3DXPlaneDotNormal XMPlaneDotNormal
D3DXPlaneScale XMVectorScale
D3DXPlaneNormalize XMPlaneNormalize o XMPlaneNormalizeEst
D3DXPlaneIntersectLine XMPlaneIntersectLine
D3DXPlaneFromPointNormal XMPlaneFromPointNormal
D3DXPlaneFromPoints XMPlaneFromPoints
D3DXPlaneTransform XMPlaneTransform
D3DXPlaneTransformArray XMPlaneTransformStream
D3DXColorNegative XMColorNegative
D3DXColorAgregar XMVectorAdd
D3DXColorSubtract XMVectorSubtract
D3DXColorScale XMVectorScale
D3DXColorModulate XMColorModulate
D3DXColorLerp XMVectorLerp o XMVectorLerpV
D3DXColorAdjustSaturation XMColorAdjustSaturation
D3DXColorAdjustContrast XMColorAdjustContrast
D3DXFresnelTerm XMFresnelTerm

 

Nota:

Las funciones armónicas esféricas para DirectXMath están disponibles por separado. También hay disponible un valor de DirectXMath equivalente a ID3DXMatrixStack .

 

Guía de programación de DirectXMath