Sign in to follow this  
SteveDeFacto

How to use XNAMath?

Recommended Posts

I need to store a 4x4 matrix in a class but I don't even know how to do this. Here is basically the problem:


class foo
{
public:
XMMATRIX matrix;
}

void func()
{
foo* instance = new foo;
instance->matrix = XMMatrixRotationRollPitchYaw( 0, 0, 0 );
}



This does not work so I instead used XMFLOAT4X4 but I don't know how to convert the XMMATRIX to a XMFLOAT4X4

I don't understand?...

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
What do you mean by "does not work"? By the way, you can store an XMMATRIX in an XMFLOAT4x4 using XMStoreFloat4x4.


Though that is one way to do it I don't think it is the right way. Here is the error I'm getting:

Quote:

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(870): error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned

Share this post


Link to post
Share on other sites
Ah, this old problem.

The issue is that classes with XMMaths types in them need to be stored aligned, which is something std::vector can't garentee. The std::vector implementation which comes with VS2010 is setup to throw an error in cases where an aligned type is used.

You could store pointers to the class just fine in the std::vector however, just not instances.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Ah, this old problem.

The issue is that classes with XMMaths types in them need to be stored aligned, which is something std::vector can't garentee. The std::vector implementation which comes with VS2010 is setup to throw an error in cases where an aligned type is used.

You could store pointers to the class just fine in the std::vector however, just not instances.


That explains the problem though the data needs to be actually contained in the class or I will have to write a bunch of code to create new instances and then delete them which I don't believe is worth the optimization so probably using the store function is really the best option...

Share this post


Link to post
Share on other sites
phantom, unless I missed something, he never once mentioned std::vector.

He is trying to use the default new with aligned data. Use _aligned_malloc or overload new.

Share this post


Link to post
Share on other sites
Quote:
Original post by Chris_F
phantom, unless I missed something, he never once mentioned std::vector.

He is trying to use the default new with aligned data. Use _aligned_malloc or overload new.


I never mentioned it though it was one of the other problems I was having but I thought they were the same problem. Also I'm probably just going to avoid using malloc or new for this because it will create a huge mess to clear up and I don't think it's worth such a small optimization.

[Edited by - SteveDeFacto on November 13, 2010 4:36:38 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this