68 lines
1.4 KiB
C#
68 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
using System.Text;
|
|
using System;
|
|
|
|
namespace Rokojori
|
|
{
|
|
public class Math3D
|
|
{
|
|
public static Vector3 LerpUnclamped( Vector3 a, Vector3 b, float amount )
|
|
{
|
|
return a + amount * ( b - a );
|
|
}
|
|
|
|
public static Vector3 LerpClamped( Vector3 a, Vector3 b, float amount )
|
|
{
|
|
return LerpUnclamped( a, b, MathX.Clamp01( amount ) );
|
|
}
|
|
|
|
public static Quaternion GetGlobalRotation( Node3D node )
|
|
{
|
|
return node.GlobalBasis.GetRotationQuaternion();
|
|
}
|
|
|
|
public static void SetGlobalRotation( Node3D node, Quaternion quaternion )
|
|
{
|
|
var forward = quaternion * Vector3.Forward;
|
|
var up = quaternion * Vector3.Up;
|
|
|
|
node.LookAt( node.GlobalPosition + forward, up );
|
|
}
|
|
|
|
public static Vector3 GetGlobalForward( Node3D node )
|
|
{
|
|
return -node.GlobalBasis.Z;
|
|
}
|
|
|
|
public static Vector3 GetGlobalUp( Node3D node )
|
|
{
|
|
return node.GlobalBasis.Y;
|
|
}
|
|
|
|
public static Vector3 GetGlobalRight( Node3D node )
|
|
{
|
|
return node.GlobalBasis.X;
|
|
}
|
|
|
|
public static Vector3 GetYPlaneForward( Node3D node )
|
|
{
|
|
var forward = GetGlobalForward( node );
|
|
|
|
forward.Y = 0;
|
|
|
|
return forward.Normalized();
|
|
}
|
|
|
|
public static Vector3 GetYPlaneRight( Node3D node )
|
|
{
|
|
var right = GetGlobalRight( node );
|
|
|
|
right.Y = 0;
|
|
|
|
return right.Normalized();
|
|
}
|
|
}
|
|
|
|
} |