2

Im doing some work using ray-picking in a DirectX project and I just wondered whether there was an actual 'ray' object type? (rather than just storing direction/origin variables)

I know I could create something like

struct ray
{
    D3DXVECTOR3 direction
    D3DXVECTOR3 origin
};

but does anything already exist? Im currently working in DX9 but I am open to answers in newer versions of DirectX.

aioobe
  • 413,195
  • 112
  • 811
  • 826
unknownSPY
  • 706
  • 4
  • 15
  • 27

1 Answers1

1

Rather than use legacy D3DXmath, you should consider DirectXMath, although that library also just takes an origin position and a direction vector to represent a ray for the BoundingSphere, BoundingBox, BoundingOrientedBox, and BoundingFrustum classes and the TriangleTests namespace

bool Intersects( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist ) const;

See the DirectXMath Programming Guide on MSDN, particularly Working with D3DXMath

You can also use the SimpleMath wrapper in DirectX Tool Kit, which has a Ray class defined.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81