Reputation: 11
I am using the GLScene RayCastIntersect function with Delphi (XE2) to determine the intersect point between a segment of a ballistic trajectory and a FreeForm mesh. If I import the mesh and use the RayCastIntersect function then the intersection point is reported correctly. However, if I translate the FreeForm object to a positive x coordinate then the function ceases to return the correct intersection point. The returned intersection point is always in front on the target (i.e. before the correct point of impact, around x = 0). Providing that the FreeForm is at x <= 0 then all other transformations and rotations appear to be handled correctly by the RayCastIntersect function.
I have noticed that if I perform the x transformation on individual MeshObjects of the FreeForm then the RayCastIntersection function returns the correct intersection point even for positive x translations. Unfortunately I am unable to use this as a workaround since there is not a method to rotate individual mesh objects.
Has anyone else come across this issue? Is it a known bug (although I have found nothing online about it)? Or am I doing something wrong? Any suggestions would be gratefully appreciated. See below for my Check Impact code.
function ChkImpact(Mesh: TGLFreeForm; x1, x2, y1, y2, z1, z2: Double): Boolean;
var
rStrt, rVect, rEnd: TVector;
dx, dy, dz: Double;
iPoint, iNorm: TVector;
begin
//***Check trajectory secgment intersection with target mesh***//
rStrt := VectorMake(x1,y1,z1,0);
rEnd := VectorMake(x2,y2,z2,0);
dx := x2-x1;
dy := y2-y1;
dz := z2-z1;
rVect := VectorMake(dx,dy,dz,1);
if Mesh.{Octree}RayCastIntersect(rStrt, rVect, @iPoint, @iNorm) then
begin
iPtX := iPoint.X;
iPtY := iPoint.Y;
iPtZ := iPoint.Z;
Result := PointOnSegment(iPoint, rStrt, rEnd);
end
else Result := False;
end;
function PointOnSegment(P, P1, P2: TVector): Boolean;
begin
//***Check whether impact point is on the trajectory segment***//
if ((P.X >= P1.X) and (P.X <= P2.X)) then Result := True else Result := False;
end;
Upvotes: 1
Views: 748
Reputation: 750
Make sure that the Z-scale of the object that you want to do "RayCastIntersect" is not the value of 0 (zero).
This cause be a lot of trouble as well.
I used "RayCastIntersect" on a plane and the plane had the scale.z set to 0 which cause "RayCastIntersect" to return incorrect values.
I don't know why this is happening.
Upvotes: 0