I have a simple IRenderable class that has members for position, scaling, and rotation:
XMFLOAT3 _position;
XMFLOAT3 _scaling;
XMVECTOR _rotation;
I am attempting to set them with the constructor. The first method here gives an access violation 0x00000000 trying to set _rotation (_position and _scaling are both set fine):
IRenderable() : _position(XMFLOAT3(0, 0, 0)), _scaling(XMFLOAT3(1, 1, 1)), _rotation(XMQuaternionIdentity()) { }
Making _rotation an XMVECTOR* instead and using _rotation(new XMVECTOR()) in the constructor sets it to an empty XMVECTOR, but then throws an access violation later when trying to set the identity Quaternion:
*_rotation = XMQuaternionIdentity();
Using the address of the XMQuaternionIdentity in the constructor works fine when creating the object,
IRenderable() : _position(new XMFLOAT3(0, 0, 0)), _scaling(new XMFLOAT3(1, 1, 1)), _rotation(&XMQuaternionIdentity()) { }
but then the quaternion itself contains garbage data by the time it needs to be used to render with. Both _position and _scaling are working fine in all of these situations.
What is the correct way to use XMVECTOR in this situation?