make field of view fixed regardless of view angle

This commit is contained in:
numzero 2026-10-18 00:43:53 +03:00
parent 80433d5ed6
commit 49cfc215a4
4 changed files with 18 additions and 21 deletions

View File

@ -12,8 +12,8 @@ pub(crate) fn view(yaw: f32, pitch: f32, distance: f32) -> Affine3A {
Affine3A::from_mat3_translation(rotation(-yaw, -pitch), vec3(0., 0., -distance))
}
pub(crate) fn projection(fovy: f32, aspect: f32) -> Mat4 {
Mat4::perspective_rh(fovy, aspect, 1.0, 100.0)
pub(crate) fn projection(fovy: f32, aspect: f32, base_distance: f32) -> Mat4 {
Mat4::perspective_rh(fovy, aspect, 0.1 * base_distance, 10.0 * base_distance)
}
#[cfg(test)]

View File

@ -14,8 +14,8 @@ const BACKGROUND: Vec4 = vec4(0.00, 0.39, 0.52, 1.00);
pub struct RedrawArgs {
pub cam_yaw: f32,
pub cam_pitch: f32,
pub cam_distance: f32,
pub cam_fovy: f32,
pub cam_view_y: f32,
pub cam_view_angle: f32,
}
impl Default for RedrawArgs {
@ -23,8 +23,8 @@ impl Default for RedrawArgs {
Self {
cam_yaw: 3. * std::f32::consts::FRAC_PI_4,
cam_pitch: std::f32::consts::FRAC_PI_6,
cam_distance: 3.,
cam_fovy: std::f32::consts::FRAC_PI_2,
cam_view_y: 80.,
cam_view_angle: std::f32::consts::FRAC_PI_2,
}
}
}
@ -109,12 +109,9 @@ impl Core {
let h = size.height as f32;
w / h
};
let view = Mat4::from(camera::view(
args.cam_yaw,
args.cam_pitch,
args.cam_distance,
));
let proj = camera::projection(args.cam_fovy, aspect);
let distance = 0.5 * args.cam_view_y / (0.5 * args.cam_view_angle).tan();
let view = Mat4::from(camera::view(args.cam_yaw, args.cam_pitch, distance));
let proj = camera::projection(args.cam_view_angle, aspect, distance);
self.mesh_pipeline.set_params(
&self.queue,
render::mesh::Params {

View File

@ -15,8 +15,8 @@ void GearCutter::updateView() {
RedrawArgs args{
.cam_yaw = qDegreesToRadians((float)m_ui->camYaw->value()),
.cam_pitch = qDegreesToRadians((float)m_ui->camPitch->value()),
.cam_distance = (float)m_ui->camDistance->value(),
.cam_fovy = qDegreesToRadians((float)m_ui->camFoV->value()),
.cam_view_y = (float)m_ui->camFoVLin->value(),
.cam_view_angle = qDegreesToRadians((float)m_ui->camFoVAng->value()),
};
m_ui->viewport->setView(args);
}

View File

@ -107,12 +107,12 @@
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Distance</string>
<string>Linear size</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="camDistance">
<widget class="QDoubleSpinBox" name="camFoVLin">
<property name="minimum">
<double>10.000000000000000</double>
</property>
@ -123,19 +123,19 @@
<enum>QAbstractSpinBox::StepType::AdaptiveDecimalStepType</enum>
</property>
<property name="value">
<double>40.000000000000000</double>
<double>80.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Field of view</string>
<string>Angular size</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="camFoV">
<widget class="QDoubleSpinBox" name="camFoVAng">
<property name="suffix">
<string> °</string>
</property>
@ -219,7 +219,7 @@
</hints>
</connection>
<connection>
<sender>camDistance</sender>
<sender>camFoVLin</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
@ -235,7 +235,7 @@
</hints>
</connection>
<connection>
<sender>camFoV</sender>
<sender>camFoVAng</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>