mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-21 12:17:12 +01:00
Add methods to the Vector3 type to calculate the distance to another point.
This commit is contained in:
parent
2d726420e0
commit
18d0fedb91
@ -527,6 +527,18 @@ void Vector3::Normalize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
Vector3::Value Vector3::GetDistanceTo(const Vector3 & vec) const
|
||||||
|
{
|
||||||
|
return std::sqrt(std::pow(vec.x - x, 2) + std::pow(vec.y - y, 2) + std::pow(vec.z - z, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
Vector3::Value Vector3::GetSquaredDistanceTo(const Vector3 & vec) const
|
||||||
|
{
|
||||||
|
return (std::pow(vec.x - x, 2) + std::pow(vec.y - y, 2) + std::pow(vec.z - z, 2));
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const Vector3 & Vector3::Get(CSStr str)
|
const Vector3 & Vector3::Get(CSStr str)
|
||||||
{
|
{
|
||||||
@ -632,7 +644,6 @@ void Register_Vector3(HSQUIRRELVM vm)
|
|||||||
.Prop(_SC("Length"), &Vector3::GetLength, &Vector3::SetLength)
|
.Prop(_SC("Length"), &Vector3::GetLength, &Vector3::SetLength)
|
||||||
.Prop(_SC("LengthSq"), &Vector3::GetLengthSquared, &Vector3::SetLengthSquared)
|
.Prop(_SC("LengthSq"), &Vector3::GetLengthSquared, &Vector3::SetLengthSquared)
|
||||||
.Prop(_SC("Normalized"), &Vector3::Normalized)
|
.Prop(_SC("Normalized"), &Vector3::Normalized)
|
||||||
|
|
||||||
// Member Methods
|
// Member Methods
|
||||||
.Func(_SC("SetScalar"), &Vector3::SetScalar)
|
.Func(_SC("SetScalar"), &Vector3::SetScalar)
|
||||||
.Func(_SC("SetVector3"), &Vector3::SetVector3)
|
.Func(_SC("SetVector3"), &Vector3::SetVector3)
|
||||||
@ -644,6 +655,8 @@ void Register_Vector3(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("SetStr"), &Vector3::SetStr)
|
.Func(_SC("SetStr"), &Vector3::SetStr)
|
||||||
.Func(_SC("Clear"), &Vector3::Clear)
|
.Func(_SC("Clear"), &Vector3::Clear)
|
||||||
.Func(_SC("Normalize"), &Vector3::Normalize)
|
.Func(_SC("Normalize"), &Vector3::Normalize)
|
||||||
|
.Func(_SC("DistanceTo"), &Vector3::GetDistanceTo)
|
||||||
|
.Func(_SC("SqDistanceTo"), &Vector3::GetSquaredDistanceTo)
|
||||||
// Member Overloads
|
// Member Overloads
|
||||||
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
|
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
|
||||||
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)
|
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)
|
||||||
|
@ -374,6 +374,17 @@ struct Vector3
|
|||||||
*/
|
*/
|
||||||
void Normalize();
|
void Normalize();
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Return the distance between this vector and another vector.
|
||||||
|
*/
|
||||||
|
Value GetDistanceTo(const Vector3 & vec) const;
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Return the squared distance between this vector and another vector.
|
||||||
|
*/
|
||||||
|
Value GetSquaredDistanceTo(const Vector3 & vec) const;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Extract the values for components of the Vector3 type from a string.
|
* Extract the values for components of the Vector3 type from a string.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user