Jump to content
crossEy3

Is it possible to calculate an angle and....

Recommended Posts

Hi there,

I'm hoping you wouldn't mind helping me with something...

 

Is there a way to calculate the angle between two points then make the mouse move on this angle but a greater distance? The mini map is scaled down with ratio between the main screen and map is 8:1. The first point i guess the origin is known and fixed (center of mini map), but the FindColor function would find the second point and from these find the angle if that is possible. Apologies for the rambling too. I hope I explained myself well enough.

Link to comment
Share on other sites

The minimap does not have the same perspective as the mainscreen, so something like that without some complex 3D-perspective projection will be quite a bit off, I am afraid.

 

But if you still want to try it there are several ways to do it for just simple scaling:

 

1. Use OSI, as it has MMToMS (MinimapToMainScreen)-function.

 

2. Simple maths Find the points on the minimap that you are interested substract the center of the minimap from those points, and do some simple multiplication: If the scale is 8:1 then you simple multiplay each point by eight, and move am to the center of the mainscreen.

 

Pseudocode:

const
 MMCenterX = 650; //Not exactly the center.. but using it for the sake of example
 MMCenterY = 650;
 MSCenterX = 350; //Not exactly the center.. but using it for the sake of example
 MSCenterY = 350;
 MMSCALE = 8;

function MMToMS(PointOnMM:TPoint): TPoint; //Not 100% sure this will work, you will just have to test..
var pt:TPoint;
begin
 pt.x := (PointOnMM.x - MMCenterX);
 pt.y := (PointOnMM.y - MMCenterY);
 pt.x := (pt.x * MMSCALE) + MSCenterX; 
 pt.y := (pt.y * MMSCALE) + MSCenterY;
 Result := pt;
end;

 

3. The harder way to do it... It is much more complicated..

 

const
 MMCenterX = 650; //Not exactly the center.. but using it for the sake of example
 MMCenterY = 650;
 MSCenterX = 350; //Not exactly the center.. but using it for the sake of example
 MSCenterY = 350;
 RadiusOfMM = 75; //Around 75px i am guessing...
 MMSCALE = 8;


function ScalePoint(const Center, Pt:TPoint; Radius:Integer): TPoint;
var
 dx,dy: Integer;
 Angle: Single;
begin
 dx := (Center.X - Pt.X);
 dy := (Center.Y - Pt.Y);
 Angle := ArcTan2(dy, dx) + PI;
 Result.x := Round(Radius * Cos(Angle)) + Center.X;
 Result.y := Round(Radius * Sin(Angle)) + Center.Y;
end;

function MMToMS(PointOnMM:TPoint): TPoint;
var
 pt:TPoint;
begin
 //.. this is pretty uncomplete (will not work witout putting some more tought in to it)..
 pt := ScalePoint(Point(MMCenterX,MMCenterY), PointOnMM, RadiusOfMM*MMSCALE); //You might have to do some changes.. 
 pt.x := (pt.x - MMCenterX) + MSCenterX;
 pt.y := (pt.y - MMCenterX) + MSCenterY;
end;

 

Note: This is still just untested pascal-like pseudo-code ("fake" code)... You will have to do the rest your self.

Edited by slacky
Link to comment
Share on other sites

This may seem like a delineation from the original topic but it is related. Do Tpoints have to be integers or can you make them extended with decimal numbers being stored? For instance if the scale were 8.3 could this be carried through without rounding the Tpoints? I am new to using scar so I am probably saying stuff all wrong.

 

The mmtoms thing works very well and its extremely close to hitting the nail on the head. :D

Edited by crossEy3
typo
Link to comment
Share on other sites

SCAR 4.0 has TPointF, which supports parameters (coordinates) as extended's, but it is not available in SCAR 3.X series.

You can always recreate it yourself to 3.X, of course.. Easy task. :)

However, none of the built-in functions support TPointF, so... You would have to write your own functions too.

Link to comment
Share on other sites

TPoint is just a record type. You can easily define your own record to hold floating point values:

 

type 
 TPointF = record
   x,y:Extended;
 end;

var
 pt: TPointF;
begin
 pt.x := 123.456;
 pt.y := 789.012;
 WriteLn(TEAToStr([pt.x, pt.y]));
end. 

I don't see much use for such a record, except in more advanced math.

Link to comment
Share on other sites

Thanks alot for the info guys. The reason i askd was after finding out about mmtoms i did some experimenting and such and was reading other stuff about it. I came across a post in another forums saying how if the tpoints were stored as [ext,ext] rather than integers it would be much more accurate. I might ave misunderstood him though which is quite likely.

 

Thanks again for the help and feel free to close the thread. I keep tweaking stuff and it gets closer and closer to being spot on.

 

Also... this is my first time learning any form of program language and you guys have made it pure easy to understand with all the tutorials and stuff. Nice one, glad I stumbled upon this. :)

Edited by crossEy3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...