Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to add a vector projection function #166

Open
ackh opened this issue Jul 11, 2023 · 2 comments
Open

Proposal to add a vector projection function #166

ackh opened this issue Jul 11, 2023 · 2 comments
Labels
simplemath Related to SimpleMath (see DirectX Tool Kit)

Comments

@ackh
Copy link

ackh commented Jul 11, 2023

Sometimes I need to project a vector on another vector, as described here. It seems that DirectXMath does not offer a function to do this out of the box which is why I came up with the following implementation:

inline XMVECTOR ProjectVectorToVector(XMVECTOR v1, XMVECTOR v2)
{
  return XMVectorMultiply(XMVectorDivide(XMVector3Dot(v1, v2), XMVector3Dot(v2, v2)), v2);
}

Admittedly, such a function isn't hard to implement but to me, it seems like such a common geometric operation that I think it makes sense to add this to DirectXMath itself.

@walbourn
Copy link
Member

The DirectxMath library itself is focused on operations that map to functions implemented by SIMD instructions directly or are particular challenging to implement for SIMD. There's also a bit of a longer time frame before new versions of DirectXMath become widespread through Windows SDK release, etc. so I tend to be slow to add new functions to it.

That said, this kind of 'helper code' fits well into SimpleMath. so I think it would make sense to add it there like Unity3D supports in their math library.

@walbourn walbourn added the simplemath Related to SimpleMath (see DirectX Tool Kit) label Jul 11, 2023
@ackh
Copy link
Author

ackh commented Jul 12, 2023

Being conservative in what gets added to DirectXMath certainly makes sense. That being said, the background for this request is that I ported an OpenGL application that uses the GLM library to DirectX 11. GLM offers a function to project a vector on another vector which I expected to be in DirectXMath's geometric vector functions as something like XMVectorProjection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
simplemath Related to SimpleMath (see DirectX Tool Kit)
Projects
None yet
Development

No branches or pull requests

2 participants