mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
arcball implementation (a bit rough around the edges)
This commit is contained in:
1 parent
e2671e4380
commit
22a48dba60
9 files changed
+244
-27
No files matched your search
Generated
+119
@@ -52,6 +52,14 @@ dependencies = [
|
||||
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arcball"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.1"
|
||||
@@ -67,6 +75,11 @@ dependencies = [
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.0"
|
||||
@@ -185,6 +198,16 @@ dependencies = [
|
||||
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cgmath"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "0.28.1"
|
||||
@@ -1268,6 +1291,24 @@ dependencies = [
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.3"
|
||||
@@ -1280,6 +1321,15 @@ dependencies = [
|
||||
"rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
@@ -1310,6 +1360,14 @@ dependencies = [
|
||||
"getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
@@ -1318,6 +1376,54 @@ dependencies = [
|
||||
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_isaac"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_jitter"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_os"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
version = "0.3.3"
|
||||
@@ -1521,6 +1627,8 @@ dependencies = [
|
||||
name = "storyteller"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"arcball 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"genmesh 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1843,8 +1951,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94"
|
||||
"checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
|
||||
"checksum arcball 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75e3433ec37e64e887a11f4f1a98599780ad766070f33c68bda46f8196359aae"
|
||||
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||
"checksum backtrace 0.3.46 (registry+https://github.com/rust-lang/crates.io-index)" = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e"
|
||||
"checksum backtrace-sys 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "7de8aba10a69c8e8d7622c5710229485ec32e9d55fdad160ea559c086fdcd118"
|
||||
@@ -1859,6 +1969,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum cgl 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff"
|
||||
"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c"
|
||||
"checksum cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "283944cdecc44bf0b8dd010ec9af888d3b4f142844fdbe026c20ef68148d6fe7"
|
||||
"checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853"
|
||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||
"checksum clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7"
|
||||
@@ -1982,12 +2093,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
||||
"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
|
||||
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
|
||||
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
|
||||
"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
"checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
|
||||
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
|
||||
"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
|
||||
"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
|
||||
"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
|
||||
"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
|
||||
"checksum raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211"
|
||||
"checksum rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098"
|
||||
"checksum rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9"
|
||||
|
||||
@@ -9,6 +9,8 @@ name = "camera"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
arcball = "1.0.0" # camera
|
||||
cgmath = "0.17.0" # for arcball, but probably good for matrices, vecs, etc.
|
||||
clipboard = "0.5" # to support imgui...
|
||||
enum_primitive = "0.1.1" # c wrapper ergonomics
|
||||
genmesh = "0.6.0" # for glium example
|
||||
|
||||
+7
-2
@@ -19,7 +19,7 @@ use glutin::ContextBuilder;
|
||||
use std::mem::size_of;
|
||||
use std::ptr::null;
|
||||
//use glium::framebuffer::ColorAttachment::Texture;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use sensor_control::CaptureProvider;
|
||||
use point_cloud;
|
||||
use point_cloud::gpu_point_cloud_converter::GpuPointCloudConverter;
|
||||
@@ -27,6 +27,9 @@ use point_cloud::point_cloud_renderer::PointCloudRenderer;
|
||||
use point_cloud::point_cloud_visualiser::{PointCloudVisualizer, PointCloudVisualizerError, ColorizationStrategy};
|
||||
use point_cloud::viewer_image::ViewerImage;
|
||||
use opengl::debug::enable_opengl_debugging;
|
||||
use arcball::ArcballCamera;
|
||||
use cgmath::Vector2;
|
||||
use cgmath::Vector3;
|
||||
|
||||
//use shader::Shader;
|
||||
|
||||
@@ -127,7 +130,9 @@ pub fn run(capture_provider: Arc<CaptureProvider>, calibration_data: k4a_sys::k4
|
||||
let mut visualizer = PointCloudVisualizer::new(
|
||||
true,
|
||||
ColorizationStrategy::Color,
|
||||
calibration_data
|
||||
calibration_data,
|
||||
Arc::new(Mutex::new(ArcballCamera::new(Vector3::new(0.0, 0.0, 0.0), 1.0,
|
||||
[1280.0, 720.0])))
|
||||
);
|
||||
|
||||
// TODO - constructed in PointCloudWindow.
|
||||
|
||||
+66
-2
@@ -6,6 +6,7 @@ use glutin::ContextBuilder;
|
||||
use glutin::event::{Event, WindowEvent};
|
||||
use glutin::event_loop::{ControlFlow, EventLoop};
|
||||
use glutin::window::WindowBuilder;
|
||||
use imgui::MouseButton;
|
||||
use imgui::*;
|
||||
use imgui::Image;
|
||||
use imgui_support;
|
||||
@@ -24,16 +25,28 @@ use std::fs::{File, OpenOptions};
|
||||
use std::io::{Write, Read};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex, PoisonError};
|
||||
use std::time::{Instant, Duration};
|
||||
use cgmath::Vector3;
|
||||
use cgmath::Vector2;
|
||||
use webcam::{WebcamWriter};
|
||||
use std::error::Error;
|
||||
use arcball::ArcballCamera;
|
||||
|
||||
pub fn run(capture_provider: Arc<CaptureProvider>, calibration_data: k4a_sys::k4a_calibration_t) {
|
||||
|
||||
let mut webcam_writer = WebcamWriter::open_file("/dev/video0", 1280, 720, 3)
|
||||
.expect("should be able to create webcamwriter");
|
||||
|
||||
let mut arcball_camera = Arc::new(
|
||||
Mutex::new(
|
||||
ArcballCamera::new(Vector3::new(0.0, 0.0, 0.0), 1.0, [1280.0, 720.0])));
|
||||
//[display_dims.0 as f32, display_dims.1 as f32]);
|
||||
|
||||
// Track if left/right mouse is down
|
||||
let mut mouse_pressed = [false, false];
|
||||
let mut prev_mouse = Vector2::new(0.0, 0.0);
|
||||
|
||||
let sdl_context = sdl2::init().unwrap();
|
||||
let video = sdl_context.video().unwrap();
|
||||
|
||||
@@ -71,7 +84,8 @@ pub fn run(capture_provider: Arc<CaptureProvider>, calibration_data: k4a_sys::k4
|
||||
let mut visualizer = PointCloudVisualizer::new(
|
||||
true,
|
||||
colorization_strategy,
|
||||
calibration_data
|
||||
calibration_data,
|
||||
arcball_camera.clone(),
|
||||
);
|
||||
|
||||
//rebinder.restore();
|
||||
@@ -116,6 +130,56 @@ pub fn run(capture_provider: Arc<CaptureProvider>, calibration_data: k4a_sys::k4
|
||||
Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
break 'running
|
||||
},
|
||||
Event::MouseButtonDown { timestamp, window_id, which, mouse_btn, clicks, x, y } => {
|
||||
//println!("Mouse down");
|
||||
match mouse_btn {
|
||||
sdl2::mouse::MouseButton::Left => mouse_pressed[0] = true,
|
||||
sdl2::mouse::MouseButton::Right => mouse_pressed[1] = true,
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
Event::MouseButtonUp { timestamp, window_id, which, mouse_btn, clicks, x, y } => {
|
||||
//println!("Mouse up");
|
||||
match mouse_btn {
|
||||
sdl2::mouse::MouseButton::Left => mouse_pressed[0] = false,
|
||||
sdl2::mouse::MouseButton::Right => mouse_pressed[1] = false,
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
Event::MouseMotion { timestamp, window_id, which, mousestate, x, y, xrel, yrel } => {
|
||||
//println!("XY Mouse: {},{}", x, y);
|
||||
if mouse_pressed[0] {
|
||||
match arcball_camera.lock() {
|
||||
Ok(mut arcball) => {
|
||||
arcball.rotate(
|
||||
Vector2::new(prev_mouse.x as f32, prev_mouse.y as f32),
|
||||
Vector2::new(x as f32, y as f32),
|
||||
);
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
} else if mouse_pressed[1] {
|
||||
let mouse_delta = Vector2::new(
|
||||
(x as f32 - prev_mouse.x as f32),
|
||||
(prev_mouse.y as f32 - y as f32), // Invert scrolling
|
||||
);
|
||||
match arcball_camera.lock() {
|
||||
Ok(mut arcball) => {
|
||||
arcball.pan(mouse_delta, 0.16);
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
}
|
||||
prev_mouse = Vector2::new(x as f32, y as f32);
|
||||
},
|
||||
Event::MouseWheel { timestamp, window_id, which, x, y, direction } => {
|
||||
match arcball_camera.lock() {
|
||||
Ok(mut arcball) => {
|
||||
arcball.zoom(y as f32, 0.16);
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@
|
||||
#[macro_use] extern crate enum_primitive;
|
||||
#[macro_use] extern crate glium;
|
||||
#[macro_use] extern crate imgui;
|
||||
extern crate arcball;
|
||||
extern crate cgmath;
|
||||
extern crate clipboard;
|
||||
extern crate genmesh;
|
||||
extern crate gl;
|
||||
@@ -17,13 +19,13 @@ extern crate imgui_sdl2;
|
||||
extern crate imgui_winit_support;
|
||||
extern crate k4a_sys;
|
||||
extern crate libc;
|
||||
extern crate memmap2;
|
||||
extern crate mmap;
|
||||
extern crate obj;
|
||||
extern crate opencv;
|
||||
extern crate rand;
|
||||
extern crate sdl2;
|
||||
extern crate winit;
|
||||
extern crate memmap2;
|
||||
extern crate mmap;
|
||||
|
||||
use std::borrow::BorrowMut;
|
||||
use std::ffi::{c_void, CStr, CString};
|
||||
|
||||
@@ -103,12 +103,12 @@ void main()
|
||||
|
||||
// Distance Threshold
|
||||
// TODO: Make configurable.
|
||||
if (vertexPosition.z > 1.5) {
|
||||
/*if (vertexPosition.z > 1.5) {
|
||||
alpha = 0.0f;
|
||||
vertexPosition.x = 0.0;
|
||||
vertexPosition.y = 0.0;
|
||||
vertexPosition.z = 0.0;
|
||||
}
|
||||
}*/
|
||||
|
||||
imageStore(destTex, pixel, vec4(vertexPosition, alpha));
|
||||
}
|
||||
|
||||
@@ -99,8 +99,11 @@ void main()
|
||||
//vertexPosition.y *= 2.0 + 10.0;
|
||||
//vertexPosition.z *= 2.0;
|
||||
|
||||
vertexPosition.x -= 2.0;
|
||||
vertexPosition.y -= 2.0;
|
||||
|
||||
if (view[0][0] > 0.5) {
|
||||
vertexPosition.x -= 2.0;
|
||||
vertexPosition.y -= 2.0;
|
||||
}
|
||||
|
||||
gl_Position = projection * view * vec4(vertexPosition, 1);
|
||||
|
||||
@@ -203,6 +206,7 @@ pub struct PointCloudRenderer {
|
||||
// TODO: better matrix types
|
||||
view: [f32; 16],
|
||||
projection: [f32; 16],
|
||||
proj_view: [[f32; 4]; 4],
|
||||
|
||||
/// Renderer setting: size of the rendered points
|
||||
point_size: u8,
|
||||
@@ -330,9 +334,17 @@ impl PointCloudRenderer {
|
||||
println!("Uniform enable shading location - view: {:?}", enable_shading_index);
|
||||
println!("Uniform point cloud texture location - view: {:?}", point_cloud_texture_index);
|
||||
|
||||
let initial_view = [
|
||||
[-1.0, 0.0, 8.74228e-08, 0.0],
|
||||
[0.0, 1.0, 0.0, 0.0],
|
||||
[-8.74228e-08, 0.0, -1.0, 0.0],
|
||||
[2.62268e-07, 1.0, -5.0, 1.0],
|
||||
];
|
||||
|
||||
Self {
|
||||
view: initial_view_matrix_4x4(),
|
||||
projection: initial_projection_matrix_4x4(),
|
||||
proj_view: initial_view,
|
||||
shader_program_id: program_id,
|
||||
vertex_shader_id,
|
||||
fragment_shader_id,
|
||||
@@ -348,13 +360,12 @@ impl PointCloudRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO need matrix maths
|
||||
pub fn update_view_projection(&mut self) {
|
||||
// TODO - matrix math
|
||||
// void PointCloudRenderer::UpdateViewProjection(mat4x4 view, mat4x4 projection)
|
||||
//mat4x4_dup(m_view, view);
|
||||
//mat4x4_dup(m_projection, projection);
|
||||
//unimplemented!();
|
||||
///
|
||||
/// Update the view matrix
|
||||
///
|
||||
pub fn update_view_projection(&mut self, proj_view: [[f32; 4]; 4]) {
|
||||
println!("Matrix: {:?}", proj_view);
|
||||
self.proj_view = proj_view;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -371,11 +382,11 @@ impl PointCloudRenderer {
|
||||
|
||||
//println!("updating point_cloud_texture: {}", point_cloud_texture.id());
|
||||
|
||||
println!("update_point_clouds() color_image: {}x{}, bytes={}, (format={:?})",
|
||||
/*println!("update_point_clouds() color_image: {}x{}, bytes={}, (format={:?})",
|
||||
color_image.get_width_pixels(),
|
||||
color_image.get_height_pixels(),
|
||||
color_image.get_size(),
|
||||
color_image.get_format());
|
||||
color_image.get_format());*/
|
||||
|
||||
unsafe {
|
||||
//println!("Binding VAO vertex_array_object id = {}", self.vertex_array_object.id());
|
||||
@@ -489,9 +500,13 @@ impl PointCloudRenderer {
|
||||
gl::UseProgram(self.shader_program_id);
|
||||
|
||||
// Update view/projection matrices in shader
|
||||
gl::UniformMatrix4fv(self.view_index, 1, gl::FALSE, self.view.as_ptr());
|
||||
//gl::UniformMatrix4fv(self.view_index, 1, gl::FALSE, self.view.as_ptr());
|
||||
gl::UniformMatrix4fv(self.projection_index, 1, gl::FALSE, self.projection.as_ptr());
|
||||
|
||||
let typed_view = self.proj_view.as_ptr() as *const GLfloat;
|
||||
gl::UniformMatrix4fv(self.view_index, 1, gl::FALSE, typed_view);
|
||||
//gl::UniformMatrix4fv(self.projection_index, 1, gl::FALSE, typed_view);
|
||||
|
||||
// Update render settings in shader
|
||||
let enable_shading = if self.enable_shading { 1 } else { 0 };
|
||||
let enable_shading = 1; // TODO FIXME FIXME FIXME
|
||||
@@ -502,7 +517,7 @@ impl PointCloudRenderer {
|
||||
gl::BindVertexArray(self.vertex_array_object.id());
|
||||
//let size = self.vertex_array_size_bytes / size_of::<BgraPixel>() as i32 / 3; // TODO: 1/3rd of information to draw
|
||||
let size = self.vertex_array_size_bytes / size_of::<BgraPixel>() as i32;
|
||||
println!("Draw size: {} (vertex array size bytes: {})", size, self.vertex_array_size_bytes);
|
||||
//println!("Draw size: {} (vertex array size bytes: {})", size, self.vertex_array_size_bytes);
|
||||
gl::DrawArrays(gl::POINTS, 0, size);
|
||||
|
||||
gl::BindVertexArray(0);
|
||||
|
||||
@@ -18,6 +18,9 @@ use std::mem::size_of;
|
||||
use conversion::k4a_image_to_rust_image_for_debug;
|
||||
use std::path::Path;
|
||||
use point_cloud::util::{ValueRange, get_depth_mode_range, colorize_depth_blue_to_red};
|
||||
use arcball::ArcballCamera;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex, PoisonError, MutexGuard};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, PointCloudVisualizerError>;
|
||||
|
||||
@@ -90,9 +93,7 @@ pub enum ColorizationStrategy {
|
||||
}
|
||||
|
||||
pub struct PointCloudVisualizer {
|
||||
// TODO: ViewControl m_viewControl;
|
||||
// TODO: linmath::mat4x4 m_projection{};
|
||||
// TODO: linmath::mat4x4 m_view{};
|
||||
arcball_camera: Arc<Mutex<ArcballCamera<f32>>>,
|
||||
|
||||
m_dimensions_width : i32,
|
||||
m_dimensions_height : i32,
|
||||
@@ -148,7 +149,8 @@ impl PointCloudVisualizer {
|
||||
///
|
||||
pub fn new(enable_color_point_cloud: bool,
|
||||
initial_colorization_strategy: ColorizationStrategy,
|
||||
calibration_data: k4a_sys::k4a_calibration_t) -> Self
|
||||
calibration_data: k4a_sys::k4a_calibration_t,
|
||||
arcball_camera: Arc<Mutex<ArcballCamera<f32>>>) -> Self
|
||||
{
|
||||
// Resolution of the point cloud texture
|
||||
// constexpr ImageDimensions PointCloudVisualizerTextureDimensions = { 1280, 1152 };
|
||||
@@ -177,6 +179,7 @@ impl PointCloudVisualizer {
|
||||
.expect("Should be in correct depth sensor mode.");
|
||||
|
||||
let mut visualizer = Self {
|
||||
arcball_camera,
|
||||
m_dimensions_width: width,
|
||||
m_dimensions_height: height,
|
||||
enable_color_point_cloud,
|
||||
@@ -260,8 +263,14 @@ impl PointCloudVisualizer {
|
||||
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
// TODO: View matrix maths
|
||||
self.point_cloud_renderer.update_view_projection();
|
||||
match self.arcball_camera.lock() {
|
||||
Ok(arcball) => {
|
||||
let proj_view: [[f32; 4]; 4] = (arcball.get_mat4()).into();
|
||||
// TODO: View matrix maths
|
||||
self.point_cloud_renderer.update_view_projection(proj_view);
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
|
||||
let render_status = self.point_cloud_renderer.render();
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ impl WebcamWriter {
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: Make it easy to update for new textures of different sizes (dynamic buffer resize)
|
||||
/// Grab the current texture held by `texture_id` and immediately write it to file.
|
||||
pub fn write_current_frame_to_file(&mut self, texture_id: GLuint) -> Result<(), WebcamError> {
|
||||
let mut typed_buffer = self.buffer.as_mut_ptr() as *mut c_void;
|
||||
|
||||
Reference in new issue
Block a user