Skip to content

Commit

Permalink
Fix cube continuity and equirectangular projection.
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAreAllTheseTaken committed Jan 26, 2024
1 parent f43f33a commit ffbdef7
Show file tree
Hide file tree
Showing 5 changed files with 493 additions and 23 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ static-array = { version = "0.5.0", features = ["rayon"] }
pixels = "0.13.0"
winit = { version = "0.29.10", default_features = false, features = ["rwh_05", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] }
rand = "0.8.5"
approx = "0.5.1"

12 changes: 6 additions & 6 deletions examples/continuity_test_cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{error::Error, f64::consts::PI};

use pixels::{SurfaceTexture, Pixels};
use surface_grid::{sphere::{CubeSphereGrid, CubeSpherePoint, SpherePoint}, SurfaceGrid};
use surface_grid::{sphere::{CubeSphereGrid, CubeSpherePoint, SpherePoint}, SurfaceGrid, GridPoint};
use winit::{event_loop::EventLoop, window::WindowBuilder, dpi::{LogicalSize, PhysicalSize}, event::{Event, WindowEvent}};

// The initial window size.
Expand All @@ -30,7 +30,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut pixels = Pixels::new(window_size.width, window_size.height, surface_texture)?;

let buffer: CubeSphereGrid<(f64, f64), 20> = CubeSphereGrid::from_fn(|point| (point.latitude(), point.longitude()));
let buffer: CubeSphereGrid<_, 200> = CubeSphereGrid::from_fn(|point| point.position(1.0));

event_loop.run(move |event, target| {
match event {
Expand Down Expand Up @@ -65,11 +65,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let latitude = (y as f64 / size.height as f64) * PI - PI / 2.0;
let longitude = (x as f64 / size.width as f64) * PI * 2.0;

// Gets the value stored at the latitude and longitude calculated.
let (lat, long) = buffer[CubeSpherePoint::from_geographic(latitude, longitude)];
let (x, y, z) = buffer[CubeSpherePoint::from_geographic(latitude, longitude)];

frame[i] = ((lat + PI / 2.0) / PI * 255.0) as u8;
frame[i + 2] = (long / (2.0 * PI) * 255.0) as u8;
frame[i + 0] = ((x + 1.0) / 2.0 * 255.0) as u8;
frame[i + 1] = ((y + 1.0) / 2.0 * 255.0) as u8;
frame[i + 2] = ((z + 1.0) / 2.0 * 255.0) as u8;
frame[i + 3] = 255;
}
}
Expand Down
11 changes: 6 additions & 5 deletions examples/continuity_test_rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{error::Error, f64::consts::PI};

use pixels::{SurfaceTexture, Pixels};
use surface_grid::{sphere::{RectangleSphereGrid, RectangleSpherePoint, SpherePoint}, SurfaceGrid};
use surface_grid::{sphere::{RectangleSphereGrid, RectangleSpherePoint, SpherePoint}, SurfaceGrid, GridPoint};
use winit::{event_loop::EventLoop, window::WindowBuilder, dpi::{LogicalSize, PhysicalSize}, event::{Event, WindowEvent}};

// The initial window size.
Expand All @@ -30,7 +30,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut pixels = Pixels::new(window_size.width, window_size.height, surface_texture)?;

let buffer: RectangleSphereGrid<(f64, f64), 50, 25> = RectangleSphereGrid::from_fn(|point| (point.latitude(), point.longitude()));
let buffer: RectangleSphereGrid<_, 400, 200> = RectangleSphereGrid::from_fn(|point| (point.position(1.0)));

event_loop.run(move |event, target| {
match event {
Expand Down Expand Up @@ -66,10 +66,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let longitude = (x as f64 / size.width as f64) * PI * 2.0;

// Gets the value stored at the latitude and longitude calculated.
let (lat, long) = buffer[RectangleSpherePoint::from_geographic(latitude, longitude)];
let (x, y, z) = buffer[RectangleSpherePoint::from_geographic(latitude, longitude)];

frame[i] = ((lat + PI / 2.0) / PI * 255.0) as u8;
frame[i + 2] = (long / (2.0 * PI) * 255.0) as u8;
frame[i + 0] = ((x + 1.0) / 2.0 * 255.0) as u8;
frame[i + 1] = ((y + 1.0) / 2.0 * 255.0) as u8;
frame[i + 2] = ((z + 1.0) / 2.0 * 255.0) as u8;
frame[i + 3] = 255;
}
}
Expand Down
Loading

0 comments on commit ffbdef7

Please sign in to comment.