Brandon
01-31-2012, 06:09 AM
K so how do I detect if my character is below a line on the minimap?
I've tried getting all the points on a line segment then checking if my character's X & Y is less than any of the corresponding values for the points.. but that takes forever!! AND it doesn't always work.. My math might have a bug :S
I'm basically trying to use the minimap as a graph/Cartesian plane to check if a player is out of bounds..
Function CrossedTheLine: Boolean;
var
LineSeg, AllPoints: TPointArray;
Slope, Len: Extended;
I, NumPoints, Dist, StepX, StepY, PX, PY: Integer;
begin
LineSeg:= [Point(54, 105), Point(49, 123)];
//Slope:= (LineSeg[1].Y - LineSeg[0].Y) div (LineSeg[1].X - LineSeg[0].X);
//B:= LineSeg[0].Y - (Slope * LineSeg[0].X);
//Y:= (Slope * X) + B;
Len:= Hypot(((LineSeg[0].X - LineSeg[1].X) * 1.0), ((LineSeg[0].Y - LineSeg[1].Y) * 1.0)); //Length Of Segment.
Dist:= Distance(LineSeg[0].X, LineSeg[0].Y, LineSeg[1].X, LineSeg[1].Y);
NumPoints:= Floor(Len div Dist);
if (NumPoints = 0) then
NumPoints:= 1; //Prevent Division By 0.
StepX:= Floor((LineSeg[1].X - LineSeg[0].X)/NumPoints);
StepY:= Floor((LineSeg[1].Y - LineSeg[0].Y)/NumPoints);
PX:= StepX + LineSeg[0].X;
PY:= StepY + LineSeg[0].Y;
For I:= 0 To NumPoints do
begin
SetLength(AllPoints, Length(AllPoints) + 1);
AllPoints[I]:= Point(PX, PY);
PX := PX + StepX;
PY := PY + StepY;
end;
writeln(AllPoints);
end;
I've tried getting all the points on a line segment then checking if my character's X & Y is less than any of the corresponding values for the points.. but that takes forever!! AND it doesn't always work.. My math might have a bug :S
I'm basically trying to use the minimap as a graph/Cartesian plane to check if a player is out of bounds..
Function CrossedTheLine: Boolean;
var
LineSeg, AllPoints: TPointArray;
Slope, Len: Extended;
I, NumPoints, Dist, StepX, StepY, PX, PY: Integer;
begin
LineSeg:= [Point(54, 105), Point(49, 123)];
//Slope:= (LineSeg[1].Y - LineSeg[0].Y) div (LineSeg[1].X - LineSeg[0].X);
//B:= LineSeg[0].Y - (Slope * LineSeg[0].X);
//Y:= (Slope * X) + B;
Len:= Hypot(((LineSeg[0].X - LineSeg[1].X) * 1.0), ((LineSeg[0].Y - LineSeg[1].Y) * 1.0)); //Length Of Segment.
Dist:= Distance(LineSeg[0].X, LineSeg[0].Y, LineSeg[1].X, LineSeg[1].Y);
NumPoints:= Floor(Len div Dist);
if (NumPoints = 0) then
NumPoints:= 1; //Prevent Division By 0.
StepX:= Floor((LineSeg[1].X - LineSeg[0].X)/NumPoints);
StepY:= Floor((LineSeg[1].Y - LineSeg[0].Y)/NumPoints);
PX:= StepX + LineSeg[0].X;
PY:= StepY + LineSeg[0].Y;
For I:= 0 To NumPoints do
begin
SetLength(AllPoints, Length(AllPoints) + 1);
AllPoints[I]:= Point(PX, PY);
PX := PX + StepX;
PY := PY + StepY;
end;
writeln(AllPoints);
end;