Xna Math Question

This topic is 2893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Reformatting a lot of things to work with XNA MATH. I also want to rework certain things to be more efficient so using XNA MATH I believe the ideal function to compute the World matrix for an object would be .

 XMMATRIX XMMatrixTransformation( XMVECTOR ScalingOrigin,XMVECTOR ScalingOrientationQuaternion,XMVECTOR Scaling,XMVECTOR RotationOrigin, XMVECTOR RotationQuaternion,XMVECTORTranslation); 

I believe ScalingOrigin should be the origin as this matrix will scale in model space.

No idea what scaling orientation quaternion should be. Maybe the IdentityQuaternion?

Scaling I believe should be a vector that has the x,y,z scaling coefficient within it.

RotationOrigin should be wherever I want to rotate the model around., normally just the Origin.

RotationQuaternion I can calculate from the XMQuaternionRotationNormal function. Where I give it the Axis Normal to Rotation and the desired Rotation Angle.

Finally Translation is simply a position vector I want to translate it too.

Can anyone Tell me if the above part is correct?

Share on other sites

Reformatting a lot of things to work with XNA MATH. I also want to rework certain things to be more efficient so using XNA MATH I believe the ideal function to compute the World matrix for an object would be .

 XMMATRIX XMMatrixTransformation( XMVECTOR ScalingOrigin,XMVECTOR ScalingOrientationQuaternion,XMVECTOR Scaling,XMVECTOR RotationOrigin, XMVECTOR RotationQuaternion,XMVECTORTranslation); 

I believe ScalingOrigin should be the origin as this matrix will scale in model space.

No idea what scaling orientation quaternion should be. Maybe the IdentityQuaternion?

Scaling I believe should be a vector that has the x,y,z scaling coefficient within it.

RotationOrigin should be wherever I want to rotate the model around., normally just the Origin.

RotationQuaternion I can calculate from the XMQuaternionRotationNormal function. Where I give it the Axis Normal to Rotation and the desired Rotation Angle.

Finally Translation is simply a position vector I want to translate it too.

Can anyone Tell me if the above part is correct?

What you're describing sounds like it will work fine. You shouldn't need any scaling rotation for most normal cases, so identity should be sufficient.

However if you just want rotation, scale, and translation than you can do it much more efficiently. First you can use XMMatrixRotationNormal to build a rotation matrix directly from your axis + angle, rather than making a quaternion first. Then to apply a scale, you can use XMVectorScale to scale the first, second, and third rows by your X, Y, and Z scale respectively. Then the translation just goes in the last row. So something like this:

 XMMATRIX MakeWorldMatrix(const XMFLOAT3& rotAxis, float rotAngle, const XMFLOAT3& scale, const XMFLOAT3& translation) { XMVECTOR axisVec = XMVector3Normalize(XMLoadFloat3(&rotAxis)); XMMATRIX world = XMMatrixRotationNormal(axisVec, rotAngle); world.r[0] = XMVectorScale(world.r[0], scale.x); world.r[1] = XMVectorScale(world.r[1], scale.y); world.r[2] = XMVectorScale(world.r[2], scale.z); world.r[3] = XMVectorSetW(XMLoadFloat3(&translation), 1.0f); return world; } 

Share on other sites
Thanks, a lot I didn't realize you could grab matrix lines as vectors. That will be useful.

When exactly are quaternions the preferred method to be used? even 1 example would be most helpful.

Share on other sites
When exactly are quaternions the preferred method to be used? even 1 example would be most helpful.[/quote]
In terms of fundamental behavior, quaternions are more or less equivalent to matrices as far as rotations are concerned. That said, quaternions do have a few advantages over matrices in some contexts, such as more efficient concatenation, interpolation, and normalization, lower storage requirements, and (arguably) greater elegance in some cases.

To provide one example of where quaternions might be useful, you might prefer quaternions over matrices for use in an animation system where a lot of data is being stored, and a lot of concatenation and interpolation is being performed on a per-frame basis.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633756
• Total Posts
3013709
×