[Release] Finding Point "p"

08/10/2011 20:04 Spirited#1
This formula can be improved.
It is used in jumping to find point "p" on the screen's border (so when people jump in, they don't just appear, they look like they jump in).

[Only registered and activated users can see links. Click Here To Register...]
(TQ's coord axis is inverted)

[Only registered and activated users can see links. Click Here To Register...]

Code:
public static double GetAngle(ushort x, ushort y, ushort x2, ushort y2)
        {
            double xf1 = x, xf2 = x2, yf1 = y, yf2 = y2;
            double result = 90 - Math.Atan((xf1 - xf2) / (yf1 - yf2)) * 180 / Math.PI;
            if (xf1 - xf2 < 0 && yf1 - yf2 < 0)
                result += 180;
            else if (xf1 - xf2 == 0 && yf1 - yf2 < 0)
                result += 180;
            else if (yf1 - yf2 < 0 && xf1 - xf2 > 0)
                result -= 180;
            return result;
        }
        public class Vector { public ushort X, Y; }
        public static Vector GetBorderCoords(ushort old_x, ushort old_y, ushort Target_x, ushort Target_y)
        {
            double Θ = GetAngle(old_x, old_y, Target_x, Target_y);
            double w, h;
            Vector v = new Vector();
            byte quadrant = 1;
            if (Θ < 0)
                Θ += 360;
            else if (Θ == 360)
                Θ = 0;
            while (Θ >= 90)
            {
                Θ -= 90;
                quadrant++;
            }
            double screendistance = ScreenDistance;
            if (quadrant == 1)
            {
                screendistance = ScreenDistance / (Math.Cos(Θ * Math.PI / 180));
                if (screendistance > 25)
                    screendistance = ScreenDistance / (Math.Sin(Θ * Math.PI / 180));
                else if (Θ != 0)
                    v.Y++;
                h = screendistance * (Math.Sin(Θ * Math.PI / 180));
                w = screendistance * (Math.Cos(Θ * Math.PI / 180));
                v.X += (ushort)(Target_x + Math.Round(w));
                if (Θ == 90)
                    v.Y += (ushort)(Target_y - Math.Round(h));
                else
                v.Y += (ushort)(Target_y + Math.Round(h));
            }
            else if (quadrant == 2)
            {
                screendistance = ScreenDistance / (Math.Cos(Θ * Math.PI / 180));
                if (screendistance > 25)
                {
                    screendistance = ScreenDistance / (Math.Sin(Θ * Math.PI / 180));
                    v.Y++;
                }
                w = screendistance * (Math.Sin(Θ * Math.PI / 180));
                h = screendistance * (Math.Cos(Θ * Math.PI / 180));
                v.X += (ushort)(Target_x - w);
                v.Y += (ushort)(Target_y + h);
            }
            else if (quadrant == 3)
            {
                screendistance = ScreenDistance / (Math.Cos(Θ * Math.PI / 180));
                if (screendistance > 25)
                    screendistance = ScreenDistance / (Math.Sin(Θ * Math.PI / 180));
                h = screendistance * (Math.Sin(Θ * Math.PI / 180));
                w = screendistance * (Math.Cos(Θ * Math.PI / 180));
                v.X += (ushort)(Target_x - w);
                v.Y += (ushort)(Target_y - h);
            }
            else if (quadrant == 4)
            {
                screendistance = ScreenDistance / (Math.Cos(Θ * Math.PI / 180));
                if (screendistance > 25)
                    screendistance = ScreenDistance / (Math.Sin(Θ * Math.PI / 180));
                else if (Θ > 0)
                    v.X++;
                w = screendistance * (Math.Sin(Θ * Math.PI / 180));
                h = screendistance * (Math.Cos(Θ * Math.PI / 180));
                v.X += (ushort)(Target_x + w);
                v.Y += (ushort)(Target_y - h);
            }
            return v;
        }
11/04/2011 21:47 The~Lord!#2
Ty Fang Good Work
11/04/2011 23:23 |xabi|#3
you are The Best
11/05/2011 05:12 Spirited#4
This is VERY old now (for me)... there's a much better way of doing this.
11/10/2011 05:24 ramy999#5
thanks #Fang
but how to used?
11/10/2011 06:03 Spirited#6
Quote:
Originally Posted by ramy999 View Post
thanks #Fang
but how to used?
I'm pretty sure I've said this before... why on earth would u use something that you don't understand?
11/10/2011 17:18 steffiet#7
And why would you thank somebody, while you don't even understand what they say:o
11/11/2011 17:15 -Sensei-#8
You must be good at math.
11/12/2011 02:57 Crazy_XX#9
thanks Fang
11/13/2011 22:00 Spirited#10
Quote:
Originally Posted by -Sensei- View Post
You must be good at math.
I think the code makes it look much more complicated than it actually is. It's really simple once you see it on paper. Here's what it looks like. (Don't mind the coffee stain... I did it at Starbucks).

[Only registered and activated users can see links. Click Here To Register...]

The only thing that picture is missing is the square... because the screen distance doesn't work on a radius of 18, it works based on a tangent of 18.
11/13/2011 22:59 F i n c h i#11
Quote:
Originally Posted by Fаng View Post
I think the code makes it look much more complicated than it actually is. It's really simple once you see it on paper. Here's what it looks like. (Don't mind the coffee stain... I did it at Starbucks).

[Only registered and activated users can see links. Click Here To Register...]

The only thing that picture is missing is the square... because the screen distance doesn't work on a radius of 18, it works based on a tangent of 18.
Well explained.
11/13/2011 23:34 Spirited#12
Quote:
Originally Posted by F i n c h i View Post
Well explained.
I didn't draw the picture to explain it. That was my first drawing for the equation when I was developing it. I just wanted to show u all that it's not challenging math.
09/04/2013 00:44 dospy#13
i know that this is ancient old and sorry for bumping the thread but i really see no point in creating another one. I am interested as in how can i use this
Quote:
Originally Posted by Fang View Post
so when people jump in, they don't just appear, they look like they jump in
.
Let's say char A request a jump from outside of view range of B inside the view range of B. to make as if A was jumping rather than just appear in B's screen you simply find the P point(as you call it), spawn A(spawn visible to B ofc) on that point and then send the jump packet?
thx in advance
09/04/2013 02:02 Spirited#14
Quote:
Originally Posted by dospy View Post
i know that this is ancient old and sorry for bumping the thread but i really see no point in creating another one. I am interested as in how can i use this .
Let's say char A request a jump from outside of view range of B inside the view range of B. to make as if A was jumping rather than just appear in B's screen you simply find the P point(as you call it), spawn A(spawn visible to B ofc) on that point and then send the jump packet?
thx in advance
I only released the formulas (which aren't perfect - this thread is very old and I've refined this a long time ago). It's up to you to implement it because it can be implemented in a lot of ways. The idea is to spawn the character on an edge and then send a modified jump. That's all. If you want to implement that, I suggest making your own formula though (because as I said, this is old and not perfect). If you do use it, expect a few bugs. Cheers.
09/04/2013 10:04 dospy#15
Quote:
Originally Posted by Fang View Post
I only released the formulas (which aren't perfect - this thread is very old and I've refined this a long time ago). It's up to you to implement it because it can be implemented in a lot of ways. The idea is to spawn the character on an edge and then send a modified jump. That's all. If you want to implement that, I suggest making your own formula though (because as I said, this is old and not perfect). If you do use it, expect a few bugs. Cheers.
thanks, i am going to try and make my own the formula for the case; as indeed i was interested in the method of using it although it sound pretty logical but i wanted to be sure that this is the best attempt to it and my work won't go in vein