Update script Rotation class and its doc

This commit is contained in:
Sezz 2025-01-23 15:25:09 +11:00
parent 0dd0061a94
commit fc0c260ea1
6 changed files with 71 additions and 86 deletions

View file

@ -108,38 +108,36 @@
<h1>Primitive Class <code>Rotation</code></h1>
<p>Represents a degree-based 3D rotation.</p>
<p> All values are clamped to the range [0.0, 360.0].</p>
<p> All angle components are in degrees clamped to the range [0.0, 360.0].</p>
<h2><a href="#Members">Members</a></h2>
<table class="function_list">
<tr>
<td class="name" ><a href="#x">x</a></td>
<td class="summary">(float) X angle component.</td>
<td class="summary">(float) X angle component in degrees.</td>
</tr>
<tr>
<td class="name" ><a href="#y">y</a></td>
<td class="summary">(float) Y angle component.</td>
<td class="summary">(float) Y angle component in degrees.</td>
</tr>
<tr>
<td class="name" ><a href="#z">z</a></td>
<td class="summary">(float) Z angle component.</td>
<td class="summary">(float) Z angle component in degrees.</td>
</tr>
</table>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" ><a href="#Rotation">Rotation(x, y, z)</a></td>
<td class="summary">
</td>
<td class="summary">Create a Rotation object.</td>
</tr>
<tr>
<td class="name" ><a href="#Direction">Direction()</a></td>
<td class="summary">Converts rotation to a direction normal.</td>
<td class="summary">Get the normalized direction vector of this Rotation.</td>
</tr>
<tr>
<td class="name" ><a href="#__tostring">__tostring(rotation)</a></td>
<td class="name" ><a href="#__tostring">__tostring(rot)</a></td>
<td class="summary">
</td>
@ -158,7 +156,7 @@
<strong>x</strong>
</dt>
<dd>
(float) X angle component.
(float) X angle component in degrees.
@ -173,7 +171,7 @@
<strong>y</strong>
</dt>
<dd>
(float) Y angle component.
(float) Y angle component in degrees.
@ -188,7 +186,7 @@
<strong>z</strong>
</dt>
<dd>
(float) Z angle component.
(float) Z angle component in degrees.
@ -207,9 +205,7 @@
<strong>Rotation(x, y, z)</strong>
</dt>
<dd>
Create a Rotation object.
@ -217,15 +213,15 @@
<ul>
<li><span class="parameter">x</span>
<span class="types"><span class="type">float</span></span>
X angle component.
X angle component in degrees.
</li>
<li><span class="parameter">y</span>
<span class="types"><span class="type">float</span></span>
Y angle component.
Y angle component in degrees.
</li>
<li><span class="parameter">z</span>
<span class="types"><span class="type">float</span></span>
Z angle component.
Z angle component in degrees.
</li>
</ul>
@ -233,7 +229,7 @@
<ol>
<span class="types"><a class="type" href="../3 primitive classes/Rotation.html#">Rotation</a></span>
A Rotation.
A new Rotation object.
</ol>
@ -245,7 +241,7 @@
<strong>Direction()</strong>
</dt>
<dd>
Converts rotation to a direction normal.
Get the normalized direction vector of this Rotation.
@ -254,7 +250,7 @@
<ol>
<span class="types"><a class="type" href="../3 primitive classes/Vec3.html#">Vec3</a></span>
resulting normal calculated from this rotation.
Normalized direction vector.
</ol>
@ -263,7 +259,7 @@
</dd>
<dt>
<a name = "__tostring"></a>
<strong>__tostring(rotation)</strong>
<strong>__tostring(rot)</strong>
</dt>
<dd>
@ -274,9 +270,9 @@
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rotation</span>
<li><span class="parameter">rot</span>
<span class="types"><a class="type" href="../3 primitive classes/Rotation.html#">Rotation</a></span>
this Rotation.
This Rotation.
</li>
</ul>
@ -284,7 +280,7 @@
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
A string showing the X, Y, and Z angle components of the Rotation.
A string showing the X, Y, and Z angle components of this Rotation.
</ol>

View file

@ -870,7 +870,7 @@ SMOKE_EMITTER_BLACK
SMOKE_EMITTER
EARTHQUAKE
BUBBLES
WATERFALL_MIST
WATERFALLMIST
GUNSHELL
SHOTGUNSHELL
GUN_FLASH
@ -1114,6 +1114,7 @@ AIR_BAR_TEXTURE
DASH_BAR_TEXTURE
SFX_BAR_TEXTURE
SPEEDOMETER
WATERFALL
CUSTOM_BAR_GRAPHIC
CUSTOM_AMMO_GRAPHIC

View file

@ -24,7 +24,6 @@ static constexpr char ScriptReserved_AIObject[] = "AIObject";
static constexpr char ScriptReserved_Volume[] = "Volume";
static constexpr char ScriptReserved_Color[] = "Color";
static constexpr char ScriptReserved_DisplayString[] = "DisplayString";
static constexpr char ScriptReserved_Rotation[] = "Rotation";
static constexpr char ScriptReserved_LevelFunc[] = "LevelFunc";
static constexpr char ScriptReserved_Statistics[] = "Statistics";
@ -438,6 +437,7 @@ constexpr char ScriptReserved_Vec3Lerp[] = "Lerp";
constexpr char ScriptReserved_Vec3Normalize[] = "Normalize";
constexpr char ScriptReserved_Vec3Rotate[] = "Rotate";
// Rotation
// Rotation object
constexpr char ScriptReserved_Rotation[] = "Rotation";
constexpr char ScriptReserved_RotationDirection[] = "Direction";

