Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » distance between two objects c++
Re: distance between two objects c++ [message #432329 is a reply to message #432316] Thu, 08 July 2010 07:41 Go to previous messageGo to previous message
Ephphatha is currently offline  Ephphatha
Messages: 1
Registered: June 2010
Karma:
Recruit
For those interested in the math, the distance between two points is the magnitude of the vector from point A to point B.

Taking the first example, the distance between obj1 and obj2 would be calculated:
Vector3 pos1, pos2;
pos1 = Commands->Get_Position(obj1);
pos2 = Commands->Get_Position(obj2);

Vector3 gap = pos1 - pos2; //Doesn't matter which order the subtraction is in.
float dist = gap.length(); //Where length() returns the magnitude of the vector (is this in the sdk?)


And the magnitude is calculated by taking the square root of the sum of the square of each element.

class Vector3
{
public:
    float x, y, z;

    float length()
    {
        return sqrt(x*x + y*y + z*z);
    }
}


So if there is no length() or equivalent function, you can still get the distance if you have access to each element of the vector.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: C++ void On_Player_Death???
Next Topic: proximity speech
Goto Forum:
  


Current Time: Fri Dec 13 21:04:21 MST 2024

Total time taken to generate the page: 0.01300 seconds