feat(ship-3d): look-at dinàmic, naus alineades amb el path (punta+cul)

This commit is contained in:
2026-05-22 09:52:14 +02:00
parent b45390a8d1
commit 54702a5afe
3 changed files with 65 additions and 17 deletions
+15 -10
View File
@@ -18,17 +18,12 @@ namespace Graphics {
.z = local.z * transform.scale,
};
// 2. Rotació Y (yaw): X i Z.
const float CY = std::cos(transform.rotation_euler.y);
const float SY = std::sin(transform.rotation_euler.y);
{
const float NX = (v.x * CY) + (v.z * SY);
const float NZ = (-v.x * SY) + (v.z * CY);
v.x = NX;
v.z = NZ;
}
// Ordre X → Y → Z: amb aquest ordre, una rotació pitch+yaw pot dur el
// vector local (0,-1,0) a qualsevol direcció mundial — necessari perquè
// les naus calculen pitch+yaw look-at per alinear-se amb el seu path.
// L'ordre invers (Y→X) no permet X arbitrari en vectors sobre l'eix Y.
// 3. Rotació X (pitch): Y i Z.
// 2. Rotació X (pitch): Y i Z.
const float CX = std::cos(transform.rotation_euler.x);
const float SX = std::sin(transform.rotation_euler.x);
{
@@ -38,6 +33,16 @@ namespace Graphics {
v.z = NZ;
}
// 3. Rotació Y (yaw): X i Z.
const float CY = std::cos(transform.rotation_euler.y);
const float SY = std::sin(transform.rotation_euler.y);
{
const float NX = (v.x * CY) + (v.z * SY);
const float NZ = (-v.x * SY) + (v.z * CY);
v.x = NX;
v.z = NZ;
}
// 4. Rotació Z (roll): X i Y.
const float CZ = std::cos(transform.rotation_euler.z);
const float SZ = std::sin(transform.rotation_euler.z);