mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-22 12:47:13 +01:00
Add methods to the Vector3 type to calculate the angle and check if between two points.
This commit is contained in:
parent
cb819d417b
commit
26c0bc4872
@ -545,6 +545,12 @@ Vector3 Vector3::CrossProduct(const Vector3 & vec) const
|
|||||||
return Vector3((y * vec.z) - (z * vec.y), (z * vec.x) - (x * vec.z), (x * vec.y) - (y * vec.x));
|
return Vector3((y * vec.z) - (z * vec.y), (z * vec.x) - (x * vec.z), (x * vec.y) - (y * vec.x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
Vector3::Value Vector3::Angle(const Vector3 & vec) const
|
||||||
|
{
|
||||||
|
return std::acos(DotProduct(vec) / (GetLength() * vec.GetLength()));
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Vector3::Value Vector3::GetDistanceTo(const Vector3 & vec) const
|
Vector3::Value Vector3::GetDistanceTo(const Vector3 & vec) const
|
||||||
{
|
{
|
||||||
@ -557,6 +563,13 @@ 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));
|
return (std::pow(vec.x - x, 2) + std::pow(vec.y - y, 2) + std::pow(vec.z - z, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
bool Vector3::IsBetweenPoints(const Vector3 & begin, const Vector3 & end) const
|
||||||
|
{
|
||||||
|
const Value length = (end - begin).GetLengthSquared();
|
||||||
|
return EpsLtEq(GetSquaredDistanceTo(begin), length) && EpsLtEq(GetSquaredDistanceTo(end), length);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const Vector3 & Vector3::Get(CSStr str)
|
const Vector3 & Vector3::Get(CSStr str)
|
||||||
{
|
{
|
||||||
@ -676,8 +689,10 @@ void Register_Vector3(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("Dot"), &Vector3::DotProduct)
|
.Func(_SC("Dot"), &Vector3::DotProduct)
|
||||||
.Func(_SC("AbsDot"), &Vector3::AbsDotProduct)
|
.Func(_SC("AbsDot"), &Vector3::AbsDotProduct)
|
||||||
.Func(_SC("Cross"), &Vector3::CrossProduct)
|
.Func(_SC("Cross"), &Vector3::CrossProduct)
|
||||||
|
.Func(_SC("Angle"), &Vector3::Angle)
|
||||||
.Func(_SC("DistanceTo"), &Vector3::GetDistanceTo)
|
.Func(_SC("DistanceTo"), &Vector3::GetDistanceTo)
|
||||||
.Func(_SC("SqDistanceTo"), &Vector3::GetSquaredDistanceTo)
|
.Func(_SC("SqDistanceTo"), &Vector3::GetSquaredDistanceTo)
|
||||||
|
.Func(_SC("IsBetweenPoints"), &Vector3::IsBetweenPoints)
|
||||||
// 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)
|
||||||
|
@ -389,17 +389,26 @@ struct Vector3
|
|||||||
*/
|
*/
|
||||||
Vector3 CrossProduct(const Vector3 & vec) const;
|
Vector3 CrossProduct(const Vector3 & vec) const;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Returns the angle between this vector and another vector in degrees.
|
||||||
|
*/
|
||||||
|
Value Angle(const Vector3 & vec) const;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Return the distance between this vector and another vector.
|
* Return the distance between this vector and another vector.
|
||||||
*/
|
*/
|
||||||
Value GetDistanceTo(const Vector3 & vec) const;
|
Value GetDistanceTo(const Vector3 & vec) const;
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Return the squared distance between this vector and another vector.
|
* Return the squared distance between this vector and another vector.
|
||||||
*/
|
*/
|
||||||
Value GetSquaredDistanceTo(const Vector3 & vec) const;
|
Value GetSquaredDistanceTo(const Vector3 & vec) const;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Linear interpolation with another vector.
|
||||||
|
*/
|
||||||
|
bool IsBetweenPoints(const Vector3 & begin, const Vector3 & end) 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