Find a radius in your coordinates?
I have my x y and z coordinates.
Once again, this is not my game.. this is for GTAVC.
I need to find out if a set of XYZ coordinates is within my radius of like 20 feet. I have my xyz coordinates.
Before you answer, you should know GTA's wacky coordinate system.
X = North/South
Y = East/West
Z = Up/Down (jumping increases your z coords..)
So is there some kind of formula that I can use PI and makybe cosine/sine to determine this? thanks
Re: Find a radius in your coordinates?
Hey I helped some guy not too long ago on this, only it was 2D.
http://www.vbforums.com/showthread.php?t=335684
Re: Find a radius in your coordinates?
Quote:
Originally Posted by Jacob Roman
Endpoint? Hmmm.. i dont want to find the endpoint, I just want to find out if another player is in my radius. I have my coordinates and I have his. I basically need to create a "circle" around me and check if that player is in it..
Re: Find a radius in your coordinates?
No, you use that as a basis. To obtain the radius, you subtact the endpoint by the starting point, and check to see if the player is within the radius. Getting it now?
Re: Find a radius in your coordinates?
X*X+Y*Y+Z*Z < R*R
where R is radius, X, Y and Z are distances to you in respective axis.
If you don't know the relative coordinates, then subtract your coordinate from the absolute coordinate.
Re: Find a radius in your coordinates?
Im sorry guys but im a complete retard when it comes to math.
Is there a boolean function someone can write, with parameters similiar to this? :
YourX, YourY, HisX, HisY
and it returns TRUE if HisX and HisY is within YourX and YourY's radius?
Re: Find a radius in your coordinates?
Just do SphereToSphere Collision
Use each persons x,y,z as the center and make up your own radius.
Here is a simple C++ Sphere class which should help you if you can convert it to VB.
I must mention this is a not a SWEEP test, so if they move very fast between 2 frames they could infact intersect but this function may miss it. For example, if player one is within 21ft in one frame but them moves right through the player and ends up 21ft away next frame on the other side, in real life there would have been a collision but since the sphere's didn't sweep, the collision will be missed.
Also, why on earth would GTA mess around with their coordinate system.
I do not believe you, I believe the way you have created your program probably gives the assumption that the coordinates are screwed.
PHP Code:
class Sphere
{
public:
//----------------------
//Constructors
Sphere();
~Sphere();
//----------------------
//----------------------
//Members variables
Vector m_vCenter;
float m_fRadius;
//----------------------
//---------------------
//Sphere to Sphere Collision -- Checkes to see if *this is colliding with s
//---------------------
inline bool Sphere::SphereToSphere(const Sphere &s) const
{
Vector vSepAxis = m_vCenter - s.m_vCenter;
float fRadiiSum = m_fRadius + s.m_fRadius;
// if the distance between the centers is less than the sum
// of the radii, then we have an intersection
if(vSepAxis.SquaredMagnitude() < (fRadiiSum * fRadiiSum))
return true;
// otherwise they are separated
return false;
}
};
Re: Find a radius in your coordinates?
Added some flexibility:
VB Code:
Function InSphere (HisX As Long, HisY As Long, HisZ As Long, _
MyX As Long, MyY As Long, MyZ As Long, _
Rad As Long, Mode As Long) _
As Long
'Mode indicates if being exactly ON the sphere counts as IN or as OUT
'Mode 0 : ON = IN Mode 1 : ON = OUT
If Mode < 0 Then Mode = 0
If Mode > 1 Then Mode = 1
'return values mode : 0 1
' he is OUT sphere : 0 -1
' he is ON sphere : 1 0
' he is IN sphere : 2 1
InSphere = 0 - Mode
If (HisX - MyX)^2 + (HisY - MyY)^2 + (HisZ - MyZ)^2 = (Rad)^2 Then _
InSphere = 1 - Mode
If (HisX - MyX)^2 + (HisY - MyY)^2 + (HisZ - MyZ)^2 < (Rad)^2 Then _
InSphere = 2 - Mode
End Function
If you put the result in a Boolean it will be IN or OUT (True or False), if you put the result in an integer you can see if it is IN, OUT or ON.
If you have the relative coordianets then leave one set 0 and fill the relative coordinates in the other set.
If you want to do this for a circle leave the Z elements 0.
Re: Find a radius in your coordinates?
It is very unlikely to use that terminology.
It should be IN, OUT, INTERSECT
INTERSECT being the most common since 2 spheres to be IN need to be 100% overlapped.
OUT is obvious.
Re: Find a radius in your coordinates?
the case is point in sphere detection
The sphere equation is
(x-x0)^2 + (z-z0)^2 + (z-z0)^2 = r^2
the sphere interior is
(x-x0)^2 + (z-z0)^2 + (z-z0)^2 < r^2
and rather than typing a^2 type a*a because its faster.
Re: Find a radius in your coordinates?
Quote:
Also, why on earth would GTA mess around with their coordinate system.
I do not believe you, I believe the way you have created your program probably gives the assumption that the coordinates are screwed.
Suit yourself, but I'm 100% certain of their coordinate system. I've been playing this game for a little over a year now and anyone who has used GTA's Mapping Tool, MooMapper, would know how it works. This program allows you to visually move around the objects in the game to your liking. Its not just my program - its that and every other one. Teleporters, all of it. Thats how the system works. Not to mention the Mission Script files (main.scm) also work this way.
Anyhow, jeroen79's function worked fine. Thanks guys :)
Re: Find a radius in your coordinates?
I'm thinking the coordinate system is based on top view since GTA 1 and 2 was 2D. Think about it:
Code:
Top View
Y+
|
|
|
|
|
----------- X+
/
/
/
Z+
Re: Find a radius in your coordinates?
VB Code:
Function CheckRadius(X1 As Single, Y1 As Single, Z1 As Single, X2 As Single, Y2 As Single, Z2 As Single) As Boolean
If Sqr((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2 + (Z2 - Z1) ^ 2) <= 20 Then CheckRadius = True 'change the number 20 to whatever distance you want to be max
End Function
Re: Find a radius in your coordinates?
Cyborg has a nice one for you there.
Jacob, I admit you are right! Amazing, I do not admit I'm wrong often.
The reason may very well be what was stated above, since GTA1/2 where 2D topview games resembling 3D world, I can understand how the translation would take effect.
RockStar games have been around since the Commodore 64, I infact played Grand Theft Auto on the Commodore 64 15 years ago :)
You know the loading screen in the Ps2 version of VICE CITY, the very first screen, its all blue, they type "Load "Vice City""..thats Commodore 64 :)
I've been playing these games since number 1, I know GTA3 very well, VICE CITY I can probably draw you the map, I know that game like my hands.
San Adreas is to big to memorize, plus it had that handy map pointer so you never really had to find anything yourself.
My brother, not me I don't have the time, he has achieved 100% in both GTA3 and VC, in VC all he got was a shirt saying "I got 100% in Vice City and all I got was this stupid shirt" and he got 200% health and body armor.
But when it comes to GTA I look at those games as a marvel, they are ultimate and are perfect the way they come. To me they are a goal to achieve, a premise at which I base my programming, to achieve GTA maybe in a Virtual World in the near future for example. As it comes to hacking the game, well I'd rather make the game and let you hack it.