
You last visited: Today at 10:33
[Release] Finding Point "p"
08/10/2011, 20:04

#1

elite*gold: 12
Join Date: Jul 2011
Posts: 7,015
Received Thanks: 3,370

[Release] Finding Point "p"
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).
(TQ's coord axis is inverted)
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

#2

elite*gold: 0
Join Date: Jan 2011
Posts: 15
Received Thanks: 0

Ty Fang Good Work



11/04/2011, 23:23

#3

elite*gold: 0
Join Date: Nov 2009
Posts: 342
Received Thanks: 17

you are The Best



11/05/2011, 05:12

#4

elite*gold: 12
Join Date: Jul 2011
Posts: 7,015
Received Thanks: 3,370

This is VERY old now (for me)... there's a much better way of doing this.



11/10/2011, 05:24

#5

elite*gold: 0
Join Date: Apr 2008
Posts: 113
Received Thanks: 2

thanks #Fang
but how to used?



11/10/2011, 06:03

#6

elite*gold: 12
Join Date: Jul 2011
Posts: 7,015
Received Thanks: 3,370

Quote:
Originally Posted by ramy999
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

#7

elite*gold: 0
Join Date: May 2010
Posts: 58
Received Thanks: 9

And why would you thank somebody, while you don't even understand what they say



11/11/2011, 17:15

#8

elite*gold: 0
Join Date: Oct 2011
Posts: 267
Received Thanks: 58

You must be good at math.



11/12/2011, 02:57

#9

elite*gold: 0
Join Date: Jun 2010
Posts: 97
Received Thanks: 4

thanks Fang



11/13/2011, 22:00

#10

elite*gold: 12
Join Date: Jul 2011
Posts: 7,015
Received Thanks: 3,370

Quote:
Originally Posted by Sensei
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).
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

#11

elite*gold: 0
Join Date: Nov 2009
Posts: 785
Received Thanks: 405

Quote:
Originally Posted by Fаng
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).
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

#12

elite*gold: 12
Join Date: Jul 2011
Posts: 7,015
Received Thanks: 3,370

Quote:
Originally Posted by F i n c h i
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

#13

elite*gold: 0
Join Date: Nov 2009
Posts: 19
Received Thanks: 4

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
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

#14

elite*gold: 12
Join Date: Jul 2011
Posts: 7,015
Received Thanks: 3,370

Quote:
Originally Posted by dospy
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

#15

elite*gold: 0
Join Date: Nov 2009
Posts: 19
Received Thanks: 4

Quote:
Originally Posted by Fang
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



All times are GMT +2. The time now is 10:33.

