mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 09:57:14 +01:00
Add methods to the Vector3 type to calculate interpolation.
This commit is contained in:
parent
26c0bc4872
commit
4a2b9d5400
@ -570,6 +570,25 @@ bool Vector3::IsBetweenPoints(const Vector3 & begin, const Vector3 & end) const
|
||||
return EpsLtEq(GetSquaredDistanceTo(begin), length) && EpsLtEq(GetSquaredDistanceTo(end), length);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector3::Interpolate(const Vector3 & a, const Vector3 & b, Value d)
|
||||
{
|
||||
x = STOVAL(static_cast< Float64 >(b.x) + ((a.x - b.x) * d));
|
||||
y = STOVAL(static_cast< Float64 >(b.y) + ((a.y - b.y) * d));
|
||||
z = STOVAL(static_cast< Float64 >(b.z) + ((a.z - b.z) * d));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3 Vector3::Interpolated(const Vector3 & vec, Value d) const
|
||||
{
|
||||
const Float64 inv = 1.0 - d;
|
||||
return Vector3(
|
||||
STOVAL((vec.x * inv) + (x * d)),
|
||||
STOVAL((vec.y * inv) + (y * d)),
|
||||
STOVAL((vec.z * inv) + (z * d))
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector3 & Vector3::Get(CSStr str)
|
||||
{
|
||||
@ -693,6 +712,8 @@ void Register_Vector3(HSQUIRRELVM vm)
|
||||
.Func(_SC("DistanceTo"), &Vector3::GetDistanceTo)
|
||||
.Func(_SC("SqDistanceTo"), &Vector3::GetSquaredDistanceTo)
|
||||
.Func(_SC("IsBetweenPoints"), &Vector3::IsBetweenPoints)
|
||||
.Func(_SC("Interpolate"), &Vector3::Interpolate)
|
||||
.Func(_SC("Interpolated"), &Vector3::Interpolated)
|
||||
// Member Overloads
|
||||
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)
|
||||
|
@ -409,6 +409,16 @@ struct Vector3
|
||||
*/
|
||||
bool IsBetweenPoints(const Vector3 & begin, const Vector3 & end) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Sets this vector to the linearly interpolated vector between a and b.
|
||||
*/
|
||||
void Interpolate(const Vector3 & a, const Vector3 & b, Value d);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Sets this vector to the linearly interpolated vector between a and b.
|
||||
*/
|
||||
Vector3 Interpolated(const Vector3 & vec, Value d) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector3 type from a string.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user