标签: xna-math-library

m = XMMatrixIdentity()后崩溃 - 类中的对齐内存?

我正在查看DirectX SDK中的教程.教程5工作正常,但在我将代码复制并分离到我自己的类后,我在启动应用程序时遇到了奇怪的错误.

这条线是:

g_World1 = XMMatrixIdentity();
Run Code Online (Sandbox Code Playgroud)

因为它,我在xnamathmatrix.int operator =中出现错误,看起来像这样:

XMFINLINE _XMMATRIX& _XMMATRIX::operator=
(
    CONST _XMMATRIX& M
)
{
    r[0] = M.r[0];
    r[1] = M.r[1];
    r[2] = M.r[2];
    r[3] = M.r[3];
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

并且错误消息是:

Access violation reading location 0xffffffff
Run Code Online (Sandbox Code Playgroud)

我在某处读过它可能是由连接到XMFLOAT4X4/XMMATRIX的东西引起的:

您是否考虑过使用XMFLOAT4X4来存储矩阵,并且只使用XMMATRIX?

但我想我已经使用过XMMATRIX了.

MyClass.h:

private:
    XMMATRIX g_World1;
Run Code Online (Sandbox Code Playgroud)

MyClass.cpp:

void init(){
   g_World1 = XMMatrixIdentity();
}
Run Code Online (Sandbox Code Playgroud)

我认为我不应该改变XMMATRIX g_World1; 到XMFLOAT4X4 g_World1,因为它会产生如下错误:

错误C2679:二进制'=':找不到哪个运算符采用'XMMATRIX'类型的右手操作数(或者没有可接受的转换)

c++ directx sse matrix xna-math-library

9
推荐指数
2
解决办法
3151
查看次数

矩阵导致崩溃

我的Direct3D11应用程序有一个奇怪的问题,我正在尝试解决几个小时.问题是该方法:

void CameraClass::Render()
{
    XMFLOAT3 sUp, sLookAt, sRotationInRadians;

    sUp.x = 0.0f;
    sUp.y = 1.0f;
    sUp.z = 0.0f;

    sLookAt.x = 0.0f;
    sLookAt.y = 0.0f;
    sLookAt.z = 1.0f;

    sRotationInRadians.x = m_Rotation.x * 0.0174532925f;
    sRotationInRadians.y = m_Rotation.y * 0.0174532925f;
    sRotationInRadians.z = m_Rotation.z * 0.0174532925f;

    XMVECTOR vecLookAt = XMVectorSet( sLookAt.x, sLookAt.y, sLookAt.z, 0.0f );
    XMVECTOR vecUp = XMVectorSet( sUp.x, sUp.y, sUp.z, 0.0f );
    XMVECTOR vecPosition = XMVectorSet( m_Position.x , m_Position.y, m_Position.z, 0.0f );

    XMMATRIX RotationMatrix( XMMatrixRotationRollPitchYaw( sRotationInRadians.x, sRotationInRadians.y, sRotationInRadians.z ));

    vecLookAt = XMVector3TransformCoord( vecLookAt, …
Run Code Online (Sandbox Code Playgroud)

c++ matrix xna-math-library direct3d11

8
推荐指数
1
解决办法
1454
查看次数

使用DirectXMath获得2点之间距离的最佳方法是什么

使用新的XMVECTOR和XMFLOAT3类,获得2点之间距离的最佳方法是什么?我找不到在XMVector*系列函数中执行此操作的函数,因此我想出了以下内容:

float distance(const XMFLOAT3& v1,const XMFLOAT3& v2)
{
    XMVECTOR vector1 = XMLoadFloat3(&v1);
    XMVECTOR vector2 = XMLoadFloat3(&v2);
    XMVECTOR vectorSub = XMVectorSubtract(vector1,vector2);
    XMVECTOR length = XMVector3Length(vectorSub);

    float distance = 0.0f;
    XMStoreFloat(&distance,length);
    return distance;
}
Run Code Online (Sandbox Code Playgroud)

这会比普通的Vector3类更快,只有3个浮点数用于x,y,z,然后使用sqrt,因为它使用内在优化?即:

float Distance(const Vector3& point1,const Vector3& point2)
{
    float distance = sqrt( (point1.x - point2.x) * (point1.x - point2.x) +
                            (point1.y - point2.y) * (point1.y - point2.y) +
                            (point1.z - point2.z) * (point1.z - point2.z) );
    return distance;
}
Run Code Online (Sandbox Code Playgroud)

c++ directx direct3d xna-math-library direct3d11

4
推荐指数
1
解决办法
1万
查看次数

如何正确使用XMVECTOR成员变量

我有一个简单的IRenderable类,它包含位置,缩放和旋转的成员:

XMFLOAT3 _position;
XMFLOAT3 _scaling;
XMVECTOR _rotation;
Run Code Online (Sandbox Code Playgroud)

我试图用构造函数设置它们.这里的第一种方法给出了一个访问冲突0x00000000尝试设置_rotation(_position和_scaling都设置正常):

IRenderable() : _position(XMFLOAT3(0, 0, 0)), _scaling(XMFLOAT3(1, 1, 1)), _rotation(XMQuaternionIdentity()) { }
Run Code Online (Sandbox Code Playgroud)

将_rotation改为XMVECTOR*并在构造函数中使用_rotation(new XMVECTOR())将其设置为空的XMVECTOR,但稍后在尝试设置身份Quaternion时抛出访问冲突:

*_rotation = XMQuaternionIdentity();
Run Code Online (Sandbox Code Playgroud)

在构造函数中使用XMQuaternionIdentity的地址在创建对象时工作正常,

IRenderable() : _position(new XMFLOAT3(0, 0, 0)), _scaling(new XMFLOAT3(1, 1, 1)), _rotation(&XMQuaternionIdentity()) { }
Run Code Online (Sandbox Code Playgroud)

但是,当它需要用于渲染时,四元数本身包含垃圾数据._position和_scaling在所有这些情况下都能正常工作.

在这种情况下使用XMVECTOR 的正确方法是什么?

c++ directx-11 xna-math-library

1
推荐指数
1
解决办法
1万
查看次数

函数后向量赋值的性能

我用这个代码:

MainLoop() {
    for (int i = 0; i < length; i++) {
        XMVector3Rotate(rays[i], orientation);
    }
}
Run Code Online (Sandbox Code Playgroud)

我有fps 1900000,但当我用这个:

MainLoop() {
    for (int i = 0; i < length; i++) {
        calculatedRays[i] = XMVector3Rotate(rays[i], orientation);
    }
}
Run Code Online (Sandbox Code Playgroud)

我有fps = 200.为什么?

c++ directx performance xna-math-library

0
推荐指数
1
解决办法
348
查看次数