# A ray with an ending position?

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

## Recommended Posts

This snippet is written for an adapter of Irrlicht to argortha
Now, I want to write another adapter for DirectX
Just wondering the code underneath which specifies a lineCollision, it is to me a
line, but when passing to getCollisionPoint, it is a ray.
Can I treat them both the same?
I would use the
D3DXboxBoundProbe function

Rather be

https://msdn.microsoft.com/en-us/library/windows/desktop/bb172713%28v=vs.85%29.aspx

irr::core::line3df lineCollision(actorPos, IrrVector3Adapter(io_actor->getPosition() + in_displacement));

irr::core::vector3df outColl;
irr::core::triangle3df outTri;

if (mScmgr->getSceneCollisionManager()->getCollisionPoint(lineCollision, mSelector, outColl, outTri))
Edited by lucky6969b

##### Share on other sites
Technically it is more or less the same, two vectors.

Semantically a line is has a start and end which can be represented as (position, position+direction) or (start_position,end_position). Well, a ray is typically a start point with a direction vector, so (position, direction), where direction is typically normalized.

Therefor it is easy to get a ray from a line by just normalizing the direction, either (position,normalize(direction)) or if you have a start-,endpoint you get (start_point, normalize(end_point-start_point)).

But, once you have a ray with an normalized direction, you can't extract the original line back.

##### Share on other sites

A ray with an ending position is called a segment.

or a displacement vector, but then the origin is unspecified, IE its just a direction and distance.

but technically speaking, yes - a line is of infinite length, and a line segment has endpoints.

##### Share on other sites

Sorry, back in here again.
I find that D3DXIntersect doesn't suit my needs.
That requires a ID3DXMesh and a Line Segment intersection test.
Just wondering what can replace the D3DXIntersect function to
test between ID3DXMesh and a Line Segment (a line that *does* have
an endpoint)
Thanks
Jack

##### Share on other sites

Hi there. You may be able to use D3DXIntersect by converting the line segment to a ray and then checking the pDist returned from the D3DXIntersect. If PDist is greater then the Lines length not a collision.

##### Share on other sites

I came up with this solution too, but just unsure if it works or not,

thanks for confirmation.

Jack

##### Share on other sites

I came up with this solution too, but just unsure if it works or not,

yes, ankhd is right, just use ray-mesh and bail if range is too long.

##### Share on other sites

If this is performance critical it would be faster to compare the squared distances to avoid calculating square roots.

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013554
×