Crates.io | raywoke |
lib.rs | raywoke |
version | |
source | src |
created_at | 2025-01-09 01:37:58.038114 |
updated_at | 2025-01-09 01:37:58.038114 |
description | Extremely simple raycasting crate |
homepage | |
repository | https://github.com/Ultrasquid9/Raywoke |
max_upload_size | |
id | 1509409 |
Cargo.toml error: | TOML parse error at line 21, column 1 | 21 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Raywoke is an extremely simple raycasting crate, forked from raylite. It was created primarily to make the API simpler to use, and integrate more closely with third-party math libraries.
In order to achieve this, Raywoke makes two compromises:
no_std
dyn-clone
, meaning it is no longer dependency-free.Raywoke provides interop with both Glam and Nalgebra. To enable this, enable their restpective features in your cargo.toml
:
[dependencies]
raywoke = { version = "0.", features = ["glam","nalgebra"] }
Using the library
use raywoke::prelude::*;
fn main() {
// Positions are differentiated here because emission direction matters
let ray = Ray {
start: (0., 0.), // Emission origin position
end: (2., 0.), // Emission end position
};
// Direction does not matter for Barriers
let mut bar = Barrier ((1., -1.), (1., 1.));
let result = cast(&ray, &bar); // Returns a Result<RayHit, RayFail>
assert!(result.is_ok()); // Result is an Ok<RayHit> containing hit info
bar = Barrier ((-1., -1.), (-1., 1.)); // Place barrier behind the Ray
let result = cast(&ray, &bar);
assert!(result.is_err()); // Result is an Err<RayFail::NoHit>
}
Glam and Nalgebra interop
use glam::Vec2;
use nalgebra::Vector2;
use raywoke::prelude::*;
fn main() {
// With the "glam" and "nalgebra" features, you can use their respective Vector structs
let ray = Ray::new(
Vec2::new(0., 0.),
Vector2::new(0., 0.),
);
}
Creating your own Point struct
use raywoke::prelude::*;
// Clone and Debug are both required
#[derive(Debug, Clone)]
struct Vec2 {
x: f32,
y: f32
}
impl Point for Vec2 {
fn x(&self) -> f32 {
self.x
}
fn y(&self) -> f32 {
self.y
}
fn edit(&mut self, x: f32, y: f32) {
self.x = x;
self.y = y;
}
}
fn main() {
let ray = Ray::new(
Vec2 { x: 0., y: 0. },
Vec2 { x: 2., y: 0. },
);
}