Is there a specified Ray object in DirectX

311 Views Asked by At

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.

1

There are 1 best solutions below

0
Chuck Walbourn On

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.