Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c28c636b7 | |||
| 6185fbb449 | |||
| 41e747d9c2 | |||
| 906aecf30d | |||
| 344a604877 | |||
| 9f5e52277a | |||
| d0998119c8 |
9
.clang-format
Normal file
9
.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: LLVM
|
||||
UseTab: Always
|
||||
TabWidth: 4
|
||||
IndentWidth: 4
|
||||
AccessModifierOffset: -4
|
||||
IndentCaseLabels: false
|
||||
ColumnLimit: 0
|
||||
PointerAlignment: Left
|
||||
PackConstructorInitializers: Never
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.18)
|
||||
cmake_minimum_required(VERSION 3.18...4.2)
|
||||
|
||||
project(PROJECT-NAME VERSION 1.0.0 LANGUAGES CXX)
|
||||
|
||||
|
|
@ -7,12 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Gui Widgets)
|
||||
find_program(CARGO cargo REQUIRED)
|
||||
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo")
|
||||
|
||||
# KDE-specific
|
||||
find_package(ECM REQUIRED NO_MODULE)
|
||||
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
|
||||
find_package(KF6 REQUIRED COMPONENTS WidgetsAddons)
|
||||
set(CARGO_TARGET_DIR "${CMAKE_SOURCE_DIR}/target" CACHE PATH "Path to the Cargo target directory")
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
|
|
|
|||
11
format.sh
Executable file
11
format.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
find src/ ui/ \
|
||||
\( \
|
||||
-name '*.cxx' -o \
|
||||
-name '*.hxx' -o \
|
||||
-name '*.c' -o \
|
||||
-name '*.h' \
|
||||
\) \
|
||||
-print \
|
||||
-exec 'clang-format' '-i' '{}' \;
|
||||
|
|
@ -9,11 +9,11 @@ pub(crate) fn rotation(yaw: f32, pitch: f32) -> Mat3 {
|
|||
}
|
||||
|
||||
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 {
|
||||
Mat4::perspective_lh(fovy, aspect, 0.1, 10.0)
|
||||
Mat4::perspective_rh(fovy, aspect, 0.1, 10.0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -50,10 +50,10 @@ mod tests {
|
|||
fn test_view() {
|
||||
let mut ok = true;
|
||||
for (yaw, pitch, x1, y1, z1) in [
|
||||
(0.0, 0.0, [0., 0., 2.], [-1., 0., 3.], [0., 1., 3.]),
|
||||
(0.5, 0.0, [1., 0., 3.], [0., 0., 2.], [0., 1., 3.]),
|
||||
(0.0, 0.5, [0., -1., 3.], [-1., 0., 3.], [0., 0., 2.]),
|
||||
(0.5, 0.5, [1., 0., 3.], [0., -1., 3.], [0., 0., 2.]),
|
||||
(0.0, 0.0, [0., 0., -4.], [-1., 0., -3.], [0., 1., -3.]),
|
||||
(0.5, 0.0, [-1., 0., -3.], [0., 0., -2.], [0., 1., -3.]),
|
||||
(0.0, 0.5, [0., 1., -3.], [-1., 0., -3.], [0., 0., -2.]),
|
||||
(0.5, 0.5, [-1., 0., -3.], [0., -1., -3.], [0., 0., -2.]),
|
||||
] {
|
||||
let m = view(yaw * PI, pitch * PI, 3.);
|
||||
for (label, world, expected) in
|
||||
|
|
|
|||
10
src/lib.rs
10
src/lib.rs
|
|
@ -5,10 +5,11 @@ use glam::{Mat4, UVec2, Vec3, Vec4, vec3, vec4};
|
|||
mod camera;
|
||||
mod render;
|
||||
|
||||
const BACKGROUND: Vec4 = vec4(0.00, 0.39, 0.52, 1.00);
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct RedrawArgs {
|
||||
pub background: Vec4,
|
||||
pub cam_yaw: f32,
|
||||
pub cam_pitch: f32,
|
||||
pub cam_distance: f32,
|
||||
|
|
@ -18,8 +19,7 @@ pub struct RedrawArgs {
|
|||
impl Default for RedrawArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
background: vec4(0.25, 0.49, 0.93, 1.00),
|
||||
cam_yaw: std::f32::consts::FRAC_PI_4,
|
||||
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,
|
||||
|
|
@ -56,7 +56,7 @@ fn cube(a: f32, b: f32) -> render::mesh::CpuMeshIndexed {
|
|||
] {
|
||||
for m in [1., -1.] {
|
||||
let base = mesh.vertices.len() as u16;
|
||||
for offset in [m * v + u, -m * v + u, -m * v - u, m * v - u] {
|
||||
for offset in [m * v + u, m * v - u, -m * v - u, -m * v + u] {
|
||||
let vertex = render::mesh::Vertex {
|
||||
position: (m * w + offset),
|
||||
color: gray + color_level * m * w,
|
||||
|
|
@ -158,7 +158,7 @@ impl Core {
|
|||
depth_slice: None,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(color_to_wgpu(srgba_to_linear(args.background))),
|
||||
load: wgpu::LoadOp::Clear(color_to_wgpu(srgba_to_linear(BACKGROUND))),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
|
|
|
|||
|
|
@ -9,6 +9,5 @@ qt_add_executable(PROJECT-NAME
|
|||
)
|
||||
|
||||
target_link_libraries(PROJECT-NAME PRIVATE Qt6::Gui Qt6::Widgets)
|
||||
target_link_libraries(PROJECT-NAME PRIVATE KF6::WidgetsAddons)
|
||||
target_link_libraries(PROJECT-NAME PRIVATE PROJECT_NAME_impl)
|
||||
target_include_directories(PROJECT-NAME PRIVATE src)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,33 @@
|
|||
# build the Rust side as a static library
|
||||
set(impl_basename "${CARGO_TARGET_DIR}/release/libPROJECT_NAME_impl")
|
||||
|
||||
set(cargo_cmake_args)
|
||||
|
||||
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.27")
|
||||
list(APPEND cargo_cmake_args DEPENDS_EXPLICIT_ONLY)
|
||||
endif()
|
||||
|
||||
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.28")
|
||||
list(APPEND cargo_cmake_args JOB_SERVER_AWARE TRUE)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${impl_basename}.a
|
||||
COMMAND env CARGO_TARGET_DIR=${CARGO_TARGET_DIR} ${CARGO} build --release --package PROJECT-NAME-impl
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPFILE ${impl_basename}.d
|
||||
OUTPUT "${impl_basename}.a"
|
||||
COMMAND env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" ${CARGO} build --release --package PROJECT-NAME-impl
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
DEPFILE "${impl_basename}.d"
|
||||
USES_TERMINAL
|
||||
JOB_SERVER_AWARE
|
||||
DEPENDS_EXPLICIT_ONLY
|
||||
VERBATIM
|
||||
${cargo_cmake_args}
|
||||
)
|
||||
|
||||
# HACK ensure CMake *actually adds* the command above
|
||||
add_custom_target(build_impl
|
||||
DEPENDS ${impl_basename}.a
|
||||
DEPENDS "${impl_basename}.a"
|
||||
)
|
||||
|
||||
add_library(PROJECT_NAME_impl STATIC IMPORTED)
|
||||
|
||||
set_target_properties(PROJECT_NAME_impl PROPERTIES
|
||||
IMPORTED_LOCATION ${impl_basename}.a
|
||||
IMPORTED_LOCATION "${impl_basename}.a"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ namespace ffi {
|
|||
struct Core;
|
||||
|
||||
struct RedrawArgs {
|
||||
Vec4 background;
|
||||
float cam_yaw;
|
||||
float cam_pitch;
|
||||
float cam_distance;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,7 @@ PROJECTNAME::PROJECTNAME(QWidget* parent)
|
|||
PROJECTNAME::~PROJECTNAME() = default;
|
||||
|
||||
void PROJECTNAME::updateView() {
|
||||
const auto color = m_ui->inBackground->color();
|
||||
RedrawArgs args{
|
||||
.background = { color.redF(), color.greenF(), color.blueF(), 1.00 },
|
||||
.cam_yaw = qDegreesToRadians((float)m_ui->camYaw->value()),
|
||||
.cam_pitch = qDegreesToRadians((float)m_ui->camPitch->value()),
|
||||
.cam_distance = (float)m_ui->camDistance->value(),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
<double>5.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>45.000000000000000</double>
|
||||
<double>135.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -156,24 +156,6 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Background color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="KColorCombo" name="inBackground">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>99</green>
|
||||
<blue>133</blue>
|
||||
</color>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
@ -192,11 +174,6 @@
|
|||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KColorCombo</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>kcolorcombo.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Viewport</class>
|
||||
<extends>QWidget</extends>
|
||||
|
|
@ -206,22 +183,6 @@
|
|||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>inBackground</sender>
|
||||
<signal>highlighted(QColor)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>1531</x>
|
||||
<y>115</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>799</x>
|
||||
<y>599</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>camYaw</sender>
|
||||
<signal>valueChanged(double)</signal>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user