37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using Godot;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Rokojori
|
|
{
|
|
public class Cameras
|
|
{
|
|
public static float ComputeCameraFrameFittingDistance( Camera3D camera, float radius )
|
|
{
|
|
var fovRadians = Mathf.DegToRad( camera.Fov );
|
|
return ( radius * 2 ) / Mathf.Tan( fovRadians / 2.0f );
|
|
}
|
|
|
|
public static float ComputeCameraFrameFittingDistance( float fovDegrees, float radius )
|
|
{
|
|
var fovRadians = Mathf.DegToRad( fovDegrees );
|
|
return ( radius * 2 ) / Mathf.Tan( fovRadians / 2.0f );
|
|
}
|
|
|
|
public static float ComputeCameraFittingScale( float fovDegrees, float distance )
|
|
{
|
|
var fovRadians = Mathf.DegToRad( fovDegrees );
|
|
return distance / ( 0.5f / Mathf.Tan( fovRadians / 2.0f ) );
|
|
}
|
|
|
|
public static float ComputeFOVForBillboard( float fovDegrees, float radius, float placingDistance )
|
|
{
|
|
var fovRadians = Mathf.DegToRad( fovDegrees );
|
|
var d = ( radius * Mathf.Tan( fovRadians / 2f ) ) / placingDistance;
|
|
var rads = 2f * Mathf.Atan( d );
|
|
|
|
return Mathf.RadToDeg( rads );
|
|
}
|
|
|
|
}
|
|
} |