【问题标题】:How is it possible to get the float value from XMVECTOR? (DirectXMath)如何从 XMVECTOR 获取浮点值? (DirectXMath)
【发布时间】:2017-10-21 12:42:15
【问题描述】:

我想在浮点数中获得两个 3D 向量的点积。但不幸的是,结果是一个向量,而不是一个浮点数。我确实可以使用vector4_f32 访问它的元素,但我得到一个错误,它不是__m128 的成员

float res = XMVector3Dot(a, b).vector4_f32[0];

[] 运算符未在 XMVECTOR 上定义

【问题讨论】:

    标签: c++ directx directxmath


    【解决方案1】:

    您可以使用XMVectorGetXXMVectorGetYXMVectorGetZXMVectorGetW 访问XMVECTOR 的各个元素。但请记住,由于 DirectXMath 使用 SIMD 指令集,这些操作更可能是昂贵的操作。欲了解更多信息:

    1:XMVector3Dot performance

    2:Expensive than expected

    【讨论】:

    • 您可能还想看看 DirectXMath 的 SimpleMath 包装器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多