-
-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avm2: Make PerspectiveProjection.focalLength more precise #19748
base: master
Are you sure you want to change the base?
Conversation
ebd8291
to
5daa9d6
Compare
The previous calculation for focalLength was correct in semantics, but the difference from FP was not tiny. The calculation involves trigonometric functions in floating point number and this semantically-equivalent refactoring makes the result of focalLength calculation closer to that of FP.
Move approximation logic from ActionScript to Ruffle test framework
@@ -40,7 +40,7 @@ pub fn get_focal_length<'gc>( | |||
let fov = this.get_slot(pp_slots::FOV).coerce_to_number(activation)?; | |||
|
|||
let width = get_width(activation, this); | |||
let focal_length = (width / 2.0) / f64::tan(fov / 2.0 * DEG2RAD); | |||
let focal_length = (width / 2.0) as f32 * f64::tan((PI - fov * DEG2RAD) / 2.0) as f32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After many trials and observations, I found this code. It doesn't seem to be perfect yet (for edge values like 1e-10), though.
1 / tan x
=cot x
=tan (pi/2 - x)
_ as f32 * f32::tan(_)
is not good. This produces better result.
'fieldOfView = ([0-9.]+)', | ||
'FOV [0-9]+ ([0-9.]+)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field of view still has some errors.
var pp: PerspectiveProjection = new PerspectiveProjection();
pp.fieldOfView = 179.99999;
trace(pp.fieldOfView);
I found the code above gives 179.99999000000003
, so even pp.fieldOfView
is not a simple storage variable.
Small follow up to #19532
The previous
focalLength
getter had a certain level of difference. This change reduces the difference from Flash Player.Also, I found Ruffle
test.toml
has the configuration section for number approximations, so move the logic fromTest.as
.