@@ -539,13 +539,13 @@ void Quaternion::RotationYawPitchRoll(float yaw, float pitch, float roll, Quater
|
|||||||
result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
|
result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::GetRotationFromNormal(const Vector3& InNormal, const Transform& InReferenceTransform)
|
Quaternion Quaternion::GetRotationFromNormal(const Vector3& normal, const Transform& reference)
|
||||||
{
|
{
|
||||||
Float3 up = InReferenceTransform.GetUp();
|
Float3 up = reference.GetUp();
|
||||||
auto dot = Vector3::Dot(InNormal, up);
|
const float dot = Vector3::Dot(normal, up);
|
||||||
if (Math::NearEqual(Math::Abs(dot), 1))
|
if (Math::NearEqual(Math::Abs(dot), 1))
|
||||||
{
|
{
|
||||||
up = InReferenceTransform.GetRight();
|
up = reference.GetRight();
|
||||||
}
|
}
|
||||||
return Quaternion::LookRotation(InNormal, up);
|
return Quaternion::LookRotation(normal, up);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1491,16 +1491,16 @@ namespace FlaxEngine
|
|||||||
/// <example><para><b>Example code:</b></para>
|
/// <example><para><b>Example code:</b></para>
|
||||||
/// <code>
|
/// <code>
|
||||||
/// <see langword="public" /> <see langword="class" /> GetRotationFromNormalExample : <see cref="Script"/><br/>
|
/// <see langword="public" /> <see langword="class" /> GetRotationFromNormalExample : <see cref="Script"/><br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> RayOrigin;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrigin.Position, RayOrigin.Transform.Forward, out <see cref="RayCastHit"/> hit)
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see cref="Vector3"/> position = Hit.Collider.Position;
|
/// <see cref="Vector3"/> position = hit.Collider.Position;
|
||||||
/// <see cref="Transform"/> transform = Hit.Collider.Transform;
|
/// <see cref="Transform"/> transform = hit.Collider.Transform;
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
/// <see cref="Vector3"/> point = hit.Point;
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
/// <see cref="Vector3"/> normal = hit.Normal;
|
||||||
/// <see cref="Quaternion"/> rot = <see cref="Quaternion"/>.GetRotationFromNormal(normal,transform);
|
/// <see cref="Quaternion"/> rot = <see cref="Quaternion"/>.GetRotationFromNormal(normal,transform);
|
||||||
/// SomeObject.Position = point;
|
/// SomeObject.Position = point;
|
||||||
/// SomeObject.Orientation = rot;
|
/// SomeObject.Orientation = rot;
|
||||||
@@ -1510,18 +1510,16 @@ namespace FlaxEngine
|
|||||||
/// </code>
|
/// </code>
|
||||||
/// </example>
|
/// </example>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
/// <param name="normal">The normal vector.</param>
|
||||||
/// <param name="InReferenceTransform">The reference transform.</param>
|
/// <param name="reference">The reference transform.</param>
|
||||||
/// <returns>The rotation from the normal vector.</returns>
|
/// <returns>The rotation from the normal vector.</returns>
|
||||||
public static Quaternion GetRotationFromNormal(Vector3 InNormal, Transform InReferenceTransform)
|
public static Quaternion GetRotationFromNormal(Vector3 normal, Transform reference)
|
||||||
{
|
{
|
||||||
Float3 up = InReferenceTransform.Up;
|
Float3 up = reference.Up;
|
||||||
var dot = Vector3.Dot(InNormal, up);
|
var dot = Vector3.Dot(normal, up);
|
||||||
if (Mathf.NearEqual(Math.Abs(dot), 1))
|
if (Mathf.NearEqual(Math.Abs(dot), 1))
|
||||||
{
|
up = reference.Right;
|
||||||
up = InReferenceTransform.Right;
|
return LookRotation(normal, up);
|
||||||
}
|
|
||||||
return LookRotation(InNormal, up);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -661,16 +661,13 @@ public:
|
|||||||
// @param result When the method completes, contains the newly created quaternion
|
// @param result When the method completes, contains the newly created quaternion
|
||||||
static void RotationYawPitchRoll(float yaw, float pitch, float roll, Quaternion& result);
|
static void RotationYawPitchRoll(float yaw, float pitch, float roll, Quaternion& result);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets rotation from a normal in relation to a transform.<br/>
|
/// Gets rotation from a normal in relation to a transform. This function is especially useful for axis aligned faces, and with <seealso cref="Physics::RayCast"/>.
|
||||||
/// This function is especially useful for axis aligned faces,
|
|
||||||
/// and with <seealso cref="Physics::RayCast"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
/// <param name="normal">The normal vector.</param>
|
||||||
/// <param name="InReferenceTransform">The reference transform.</param>
|
/// <param name="reference">The reference transform.</param>
|
||||||
/// <returns>The rotation from the normal vector.</returns>
|
/// <returns>The rotation from the normal vector.</returns>
|
||||||
static Quaternion GetRotationFromNormal(const Vector3& InNormal, const Transform& InReferenceTransform);
|
static Quaternion GetRotationFromNormal(const Vector3& normal, const Transform& reference);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -253,26 +253,8 @@ void Transform::Lerp(const Transform& t1, const Transform& t2, float amount, Tra
|
|||||||
Float3::Lerp(t1.Scale, t2.Scale, amount, result.Scale);
|
Float3::Lerp(t1.Scale, t2.Scale, amount, result.Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize)
|
Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& point, const Vector3& normal, const Vector3& normalOffset, const Transform& relativeTo, const Vector3& gridSize, const Float3& scale)
|
||||||
{
|
{
|
||||||
Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo);
|
Quaternion rot = Quaternion::GetRotationFromNormal(normal, relativeTo);
|
||||||
return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale);
|
return Transform(Vector3::SnapToGrid(point, gridSize, rot, relativeTo.Translation, normalOffset), rot, scale);
|
||||||
}
|
|
||||||
|
|
||||||
inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize)
|
|
||||||
{
|
|
||||||
Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo);
|
|
||||||
return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3::One);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize)
|
|
||||||
{
|
|
||||||
Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo);
|
|
||||||
return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Transform Transform::AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize)
|
|
||||||
{
|
|
||||||
Quaternion rot = Quaternion::GetRotationFromNormal(InNormal, InRelativeTo);
|
|
||||||
return Transform(Vector3::SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3::One);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -477,24 +477,25 @@ namespace FlaxEngine
|
|||||||
Quaternion.Slerp(ref start.Orientation, ref end.Orientation, amount, out result.Orientation);
|
Quaternion.Slerp(ref start.Orientation, ref end.Orientation, amount, out result.Orientation);
|
||||||
Float3.Lerp(ref start.Scale, ref end.Scale, amount, out result.Scale);
|
Float3.Lerp(ref start.Scale, ref end.Scale, amount, out result.Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combines the functions: <br/>
|
/// Combines the functions:<br/>
|
||||||
/// <see cref="Vector3.SnapToRotatedGridWithOffset"/>,<br/>
|
/// <see cref="Vector3.SnapToGrid(FlaxEngine.Vector3,FlaxEngine.Vector3)"/>,<br/>
|
||||||
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
||||||
/// <example><para><b>Example code:</b></para>
|
/// <example><para><b>Example code:</b></para>
|
||||||
/// <code>
|
/// <code>
|
||||||
/// <see langword="public" /> <see langword="class" /> AlignRotationToObjectAndSnapToGridExample : <see cref="Script"/><br/>
|
/// <see langword="public" /> <see langword="class" /> AlignRotationToObjectAndSnapToGridExample : <see cref="Script"/><br/>
|
||||||
/// <see langword="public" /> <see cref="float"/> Offset = 50.0f;<br/>
|
/// <see langword="public" /> <see cref="Vector3"/> Offset = new Vector3(0, 0, 50f);<br/>
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> RayOrigin;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrigin.Position, RayOrigin.Transform.Forward, out <see cref="RayCastHit"/> hit)
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see cref="Transform"/> transform = Hit.Collider.Transform;
|
/// <see cref="Transform"/> transform = hit.Collider.Transform;
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
/// <see cref="Vector3"/> point = hit.Point;
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
/// <see cref="Vector3"/> normal = hit.Normal;
|
||||||
/// SomeObject.Transform = <see cref="Transform"/>.AlignRotationToNormalAndSnapToGrid
|
/// SomeObject.Transform = <see cref="Transform"/>.AlignRotationToNormalAndSnapToGrid
|
||||||
/// (
|
/// (
|
||||||
/// point,
|
/// point,
|
||||||
@@ -502,7 +503,8 @@ namespace FlaxEngine
|
|||||||
/// Offset,
|
/// Offset,
|
||||||
/// transform,
|
/// transform,
|
||||||
/// SomeObject.Scale,
|
/// SomeObject.Scale,
|
||||||
/// GridSize
|
/// GridSize,
|
||||||
|
/// Float3.One
|
||||||
/// );
|
/// );
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@@ -510,127 +512,37 @@ namespace FlaxEngine
|
|||||||
/// </code>
|
/// </code>
|
||||||
/// </example>
|
/// </example>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
/// <param name="point">The position to snap.</param>
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
/// <param name="gridSize">The size of the grid.</param>
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
/// <param name="normalOffset">The local grid offset to apply after snapping.</param>
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
/// <param name="normal">The normal vector.</param>
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
/// <param name="relativeTo">The relative transform.</param>
|
||||||
/// <param name="InReturnScale">The scale to apply to the transform.</param>
|
/// <param name="scale">The scale to apply to the transform.</param>
|
||||||
/// <returns>The rotated and snapped transform.</returns>
|
/// <returns>The rotated and snapped transform.</returns>
|
||||||
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize)
|
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 point, Vector3 normal, Vector3 normalOffset, Transform relativeTo, Vector3 gridSize, Float3 scale)
|
||||||
{
|
{
|
||||||
Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo);
|
Quaternion rot = Quaternion.GetRotationFromNormal(normal, relativeTo);
|
||||||
return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, new Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, InReturnScale);
|
return new Transform(Vector3.SnapToGrid(point, gridSize, rot, relativeTo.Translation, normalOffset), rot, scale);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Combines the functions: <br/>
|
|
||||||
/// <see cref="Vector3.SnapToRotatedGridWithOffset"/>,<br/>
|
|
||||||
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
|
||||||
/// <example><para><b>Example code:</b></para>
|
|
||||||
/// <code>
|
|
||||||
/// <see langword="public" /> <see langword="class" /> AlignRotationToObjectAndSnapToGridExample : <see cref="Script"/><br/>
|
|
||||||
/// <see langword="public" /> <see cref="float"/> Offset = 50.0f;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
|
||||||
/// {<br/>
|
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
|
||||||
/// {<br/>
|
|
||||||
/// <see cref="Transform"/> transform = Hit.Collider.Transform;
|
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
|
||||||
/// SomeObject.Transform = <see cref="Transform"/>.AlignRotationToNormalAndSnapToGrid
|
|
||||||
/// (
|
|
||||||
/// point,
|
|
||||||
/// normal,
|
|
||||||
/// Offset,
|
|
||||||
/// transform,
|
|
||||||
/// GridSize
|
|
||||||
/// );
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// </code>
|
|
||||||
/// </example>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
|
||||||
/// <returns>The rotated and snapped transform with scale <see cref="Float3.One"/>.</returns>
|
|
||||||
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, float InNormalOffset, Transform InRelativeTo, Vector3 InGridSize)
|
|
||||||
{
|
|
||||||
Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo);
|
|
||||||
return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, new Vector3(0, 0, InNormalOffset), rot, InGridSize), rot, Float3.One);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combines the functions:<br/>
|
/// Combines the functions:<br/>
|
||||||
/// <see cref="Vector3.SnapToRotatedGridWithOffset"/>,<br/>
|
/// <see cref="Vector3.SnapToGrid(FlaxEngine.Vector3,FlaxEngine.Vector3)"/>,<br/>
|
||||||
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
||||||
/// <example><para><b>Example code:</b></para>
|
/// <example><para><b>Example code:</b></para>
|
||||||
/// <code>
|
/// <code>
|
||||||
/// <see langword="public" /> <see langword="class" /> AlignRotationToObjectAndSnapToGridExample : <see cref="Script"/><br/>
|
/// <see langword="public" /> <see langword="class" /> AlignRotationToObjectAndSnapToGridExample : <see cref="Script"/><br/>
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> Offset = new Vector3(0, 0, 50f);<br/>
|
/// <see langword="public" /> <see cref="Vector3"/> Offset = new Vector3(0, 0, 50f);<br/>
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> RayOrigin;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrigin.Position, RayOrigin.Transform.Forward, out <see cref="RayCastHit"/> hit)
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see cref="Transform"/> transform = Hit.Collider.Transform;
|
/// <see cref="Transform"/> transform = hit.Collider.Transform;
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
/// <see cref="Vector3"/> point = hit.Point;
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
/// <see cref="Vector3"/> normal = hit.Normal;
|
||||||
/// SomeObject.Transform = <see cref="Transform"/>.AlignRotationToNormalAndSnapToGrid
|
|
||||||
/// (
|
|
||||||
/// point,
|
|
||||||
/// normal,
|
|
||||||
/// Offset,
|
|
||||||
/// transform,
|
|
||||||
/// SomeObject.Scale,
|
|
||||||
/// GridSize
|
|
||||||
/// );
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// </code>
|
|
||||||
/// </example>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
|
||||||
/// <param name="InReturnScale">The scale to apply to the transform.</param>
|
|
||||||
/// <returns>The rotated and snapped transform.</returns>
|
|
||||||
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Float3 InReturnScale, Vector3 InGridSize)
|
|
||||||
{
|
|
||||||
Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo);
|
|
||||||
return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, InReturnScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Combines the functions:<br/>
|
|
||||||
/// <see cref="Vector3.SnapToRotatedGridWithOffset"/>,<br/>
|
|
||||||
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
|
||||||
/// <example><para><b>Example code:</b></para>
|
|
||||||
/// <code>
|
|
||||||
/// <see langword="public" /> <see langword="class" /> AlignRotationToObjectAndSnapToGridExample : <see cref="Script"/><br/>
|
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> Offset = new Vector3(0, 0, 50f);<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
|
||||||
/// {<br/>
|
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
|
||||||
/// {<br/>
|
|
||||||
/// <see cref="Transform"/> transform = Hit.Collider.Transform;
|
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
|
||||||
/// SomeObject.Transform = <see cref="Transform"/>.AlignRotationToNormalAndSnapToGrid
|
/// SomeObject.Transform = <see cref="Transform"/>.AlignRotationToNormalAndSnapToGrid
|
||||||
/// (
|
/// (
|
||||||
/// point,
|
/// point,
|
||||||
@@ -645,16 +557,15 @@ namespace FlaxEngine
|
|||||||
/// </code>
|
/// </code>
|
||||||
/// </example>
|
/// </example>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
/// <param name="point">The position to snap.</param>
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
/// <param name="gridSize">The size of the grid.</param>
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
/// <param name="normalOffset">The local grid offset to apply after snapping.</param>
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
/// <param name="normal">The normal vector.</param>
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
/// <param name="relativeTo">The relative transform.</param>
|
||||||
/// <returns>The rotated and snapped transform with scale <see cref="Float3.One"/>.</returns>
|
/// <returns>The rotated and snapped transform with scale <see cref="Float3.One"/>.</returns>
|
||||||
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 InPoint, Vector3 InNormal, Vector3 InNormalOffset, Transform InRelativeTo, Vector3 InGridSize)
|
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 point, Vector3 normal, Vector3 normalOffset, Transform relativeTo, Vector3 gridSize)
|
||||||
{
|
{
|
||||||
Quaternion rot = Quaternion.GetRotationFromNormal(InNormal, InRelativeTo);
|
return AlignRotationToNormalAndSnapToGrid(point, normal, normalOffset, relativeTo, gridSize, Float3.One);
|
||||||
return new Transform(Vector3.SnapToRotatedGridWithOffset(InPoint, InRelativeTo.Translation, InNormalOffset, rot, InGridSize), rot, Float3.One);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -18,20 +18,20 @@ API_STRUCT() struct FLAXENGINE_API Transform
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The translation vector of the transform.
|
/// The translation vector of the transform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD(Attributes = "EditorOrder(10), EditorDisplay(null, \"Position\"), ValueCategory(Utils.ValueCategory.Distance)")
|
API_FIELD(Attributes="EditorOrder(10), EditorDisplay(null, \"Position\"), ValueCategory(Utils.ValueCategory.Distance)")
|
||||||
Vector3 Translation;
|
Vector3 Translation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The rotation of the transform.
|
/// The rotation of the transform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD(Attributes = "EditorOrder(20), EditorDisplay(null, \"Rotation\"), ValueCategory(Utils.ValueCategory.Angle)")
|
API_FIELD(Attributes="EditorOrder(20), EditorDisplay(null, \"Rotation\"), ValueCategory(Utils.ValueCategory.Angle)")
|
||||||
Quaternion Orientation;
|
Quaternion Orientation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The scale vector of the transform.
|
/// The scale vector of the transform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD(Attributes = "EditorOrder(30), Limit(float.MinValue, float.MaxValue, 0.01f)")
|
API_FIELD(Attributes="EditorOrder(30), Limit(float.MinValue, float.MaxValue, 0.01f)")
|
||||||
Float3 Scale;
|
Float3 Scale;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -291,61 +291,19 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combines the functions: <br/>
|
/// Combines the functions: <br/>
|
||||||
/// <see cref="SnapToRotatedGridWithOffset"/>,<br/>
|
/// <see cref="SnapToGrid"/>,<br/>
|
||||||
/// <see cref="GetRotationFromNormal"/>.
|
/// <see cref="GetRotationFromNormal"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
/// <param name="point">The position to snap.</param>
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
/// <param name="gridSize">The size of the grid.</param>
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
/// <param name="normalOffset">The local grid offset to apply after snapping.</param>
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
/// <param name="normal">The normal vector.</param>
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
/// <param name="relativeTo">The relative transform.</param>
|
||||||
/// <param name="InReturnScale">The scale to apply to the transform.</param>
|
/// <param name="scale">The scale to apply to the transform.</param>
|
||||||
/// <returns>The rotated and snapped transform.</returns>
|
/// <returns>The rotated and snapped transform.</returns>
|
||||||
static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize);
|
static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& point, const Vector3& normal, const Vector3& normalOffset, const Transform& relativeTo, const Vector3& gridSize, const Float3& scale = Float3::One);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Combines the functions: <br/>
|
|
||||||
/// <see cref="Vector3.SnapToRotatedGridWithOffset"/>,<br/>
|
|
||||||
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
|
||||||
/// <returns>The rotated and snapped transform with scale <see cref="Float3.One"/>.</returns>
|
|
||||||
static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, float InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Combines the functions: <br/>
|
|
||||||
/// <see cref="SnapToRotatedGridWithOffset"/>,<br/>
|
|
||||||
/// <see cref="GetRotationFromNormal"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
|
||||||
/// <param name="InReturnScale">The scale to apply to the transform.</param>
|
|
||||||
/// <returns>The rotated and snapped transform.</returns>
|
|
||||||
static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Float3& InReturnScale, const Vector3& InGridSize);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Combines the functions: <br/>
|
|
||||||
/// <see cref="Vector3.SnapToRotatedGridWithOffset"/>,<br/>
|
|
||||||
/// <see cref="Quaternion.GetRotationFromNormal"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InNormalOffset">The local Z grid offset to apply after snapping.</param>
|
|
||||||
/// <param name="InNormal">The normal vector.</param>
|
|
||||||
/// <param name="InRelativeTo">The relative transform.</param>
|
|
||||||
/// <returns>The rotated and snapped transform with scale <see cref="Float3.One"/>.</returns>
|
|
||||||
static Transform AlignRotationToNormalAndSnapToGrid(const Vector3& InPoint, const Vector3& InNormal, const Vector3& InNormalOffset, const Transform& InRelativeTo, const Vector3& InGridSize);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FORCE_INLINE Transform operator*(const Transform& other) const
|
FORCE_INLINE Transform operator*(const Transform& other) const
|
||||||
|
|||||||
@@ -328,20 +328,14 @@ template<>
|
|||||||
Float3 Float3::SnapToGrid(const Float3& pos, const Float3& gridSize)
|
Float3 Float3::SnapToGrid(const Float3& pos, const Float3& gridSize)
|
||||||
{
|
{
|
||||||
return Float3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X,
|
return Float3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X,
|
||||||
Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y,
|
Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y,
|
||||||
Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z);
|
Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Float3 Float3::SnapToRotatedGridWithOffset(const Float3& InPoint, const Float3& InCenterPoint, const Float3& InOffset, const Quaternion& InOrientation, const Float3& InGridSize)
|
Float3 Float3::SnapToGrid(const Float3& point, const Float3& gridSize, const Quaternion& gridOrientation, const Float3& gridOrigin, const Float3& offset)
|
||||||
{
|
{
|
||||||
return (InOrientation * (InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize) + InOffset)) + InCenterPoint;
|
return (gridOrientation * (gridOrientation.Conjugated() * SnapToGrid(point - gridOrigin, gridSize) + offset)) + gridOrigin;
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
Float3 Float3::SnapToRotatedGrid(const Float3& InPoint, const Float3& InCenterPoint, const Quaternion& InOrientation, const Float3& InGridSize)
|
|
||||||
{
|
|
||||||
return (InOrientation * InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize)) + InCenterPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Double
|
// Double
|
||||||
@@ -661,21 +655,15 @@ double Double3::Angle(const Double3& from, const Double3& to)
|
|||||||
template<>
|
template<>
|
||||||
Double3 Double3::SnapToGrid(const Double3& pos, const Double3& gridSize)
|
Double3 Double3::SnapToGrid(const Double3& pos, const Double3& gridSize)
|
||||||
{
|
{
|
||||||
return Double3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X,
|
return Double3(Math::Ceil((pos.X - (gridSize.X * 0.5)) / gridSize.X) * gridSize.X,
|
||||||
Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y,
|
Math::Ceil((pos.Y - (gridSize.Y * 0.5)) / gridSize.Y) * gridSize.Y,
|
||||||
Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z);
|
Math::Ceil((pos.Z - (gridSize.Z * 0.5)) / gridSize.Z) * gridSize.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Double3 Double3::SnapToRotatedGridWithOffset(const Double3& InPoint, const Double3& InCenterPoint, const Double3& InOffset, const Quaternion& InOrientation, const Double3& InGridSize)
|
Double3 Double3::SnapToGrid(const Double3& point, const Double3& gridSize, const Quaternion& gridOrientation, const Double3& gridOrigin, const Double3& offset)
|
||||||
{
|
{
|
||||||
return (InOrientation * (InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize) + InOffset)) + InCenterPoint;
|
return (gridOrientation * (gridOrientation.Conjugated() * SnapToGrid(point - gridOrigin, gridSize) + offset)) + gridOrigin;
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
Double3 Double3::SnapToRotatedGrid(const Double3& InPoint, const Double3& InCenterPoint, const Quaternion& InOrientation, const Double3& InGridSize)
|
|
||||||
{
|
|
||||||
return (InOrientation * InOrientation.Conjugated() * Float3::SnapToGrid((InPoint - InCenterPoint), InGridSize)) + InCenterPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int
|
// Int
|
||||||
@@ -896,19 +884,13 @@ int32 Int3::Angle(const Int3& from, const Int3& to)
|
|||||||
template<>
|
template<>
|
||||||
Int3 Int3::SnapToGrid(const Int3& pos, const Int3& gridSize)
|
Int3 Int3::SnapToGrid(const Int3& pos, const Int3& gridSize)
|
||||||
{
|
{
|
||||||
return Double3(Math::Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X,
|
return Int3(((pos.X - (gridSize.X / 2)) / gridSize.X) * gridSize.X,
|
||||||
Math::Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y,
|
((pos.Y - (gridSize.Y / 2)) / gridSize.Y) * gridSize.Y,
|
||||||
Math::Ceil((pos.Z - (gridSize.Z * 0.5f)) / gridSize.Z) * gridSize.Z);
|
((pos.Z - (gridSize.Z / 2)) / gridSize.Z) * gridSize.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Int3 Int3::SnapToRotatedGridWithOffset(const Int3& InPoint, const Int3& InCenterPoint, const Int3& InOffset, const Quaternion& InOrientation, const Int3& InGridSize)
|
Int3 Int3::SnapToGrid(const Int3& point, const Int3& gridSize, const Quaternion& gridOrientation, const Int3& gridOrigin, const Int3& offset)
|
||||||
{
|
{
|
||||||
return (InOrientation * (InOrientation.Conjugated() * Int3::SnapToGrid((InPoint - InCenterPoint), InGridSize) + InOffset)) + InCenterPoint;
|
return (gridOrientation * (gridOrientation.Conjugated() * SnapToGrid(point - gridOrigin, gridSize) + offset)) + gridOrigin;
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
Int3 Int3::SnapToRotatedGrid(const Int3& InPoint, const Int3& InCenterPoint, const Quaternion& InOrientation, const Int3& InGridSize)
|
|
||||||
{
|
|
||||||
return (InOrientation * InOrientation.Conjugated() * Int3::SnapToGrid((InPoint - InCenterPoint), InGridSize)) + InCenterPoint;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1686,25 +1686,25 @@ namespace FlaxEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Snaps the <paramref name="InPoint"/> onto the rotated grid.<br/>
|
/// Snaps the <paramref name="point"/> onto the rotated grid.<br/>
|
||||||
/// For world aligned grid snapping use <b><see cref="SnapToGrid"/></b> instead.
|
/// For world aligned grid snapping use <b><see cref="SnapToGrid(FlaxEngine.Vector3,FlaxEngine.Vector3)"/></b> instead.
|
||||||
/// <example><para><b>Example code:</b></para>
|
/// <example><para><b>Example code:</b></para>
|
||||||
/// <code>
|
/// <code>
|
||||||
/// <see langword="public" /> <see langword="class" /> SnapToRotatedGridExample : <see cref="Script"/><br/>
|
/// <see langword="public" /> <see langword="class" /> SnapToGridExample : <see cref="Script"/><br/>
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> RayOrigin;<br/>
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrigin.Position, RayOrigin.Transform.Forward, out <see cref="RayCastHit"/> hit)
|
||||||
/// {<br/>
|
/// {<br/>
|
||||||
/// <see cref="Vector3"/> position = Hit.Collider.Position;
|
/// <see cref="Vector3"/> position = hit.Collider.Position;
|
||||||
/// <see cref="FlaxEngine.Transform"/> transform = Hit.Collider.Transform;
|
/// <see cref="FlaxEngine.Transform"/> transform = hit.Collider.Transform;
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
/// <see cref="Vector3"/> point = hit.Point;
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
/// <see cref="Vector3"/> normal = hit.Normal;
|
||||||
/// //Get rotation from normal relative to collider transform
|
/// //Get rotation from normal relative to collider transform
|
||||||
/// <see cref="Quaternion"/> rot = <see cref="Quaternion"/>.GetRotacionFromNormal(normal,transform);
|
/// <see cref="Quaternion"/> rot = <see cref="Quaternion"/>.GetRotationFromNormal(normal, transform);
|
||||||
/// point = <see cref="Vector3"/>.SnapToRotatedGrid(point,position,rot,GridSize);
|
/// point = <see cref="Vector3"/>.SnapToGrid(point, GridSize, rot, position);
|
||||||
/// SomeObject.Position = point;
|
/// SomeObject.Position = point;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@@ -1712,139 +1712,15 @@ namespace FlaxEngine
|
|||||||
/// </code>
|
/// </code>
|
||||||
/// </example>
|
/// </example>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
/// <param name="point">The position to snap.</param>
|
||||||
/// <param name="InCenterPoint">The center point.</param>
|
/// <param name="gridSize">The size of the grid.</param>
|
||||||
/// <param name="InOrientation">The rotation of the grid.</param>
|
/// <param name="gridOrientation">The rotation of the grid.</param>
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
/// <param name="gridOrigin">The center point of the grid.</param>
|
||||||
|
/// <param name="offset">The local position offset applied to the snapped position before grid rotation.</param>
|
||||||
/// <returns>The position snapped to the grid.</returns>
|
/// <returns>The position snapped to the grid.</returns>
|
||||||
public static Vector3 SnapToRotatedGrid(Vector3 InPoint, Vector3 InCenterPoint, Quaternion InOrientation, Vector3 InGridSize)
|
public static Vector3 SnapToGrid(Vector3 point, Vector3 gridSize, Quaternion gridOrientation, Vector3 gridOrigin, Vector3 offset)
|
||||||
{
|
{
|
||||||
Vector3 p = (InPoint - InCenterPoint) * InOrientation.Conjugated();
|
return ((SnapToGrid(point - gridOrigin, gridSize) * gridOrientation.Conjugated() + offset) * gridOrientation) + gridOrigin;
|
||||||
return (SnapToGrid(p, InGridSize) * InOrientation) + InCenterPoint;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// The same as <see cref="SnapToRotatedGrid"/> but with local offset applied after point is snapped.
|
|
||||||
/// <example><para><b>Example code:</b></para>
|
|
||||||
/// <code>
|
|
||||||
/// <see langword="public" /> <see langword="class" /> SnapToRotatedGridWithOffsetExample : <see cref="Script"/><br/>
|
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> Offset = new Vector3(0, 0, 50f);<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Vector3"/> GridSize = <see cref="Vector3.One"/> * 20.0f;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Actor"/> RayOrgin;<br/>
|
|
||||||
/// <see langword="public" /> <see cref="Actor"/> SomeObject;<br/>
|
|
||||||
/// <see langword="public" /> <see langword="override" /> <see langword="void" /> <see cref="Script.OnFixedUpdate"/><br/>
|
|
||||||
/// {<br/>
|
|
||||||
/// <see langword="if" /> (<see cref="Physics"/>.RayCast(RayOrgin.Position, RayOrgin.Transform.Forward, out <see cref="RayCastHit"/> Hit)
|
|
||||||
/// {<br/>
|
|
||||||
/// <see cref="Vector3"/> position = Hit.Collider.Position;
|
|
||||||
/// <see cref="FlaxEngine.Transform"/> transform = Hit.Collider.Transform;
|
|
||||||
/// <see cref="Vector3"/> point = Hit.Point;
|
|
||||||
/// <see cref="Vector3"/> normal = Hit.Normal;
|
|
||||||
/// <see cref="Quaternion"/> rot = <see cref="Quaternion"/>.GetRotationFromNormal(normal,transform);
|
|
||||||
/// point = <see cref="Vector3"/>.SnapToRotatedGridWithOffset(point,position,Offset,rot,GridSize);
|
|
||||||
/// SomeObject.Position = point;
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// </code>
|
|
||||||
/// </example>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InCenterPoint">The center point.</param>
|
|
||||||
/// <param name="InOrientation">The rotation of the grid.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InOffset">The local grid offset to apply after snapping.</param>
|
|
||||||
/// <returns>The position snapped to the grid, with offset applied.</returns>
|
|
||||||
public static Vector3 SnapToRotatedGridWithOffset(Vector3 InPoint, Vector3 InCenterPoint, Vector3 InOffset, Quaternion InOrientation, Vector3 InGridSize)
|
|
||||||
{
|
|
||||||
return ((SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) + InOffset) * InOrientation) + InCenterPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the closest vector id to <see langword="this" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InArray"></param>
|
|
||||||
/// <param name="Tolerance"></param>
|
|
||||||
/// <returns>index or -1 if all vectors in array are outside of <paramref name="Tolerance"/></returns>
|
|
||||||
public int GetClosest(ref Vector3[] InArray, Real Tolerance)
|
|
||||||
{
|
|
||||||
Vector3 self = this;
|
|
||||||
int FinalID = -1;
|
|
||||||
for (int i = 0; i < InArray.Length; i++)
|
|
||||||
{
|
|
||||||
if (Distance(self, InArray[i]) <= Tolerance)
|
|
||||||
{
|
|
||||||
FinalID = i;
|
|
||||||
self = InArray[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FinalID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the closest vector id to <see langword="this" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InList"></param>
|
|
||||||
/// <param name="Tolerance"></param>
|
|
||||||
/// <returns>index or -1 if all vectors in array are outside of <paramref name="Tolerance"/></returns>
|
|
||||||
public int GetClosest(ref System.Collections.Generic.List<Vector3> InList, Real Tolerance)
|
|
||||||
{
|
|
||||||
Vector3 self = this;
|
|
||||||
int FinalID = -1;
|
|
||||||
for (int i = 0; i < InList.Count; i++)
|
|
||||||
{
|
|
||||||
if (Distance(self, InList[i]) <= Tolerance)
|
|
||||||
{
|
|
||||||
FinalID = i;
|
|
||||||
self = InList[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FinalID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the closest vector to <see langword="this" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InArray"></param>
|
|
||||||
/// <param name="OutDistance"></param>
|
|
||||||
/// <param name="OutVector"></param>
|
|
||||||
public void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref Real OutDistance)
|
|
||||||
{
|
|
||||||
Vector3 self = this;
|
|
||||||
Real LastDistance = Real.MaxValue;
|
|
||||||
for (int i = 0; i < InArray.Length; i++)
|
|
||||||
{
|
|
||||||
var d = Distance(self, InArray[i]);
|
|
||||||
if (d <= LastDistance)
|
|
||||||
{
|
|
||||||
self = InArray[i];
|
|
||||||
LastDistance = d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OutDistance = LastDistance;
|
|
||||||
OutVector = self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the closest vector to <see langword="this" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InList"></param>
|
|
||||||
/// <param name="OutDistance"></param>
|
|
||||||
/// <param name="OutVector"></param>
|
|
||||||
public void GetClosest(ref System.Collections.Generic.List<Vector3> InList, ref Vector3 OutVector, ref Real OutDistance)
|
|
||||||
{
|
|
||||||
Vector3 self = this;
|
|
||||||
Real LastDistance = Real.MaxValue;
|
|
||||||
for (int i = 0; i < InList.Count; i++)
|
|
||||||
{
|
|
||||||
var d = Distance(self, InList[i]);
|
|
||||||
if (d <= LastDistance)
|
|
||||||
{
|
|
||||||
self = InList[i];
|
|
||||||
LastDistance = d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OutDistance = LastDistance;
|
|
||||||
OutVector = self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -937,26 +937,15 @@ public:
|
|||||||
static FLAXENGINE_API Vector3Base SnapToGrid(const Vector3Base& pos, const Vector3Base& gridSize);
|
static FLAXENGINE_API Vector3Base SnapToGrid(const Vector3Base& pos, const Vector3Base& gridSize);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Snaps the <paramref name="InPoint"/> onto the rotated grid.<br/>
|
/// Snaps the <paramref name="point"/> onto the rotated grid. For world aligned grid snapping use <b><see cref="SnapToGrid"/></b> instead.
|
||||||
/// For world aligned grid snapping use <b><see cref="SnapToGrid"/></b> instead.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
/// <param name="point">The position to snap.</param>
|
||||||
/// <param name="InCenterPoint">The center point.</param>
|
/// <param name="gridSize">The size of the grid.</param>
|
||||||
/// <param name="InOrientation">The rotation of the grid.</param>
|
/// <param name="gridOrigin">The center point of the grid.</param>
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
/// <param name="gridOrientation">The rotation of the grid.</param>
|
||||||
|
/// <param name="offset">The local position offset applied to the snapped position before grid rotation.</param>
|
||||||
/// <returns>The position snapped to the grid.</returns>
|
/// <returns>The position snapped to the grid.</returns>
|
||||||
static FLAXENGINE_API Vector3Base SnapToRotatedGrid(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Quaternion& InOrientation, const Vector3Base& InGridSize);
|
static FLAXENGINE_API Vector3Base SnapToGrid(const Vector3Base& point, const Vector3Base& gridSize, const Quaternion& gridOrientation, const Vector3Base& gridOrigin = Zero, const Vector3Base& offset = Zero);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The same as <see cref="SnapToRotatedGrid"/> but with local offset applied after point is snapped.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="InPoint">The position to snap.</param>
|
|
||||||
/// <param name="InCenterPoint">The center point.</param>
|
|
||||||
/// <param name="InOrientation">The rotation of the grid.</param>
|
|
||||||
/// <param name="InGridSize">The size of the grid.</param>
|
|
||||||
/// <param name="InOffset">The local grid offset to apply after snapping.</param>
|
|
||||||
/// <returns>The position snapped to the grid, with offset applied.</returns>
|
|
||||||
static FLAXENGINE_API Vector3Base SnapToRotatedGridWithOffset(const Vector3Base& InPoint, const Vector3Base& InCenterPoint, const Vector3Base& InOffset, const Quaternion& InOrientation, const Vector3Base& InGridSize);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user