make field of view fixed regardless of view angle
This commit is contained in:
parent
80433d5ed6
commit
49cfc215a4
|
|
@ -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))
|
Affine3A::from_mat3_translation(rotation(-yaw, -pitch), vec3(0., 0., -distance))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn projection(fovy: f32, aspect: f32) -> Mat4 {
|
pub(crate) fn projection(fovy: f32, aspect: f32, base_distance: f32) -> Mat4 {
|
||||||
Mat4::perspective_rh(fovy, aspect, 1.0, 100.0)
|
Mat4::perspective_rh(fovy, aspect, 0.1 * base_distance, 10.0 * base_distance)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
17
src/lib.rs
17
src/lib.rs
|
|
@ -14,8 +14,8 @@ const BACKGROUND: Vec4 = vec4(0.00, 0.39, 0.52, 1.00);
|
||||||
pub struct RedrawArgs {
|
pub struct RedrawArgs {
|
||||||
pub cam_yaw: f32,
|
pub cam_yaw: f32,
|
||||||
pub cam_pitch: f32,
|
pub cam_pitch: f32,
|
||||||
pub cam_distance: f32,
|
pub cam_view_y: f32,
|
||||||
pub cam_fovy: f32,
|
pub cam_view_angle: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RedrawArgs {
|
impl Default for RedrawArgs {
|
||||||
|
|
@ -23,8 +23,8 @@ impl Default for RedrawArgs {
|
||||||
Self {
|
Self {
|
||||||
cam_yaw: 3. * std::f32::consts::FRAC_PI_4,
|
cam_yaw: 3. * std::f32::consts::FRAC_PI_4,
|
||||||
cam_pitch: std::f32::consts::FRAC_PI_6,
|
cam_pitch: std::f32::consts::FRAC_PI_6,
|
||||||
cam_distance: 3.,
|
cam_view_y: 80.,
|
||||||
cam_fovy: std::f32::consts::FRAC_PI_2,
|
cam_view_angle: std::f32::consts::FRAC_PI_2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,12 +109,9 @@ impl Core {
|
||||||
let h = size.height as f32;
|
let h = size.height as f32;
|
||||||
w / h
|
w / h
|
||||||
};
|
};
|
||||||
let view = Mat4::from(camera::view(
|
let distance = 0.5 * args.cam_view_y / (0.5 * args.cam_view_angle).tan();
|
||||||
args.cam_yaw,
|
let view = Mat4::from(camera::view(args.cam_yaw, args.cam_pitch, distance));
|
||||||
args.cam_pitch,
|
let proj = camera::projection(args.cam_view_angle, aspect, distance);
|
||||||
args.cam_distance,
|
|
||||||
));
|
|
||||||
let proj = camera::projection(args.cam_fovy, aspect);
|
|
||||||
self.mesh_pipeline.set_params(
|
self.mesh_pipeline.set_params(
|
||||||
&self.queue,
|
&self.queue,
|
||||||
render::mesh::Params {
|
render::mesh::Params {
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ void GearCutter::updateView() {
|
||||||
RedrawArgs args{
|
RedrawArgs args{
|
||||||
.cam_yaw = qDegreesToRadians((float)m_ui->camYaw->value()),
|
.cam_yaw = qDegreesToRadians((float)m_ui->camYaw->value()),
|
||||||
.cam_pitch = qDegreesToRadians((float)m_ui->camPitch->value()),
|
.cam_pitch = qDegreesToRadians((float)m_ui->camPitch->value()),
|
||||||
.cam_distance = (float)m_ui->camDistance->value(),
|
.cam_view_y = (float)m_ui->camFoVLin->value(),
|
||||||
.cam_fovy = qDegreesToRadians((float)m_ui->camFoV->value()),
|
.cam_view_angle = qDegreesToRadians((float)m_ui->camFoVAng->value()),
|
||||||
};
|
};
|
||||||
m_ui->viewport->setView(args);
|
m_ui->viewport->setView(args);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,12 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Distance</string>
|
<string>Linear size</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="camDistance">
|
<widget class="QDoubleSpinBox" name="camFoVLin">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<double>10.000000000000000</double>
|
<double>10.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -123,19 +123,19 @@
|
||||||
<enum>QAbstractSpinBox::StepType::AdaptiveDecimalStepType</enum>
|
<enum>QAbstractSpinBox::StepType::AdaptiveDecimalStepType</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<double>40.000000000000000</double>
|
<double>80.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Field of view</string>
|
<string>Angular size</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="camFoV">
|
<widget class="QDoubleSpinBox" name="camFoVAng">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> °</string>
|
<string> °</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -219,7 +219,7 @@
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>camDistance</sender>
|
<sender>camFoVLin</sender>
|
||||||
<signal>valueChanged(double)</signal>
|
<signal>valueChanged(double)</signal>
|
||||||
<receiver>MainWindow</receiver>
|
<receiver>MainWindow</receiver>
|
||||||
<slot>updateView()</slot>
|
<slot>updateView()</slot>
|
||||||
|
|
@ -235,7 +235,7 @@
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>camFoV</sender>
|
<sender>camFoVAng</sender>
|
||||||
<signal>valueChanged(double)</signal>
|
<signal>valueChanged(double)</signal>
|
||||||
<receiver>MainWindow</receiver>
|
<receiver>MainWindow</receiver>
|
||||||
<slot>updateView()</slot>
|
<slot>updateView()</slot>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user