【问题标题】:XMVECTOR weird valuesXMVECTOR 奇怪的值
【发布时间】:2019-03-06 18:01:23
【问题描述】:

从 DirectX 开始,然后在 XMVECTORs 上玩转

(我知道我不会在上下文中使用它们,我只是好奇)

// Vectors.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

#include <DirectXMath.h>
#include <DirectXPackedVector.h>


int main()
{
    using namespace DirectX;

    XMVECTOR vector = XMVectorSet(1, 2, 3, 1);

    int x = XMVectorGetIntX(vector);

    std::cout << "vector.x: " << x << std::endl;

    system("pause");

    return 0;
}

这会打印出 1065353216

的值

虽然很有趣,但我想知道我做错了什么,或者这是否确实是预期的功能。

【问题讨论】:

  • 如果你想存储整数数据,你应该使用XMVectorSetInt
  • 1065353216 是十六进制的0x3F800000,1.0f 的 IEEE754 表示形式是什么。
  • 啊,我明白了!那么 XMVectorSet 的用途是什么?
  • 不带 *Int 后缀的都是浮点数据。

标签: c++ vector graphics directx directx-12


【解决方案1】:

底层 SIMD 指令是无类型的。您可以将相同的数据视为 4 个浮点数或 4 个整数(或 8 个短字节或 16 个字节)。 DirectXMath 通常使用 4 个浮点数,这是您的 XMVECTORXMVectorSet 得到的。

如果你使用float x = XMVectorGetX(vector);,你会得到“1.0”。

或者,您也可以使用XMVECTOR vector = XMVectorSetInt(1, 2, 3, 1);

参见DirectXMath Programmer's GuideGitHub project

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 2016-06-02
    相关资源
    最近更新 更多