godot-interpolated-camera3d
godot-interpolated-camera3d copied to clipboard
C# Port Error: Quaternion is not normalized
So I was trying to port this code to C#, this is how it looks (It's really 1:1 conversion)
using Godot;
using System;
public partial class SmoothCam : Camera3D
{
[Export] public double translate_speed = 0.95;
[Export] public double rotate_speed = 0.95;
[Export] public double fov_speed = 0.95;
[Export] public double near_far_speed = 0.95;
[Export] public Node3D target;
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if(target == null) return;
var translate_factor = 1 - Mathf.Pow(1 - translate_speed, delta * 3.45233);
var rotate_factor = 1 - Mathf.Pow(1 - rotate_speed, delta * 3.45233);
var target_xform = target.GlobalTransform;
var local_transform_only_origin = new Transform3D(new(),GlobalTransform.Origin);
var local_transfrom_only_basis = new Transform3D(GlobalTransform.Basis,new());
local_transform_only_origin = local_transform_only_origin.InterpolateWith(target_xform, (float)translate_factor);
local_transfrom_only_basis = local_transfrom_only_basis.InterpolateWith(target_xform, (float)rotate_factor);
GlobalTransform = new(local_transfrom_only_basis.Basis,local_transform_only_origin.Origin);
if(target is Camera3D camera)
{
if(camera.Projection == Projection)
{
var near_far_factor = 1 - Mathf.Pow(1 - near_far_speed, delta * 3.45233);
var fov_factor = 1- Mathf.Pow(1 - fov_speed, delta * 3.45233);
var new_near = (float)Mathf.Lerp(Near,camera.Near,near_far_factor);
var new_far = (float)Mathf.Lerp(Far,camera.Far,near_far_factor);
if(camera.Projection == ProjectionType.Orthogonal)
{
var new_size = (float)Mathf.Lerp(Size,camera.Size,fov_factor);
SetOrthogonal(new_size,new_near,new_far);
}
else
{
var new_fov = (float)Mathf.Lerp(Fov,camera.Fov,fov_factor);
SetPerspective(new_fov,new_near,new_far);
}
}
}
}
}
But I always get an exception at the InterpolateWith at local_transform_only_origin; Quaternion is not normalized.
This is really confusing because, as said, it's been ported 1:1 to C# so there should be any problems, right?
I'm using Godot 4.0.3.stable.mono
Basis and Quaternions need special treatment and I don't know your types.
Basis and Quaternions need special treatment and I don't know your types.
There are no types defined by me, everything is from Godot and what do you mean with "special treatment"? Why does C# need it, but GDScript not?
Your c# isn’t typed. I suspect you are not converting basis to quaternion using the right methodOn Jun 24, 2023, at 3:03 AM, Night The Fox @.***> wrote:
Basis and Quaternions need special treatment and I don't know your types.
There are no types defined by me, everything is from Godot and what do you mean with "special treatment"? Why does C# need it, but GDScript not?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>