A ray with an ending position?

Started by
7 comments, last by Polydone 8 years, 1 month ago

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

D3DXIntersect instead, sorry

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))
Advertisement
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.

A ray with an ending position is called a segment.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

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

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.

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

thanks for confirmation.

Jack


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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

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

Developer journal: Multiplayer RPG dev diary

This topic is closed to new replies.

Advertisement