Add Transform.LocalToWorldVector and Transform.WorldToLocalVector
This commit is contained in:
@@ -94,6 +94,13 @@ Vector3 Transform::LocalToWorld(const Vector3& point) const
|
|||||||
return result + Translation;
|
return result + Translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 Transform::LocalToWorldVector(const Vector3& vector) const
|
||||||
|
{
|
||||||
|
Vector3 result = vector * Scale;
|
||||||
|
Vector3::Transform(result, Orientation, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void Transform::LocalToWorld(const Vector3& point, Vector3& result) const
|
void Transform::LocalToWorld(const Vector3& point, Vector3& result) const
|
||||||
{
|
{
|
||||||
Vector3 tmp = point * Scale;
|
Vector3 tmp = point * Scale;
|
||||||
@@ -171,6 +178,24 @@ Vector3 Transform::WorldToLocal(const Vector3& point) const
|
|||||||
return result * invScale;
|
return result * invScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 Transform::WorldToLocalVector(const Vector3& vector) const
|
||||||
|
{
|
||||||
|
Vector3 invScale = Scale;
|
||||||
|
if (invScale.X != 0.0f)
|
||||||
|
invScale.X = 1.0f / invScale.X;
|
||||||
|
if (invScale.Y != 0.0f)
|
||||||
|
invScale.Y = 1.0f / invScale.Y;
|
||||||
|
if (invScale.Z != 0.0f)
|
||||||
|
invScale.Z = 1.0f / invScale.Z;
|
||||||
|
|
||||||
|
const Quaternion invRotation = Orientation.Conjugated();
|
||||||
|
|
||||||
|
Vector3 result;
|
||||||
|
Vector3::Transform(vector, invRotation, result);
|
||||||
|
|
||||||
|
return result * invScale;
|
||||||
|
}
|
||||||
|
|
||||||
void Transform::WorldToLocal(const Vector3* points, int32 pointsCount, Vector3* result) const
|
void Transform::WorldToLocal(const Vector3* points, int32 pointsCount, Vector3* result) const
|
||||||
{
|
{
|
||||||
Vector3 invScale = Scale;
|
Vector3 invScale = Scale;
|
||||||
|
|||||||
@@ -197,6 +197,18 @@ namespace FlaxEngine
|
|||||||
return point + Translation;
|
return point + Translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs transformation of the given vector in local space to the world space of this transform.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The local space vector.</param>
|
||||||
|
/// <returns>The world space vector.</returns>
|
||||||
|
public Vector3 LocalToWorldVector(Vector3 vector)
|
||||||
|
{
|
||||||
|
vector *= Scale;
|
||||||
|
Vector3.Transform(ref vector, ref Orientation, out vector);
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform transformation of the given points in local space
|
/// Perform transformation of the given points in local space
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -259,6 +271,29 @@ namespace FlaxEngine
|
|||||||
return result * invScale;
|
return result * invScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform transformation of the given vector in world space
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">World space vector</param>
|
||||||
|
/// <returns>Local space vector</returns>
|
||||||
|
public Vector3 WorldToLocalVector(Vector3 vector)
|
||||||
|
{
|
||||||
|
Vector3 invScale = Scale;
|
||||||
|
if (invScale.X != 0.0f)
|
||||||
|
invScale.X = 1.0f / invScale.X;
|
||||||
|
if (invScale.Y != 0.0f)
|
||||||
|
invScale.Y = 1.0f / invScale.Y;
|
||||||
|
if (invScale.Z != 0.0f)
|
||||||
|
invScale.Z = 1.0f / invScale.Z;
|
||||||
|
|
||||||
|
Quaternion invRotation = Orientation;
|
||||||
|
invRotation.Invert();
|
||||||
|
|
||||||
|
Vector3.Transform(ref vector, ref invRotation, out var result);
|
||||||
|
|
||||||
|
return result * invScale;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform transformation of the given points in world space
|
/// Perform transformation of the given points in world space
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -184,6 +184,13 @@ public:
|
|||||||
/// <returns>The world space point.</returns>
|
/// <returns>The world space point.</returns>
|
||||||
Vector3 LocalToWorld(const Vector3& point) const;
|
Vector3 LocalToWorld(const Vector3& point) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs transformation of the given vector in local space to the world space of this transform.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The local space vector.</param>
|
||||||
|
/// <returns>The world space vector.</returns>
|
||||||
|
Vector3 LocalToWorldVector(const Vector3& vector) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs transformation of the given point in local space to the world space of this transform.
|
/// Performs transformation of the given point in local space to the world space of this transform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -220,6 +227,13 @@ public:
|
|||||||
/// <returns>The local space point.</returns>
|
/// <returns>The local space point.</returns>
|
||||||
Vector3 WorldToLocal(const Vector3& point) const;
|
Vector3 WorldToLocal(const Vector3& point) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs transformation of the given vector in world space to the local space of this transform.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The world space vector.</param>
|
||||||
|
/// <returns>The local space vector.</returns>
|
||||||
|
Vector3 WorldToLocalVector(const Vector3& vector) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs transformation of the given points in world space to the local space of this transform.
|
/// Performs transformation of the given points in world space to the local space of this transform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user