View file

@ -9,37 +9,44 @@ using namespace TEN::Math;
namespace TEN::Scripting
{
/// Represents a degree-based 3D rotation.
// All values are clamped to the range [0.0, 360.0].
// All angle components are in degrees clamped to the range [0.0, 360.0].
// @tenprimitive Rotation
// @pragma nostrip
void Rotation::Register(sol::table& parent)
{
using ctors = sol::constructors<Rotation(float, float, float)>;
parent.new_usertype<Rotation>(ScriptReserved_Rotation,
using ctors = sol::constructors<
Rotation(float, float, float)>;
// Register type.
parent.new_usertype<Rotation>(
ScriptReserved_Rotation,
ctors(),
sol::call_constructor, ctors(),
sol::meta_function::to_string, &Rotation::ToString,
ScriptReserved_RotationDirection, &Rotation::Direction,
/// (float) X angle component.
/// (float) X angle component in degrees.
// @mem x
"x", &Rotation::x,
/// (float) Y angle component.
/// (float) Y angle component in degrees.
// @mem y
"y", &Rotation::y,
/// (float) Z angle component.
/// (float) Z angle component in degrees.
// @mem z
"z", &Rotation::z);
}
/// @tparam float x X angle component.
// @tparam float y Y angle component.
// @tparam float z Z angle component.
// @treturn Rotation A Rotation.
/// Create a Rotation object.
// @function Rotation
// @tparam float x X angle component in degrees.
// @tparam float y Y angle component in degrees.
// @tparam float z Z angle component in degrees.
// @treturn Rotation A new Rotation object.
Rotation::Rotation(float x, float y, float z)
{
this->x = x;
@ -47,13 +54,6 @@ namespace TEN::Scripting
this->z = z;
}
Rotation::Rotation(const EulerAngles& eulers)
{
x = TO_DEGREES(eulers.x);
y = TO_DEGREES(eulers.y);
z = TO_DEGREES(eulers.z);
}
Rotation::Rotation(const Vector3& vec)
{
x = vec.x;
@ -61,46 +61,25 @@ namespace TEN::Scripting
z = vec.z;
}
Rotation::Rotation(const Pose& pose)
Rotation::Rotation(const EulerAngles& eulers)
{
x = TO_DEGREES(pose.Orientation.x);
y = TO_DEGREES(pose.Orientation.y);
z = TO_DEGREES(pose.Orientation.z);
x = TO_DEGREES(eulers.x);
y = TO_DEGREES(eulers.y);
z = TO_DEGREES(eulers.z);
}
void Rotation::StoreInPHDPos(Pose& pose) const
{
pose.Orientation.x = ANGLE(x);
pose.Orientation.y = ANGLE(y);
pose.Orientation.z = ANGLE(z);
}
Rotation::operator Vector3() const
{
return Vector3(x, y, z);
};
/// Converts rotation to a direction normal.
// @treturn Vec3 resulting normal calculated from this rotation.
/// Get the normalized direction vector of this Rotation.
// @function Direction
// @treturn Vec3 Normalized direction vector.
Vec3 Rotation::Direction() const
{
// Convert degrees to radians.
float xRad = x * RADIAN;
float yRad = y * RADIAN;
// Calculate the direction vector.
float dirX = sin(yRad) * cos(xRad);
float dirY = -sin(xRad);
float dirZ = cos(yRad) * cos(xRad);
// Scale by the given distance.
return Vec3(dirX, dirY, dirZ);
auto eulers = ToEulerAngles();
return Vec3(eulers.ToDirection());
}
/// @tparam Rotation rotation this Rotation.
// @treturn string A string showing the X, Y, and Z angle components of the Rotation.
// @function __tostring
/// @function __tostring
// @tparam Rotation rot This Rotation.
// @treturn string A string showing the X, Y, and Z angle components of this Rotation.
std::string Rotation::ToString() const
{
return ("{ " + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + " }");
@ -110,4 +89,9 @@ namespace TEN::Scripting
{
return EulerAngles(ANGLE(x), ANGLE(y), ANGLE(z));
}
Rotation::operator Vector3() const
{
return Vector3(x, y, z);
};
}

View file

@ -1,6 +1,5 @@
#pragma once
#include "Math/Objects/EulerAngles.h"
#include "Scripting/Internal/TEN/Types/Vec3/Vec3.h"
class EulerAngles;
@ -15,26 +14,30 @@ namespace TEN::Scripting
public:
static void Register(sol::table& parent);
// Members
// Fields
float x = 0;
float y = 0;
float z = 0;
// Constructors
Rotation() = default;
Rotation(float x, float y, float z);
Rotation(const Vector3& vec);
Rotation(const EulerAngles& eulers);
Rotation(const Pose& pose);
Rotation(const Vector3& vector);
void StoreInPHDPos(Pose& pose) const;
// Utilities
// Converters
std::string ToString() const;
EulerAngles ToEulerAngles() const;
Vec3 Direction() const;
// Converters
std::string ToString() const;
EulerAngles ToEulerAngles() const;
// Operators
operator Vector3() const;
};
}

View file

@ -8,7 +8,7 @@ class Vec2
public:
static void Register(sol::table& parent);
// Members
// Fields
float x = 0;
float y = 0;
@ -21,6 +21,7 @@ public:
//Vec2(const Vector2i& vector);
// Utilities
Vec2 Normalize() const;
Vec2 Rotate(float rot) const;
Vec2 Lerp(const Vec2& vector, float alpha) const;