1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Add method to the Vector3 type to obtain a rotated version of the point.

This commit is contained in:
Sandu Liviu Catalin 2016-08-04 03:41:46 +03:00
parent 4a2b9d5400
commit ef2bc41fbc
2 changed files with 13 additions and 0 deletions

View File

@ -589,6 +589,13 @@ Vector3 Vector3::Interpolated(const Vector3 & vec, Value d) const
);
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::Rotated(const Vector3 & axis, Value angle) const
{
const Vector3 o(axis * axis.DotProduct(*this));
return (o + ((*this - o) * std::cos(angle)) + (axis.CrossProduct(*this) * std::sin(angle)));
}
// ------------------------------------------------------------------------------------------------
const Vector3 & Vector3::Get(CSStr str)
{
@ -714,6 +721,7 @@ void Register_Vector3(HSQUIRRELVM vm)
.Func(_SC("IsBetweenPoints"), &Vector3::IsBetweenPoints)
.Func(_SC("Interpolate"), &Vector3::Interpolate)
.Func(_SC("Interpolated"), &Vector3::Interpolated)
.Func(_SC("Rotated"), &Vector3::Rotated)
// Member Overloads
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)

View File

@ -419,6 +419,11 @@ struct Vector3
*/
Vector3 Interpolated(const Vector3 & vec, Value d) const;
/* --------------------------------------------------------------------------------------------
* Rotates the vector by a specified number of degrees around the Y axis and the specified center.
*/
Vector3 Rotated(const Vector3 & axis, Value angle) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/