PDA

View Full Version : [Func]TurnToMMPoint



Flight
08-02-2012, 10:25 AM
Heya. So I had to make up something like this in one of my projects I've been working on lately. Just feed the function a point on the MM and it'll turn your camera to that point as well as return the degree of the point. It works really nicely for SPS as well.


Procedure TurnToMMPoint(P: TPoint);
var
BaseRad: Extended;
FinalAn,RMod,CAng: Integer;
begin
CAng := (Round(rs_GetCompassAngleDegrees)-90);
if (CAng < 0) then
CAng := (360+CAng);

BaseRad := (ArcTan2((P.Y - MMCY),(P.X - MMCX)) + Radians(CAng));
FinalAn := Round(Degrees(fixRad(BaseRad-Pi)));
MakeCompass(FinalAn);
end;


You can see it uses similar math to SRL's 'rs_GetCompassAngleRadians'. Maybe some of you will find the use out of this for things like rotating to the nearest NPC/Object on the MM to get a better camera view for a higher chance of finding the MS object, ect...

For use with SPS just do something like this:

TurnToMMPoint(SPS_PosToMM(Point(X, Y)));


Edit:
I'd also like to bring up to an SRL dev a updated 'rs_GetCompassAngleRadians'. This modified version is mathematically correct therefore more accurate: Already added to the include.

Function rs_GetCompassAngleRadians: Extended;
var
TPA: TPointArray;
T: TPoint;
B: TBox;
begin
B := IntToBox(524, 5, 562, 43);
with B do
FindColorsSpiralTolerance(T.x, T.y, TPA, 65536, x1, y1, x2, y2, 0);
if Length(TPA) < 1 then
Exit;
T := MiddleTPA(TPA);
Result := ArcTan2(-(T.Y - 24), T.X - 543) + Radians(90);
Result := fixRad(Result - Pi);
end;

Footy
08-02-2012, 12:17 PM
This looks incredibly useful. Nice work flight!

Flight
08-02-2012, 12:23 PM
Ops. Apparently I didn't need to define the MMCX/Y as a point. Changed it. :p

Mark
08-02-2012, 12:26 PM
Great work flight will most certainly improve quallity of many users functions

Nebula
08-02-2012, 06:11 PM
Ooh this looks like it would have great human-like use in a fighter script. Have the camera angle down a bit and rotate the compass toward the closest yellow dot. Then obviously click the monster. Good work Flight :3

NCDS
08-03-2012, 01:23 AM
Love it Flight, will definitely be used in MSI once I get back to it. I needed something to do just this, just never got a chance to put it together. :)

Jakkle
08-05-2012, 11:52 AM
Very nice Flight, a much needed addition. Thanks.

Flight
08-13-2012, 10:01 AM
Updated the OP to include a more accurate 'rs_GetCompassAngleRadians'. I hope a Dev reads this and makes the change.

Flight
09-04-2012, 03:55 AM
Um, apologies for the double post but I thought I should bring up that the previous procedure didn't function correctly when the camera angle was between North and West.

I fixed this by also incorporating the MM compass angle in with the math formula to get a precise angle to for us to turn to. I tested this at N,NE,E,SE,S,SW,W,NW angles, all work perfectly.

So enjoy. Probably today I'll be playing around with this to see if I can correctly walk via SPS at any camera angle.