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 dot and cross product.
This commit is contained in:
parent
18d0fedb91
commit
cb819d417b
@ -527,6 +527,24 @@ void Vector3::Normalize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
Vector3::Value Vector3::DotProduct(const Vector3 & vec) const
|
||||||
|
{
|
||||||
|
return ((x * vec.x) + (y * vec.y) + (z * vec.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
Vector3::Value Vector3::AbsDotProduct(const Vector3 & vec) const
|
||||||
|
{
|
||||||
|
return (std::abs(x * vec.x) + std::abs(y * vec.y) + std::abs(z * vec.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Vector3::Value Vector3::GetDistanceTo(const Vector3 & vec) const
|
Vector3::Value Vector3::GetDistanceTo(const Vector3 & vec) const
|
||||||
{
|
{
|
||||||
@ -655,6 +673,9 @@ 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("Dot"), &Vector3::DotProduct)
|
||||||
|
.Func(_SC("AbsDot"), &Vector3::AbsDotProduct)
|
||||||
|
.Func(_SC("Cross"), &Vector3::CrossProduct)
|
||||||
.Func(_SC("DistanceTo"), &Vector3::GetDistanceTo)
|
.Func(_SC("DistanceTo"), &Vector3::GetDistanceTo)
|
||||||
.Func(_SC("SqDistanceTo"), &Vector3::GetSquaredDistanceTo)
|
.Func(_SC("SqDistanceTo"), &Vector3::GetSquaredDistanceTo)
|
||||||
// Member Overloads
|
// Member Overloads
|
||||||
|
@ -374,6 +374,21 @@ struct Vector3
|
|||||||
*/
|
*/
|
||||||
void Normalize();
|
void Normalize();
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Calculate dot product.
|
||||||
|
*/
|
||||||
|
Value DotProduct(const Vector3 & vec) const;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Calculate absolute dot product.
|
||||||
|
*/
|
||||||
|
Value AbsDotProduct(const Vector3 & vec) const;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Calculate cross product.
|
||||||
|
*/
|
||||||
|
Vector3 CrossProduct(const Vector3 & vec) const;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Return the distance between this vector and another vector.
|
* Return the distance between this vector and another vector.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user