1

Color and algebra

This commit is contained in:
Evan Pratten 2022-12-09 11:26:47 -05:00
parent eb84151e46
commit 9b1a591e22
6 changed files with 189 additions and 5 deletions

View File

@ -20,7 +20,7 @@ exclude = [
[dependencies]
rgb = "^0.8.34"
cgmath = "^0.18.0"
[build-dependencies]
bindgen = "^0.63.0"

View File

@ -18,13 +18,13 @@ pub fn main() {
renderkit::raylib::ffi::BeginDrawing();
// Render text and a background
renderkit::raylib::ffi::ClearBackground(rgb::RGB::new(255, 255, 255).into());
renderkit::raylib::ffi::ClearBackground(renderkit::raylib::palette::RAYWHITE.into());
renderkit::raylib::ffi::DrawText(
"Congrats! You created your first window!\0".as_ptr() as *const i8,
190,
200,
20,
rgb::RGB::new(0, 0, 0).into(),
renderkit::raylib::palette::BLACK.into(),
);
// End the draw call

View File

@ -1,4 +1,5 @@
//! Bindings and helpers for interfacing with raylib
pub mod xlat;
pub mod ffi;
pub mod ffi;
pub mod palette;

78
src/raylib/palette.rs Normal file
View File

@ -0,0 +1,78 @@
// Light Gray
pub const LIGHTGRAY: rgb::RGB8 = rgb::RGB8::new(200, 200, 200);
// Gray
pub const GRAY: rgb::RGB8 = rgb::RGB8::new(130, 130, 130);
// Dark Gray
pub const DARKGRAY: rgb::RGB8 = rgb::RGB8::new(80, 80, 80);
// Yellow
pub const YELLOW: rgb::RGB8 = rgb::RGB8::new(253, 249, 0);
// Gold
pub const GOLD: rgb::RGB8 = rgb::RGB8::new(255, 203, 0);
// Orange
pub const ORANGE: rgb::RGB8 = rgb::RGB8::new(255, 161, 0);
// Pink
pub const PINK: rgb::RGB8 = rgb::RGB8::new(255, 109, 194);
// Red
pub const RED: rgb::RGB8 = rgb::RGB8::new(230, 41, 55);
// Maroon
pub const MAROON: rgb::RGB8 = rgb::RGB8::new(190, 33, 55);
// Green
pub const GREEN: rgb::RGB8 = rgb::RGB8::new(0, 228, 48);
// Lime
pub const LIME: rgb::RGB8 = rgb::RGB8::new(0, 158, 47);
// Dark Green
pub const DARKGREEN: rgb::RGB8 = rgb::RGB8::new(0, 117, 44);
// Sky Blue
pub const SKYBLUE: rgb::RGB8 = rgb::RGB8::new(102, 191, 255);
// Blue
pub const BLUE: rgb::RGB8 = rgb::RGB8::new(0, 121, 241);
// Dark Blue
pub const DARKBLUE: rgb::RGB8 = rgb::RGB8::new(0, 82, 172);
// Purple
pub const PURPLE: rgb::RGB8 = rgb::RGB8::new(200, 122, 255);
// Violet
pub const VIOLET: rgb::RGB8 = rgb::RGB8::new(135, 60, 190);
// Dark Purple
pub const DARKPURPLE: rgb::RGB8 = rgb::RGB8::new(112, 31, 126);
// Beige
pub const BEIGE: rgb::RGB8 = rgb::RGB8::new(211, 176, 131);
// Brown
pub const BROWN: rgb::RGB8 = rgb::RGB8::new(127, 106, 79);
// Dark Brown
pub const DARKBROWN: rgb::RGB8 = rgb::RGB8::new(76, 63, 47);
// White
pub const WHITE: rgb::RGB8 = rgb::RGB8::new(255, 255, 255);
// Black
pub const BLACK: rgb::RGB8 = rgb::RGB8::new(0, 0, 0);
// Blank
pub const BLANK: rgb::RGBA8 = rgb::RGBA8::new(0, 0, 0, 0);
// Magenta
pub const MAGENTA: rgb::RGB8 = rgb::RGB8::new(255, 0, 255);
// Raylib WHite
pub const RAYWHITE: rgb::RGB8 = rgb::RGB8::new(245, 245, 245);

104
src/raylib/xlat/cgmath.rs Normal file
View File

@ -0,0 +1,104 @@
//! Conversions between the `cgmath` crate and raylib's math types.
impl Into<crate::raylib::ffi::Vector2> for cgmath::Vector2<f32> {
fn into(self) -> crate::raylib::ffi::Vector2 {
crate::raylib::ffi::Vector2 {
x: self.x,
y: self.y,
}
}
}
impl From<crate::raylib::ffi::Vector2> for cgmath::Vector2<f32> {
fn from(vec: crate::raylib::ffi::Vector2) -> Self {
Self {
x: vec.x,
y: vec.y,
}
}
}
impl Into<crate::raylib::ffi::Vector3> for cgmath::Vector3<f32> {
fn into(self) -> crate::raylib::ffi::Vector3 {
crate::raylib::ffi::Vector3 {
x: self.x,
y: self.y,
z: self.z,
}
}
}
impl From<crate::raylib::ffi::Vector3> for cgmath::Vector3<f32> {
fn from(vec: crate::raylib::ffi::Vector3) -> Self {
Self {
x: vec.x,
y: vec.y,
z: vec.z,
}
}
}
impl Into<crate::raylib::ffi::Vector4> for cgmath::Vector4<f32> {
fn into(self) -> crate::raylib::ffi::Vector4 {
crate::raylib::ffi::Vector4 {
x: self.x,
y: self.y,
z: self.z,
w: self.w,
}
}
}
impl From<crate::raylib::ffi::Vector4> for cgmath::Vector4<f32> {
fn from(vec: crate::raylib::ffi::Vector4) -> Self {
Self {
x: vec.x,
y: vec.y,
z: vec.z,
w: vec.w,
}
}
}
impl Into<crate::raylib::ffi::Quaternion> for cgmath::Quaternion<f32> {
fn into(self) -> crate::raylib::ffi::Quaternion {
crate::raylib::ffi::Quaternion {
x: self.v.x,
y: self.v.y,
z: self.v.z,
w: self.s,
}
}
}
impl From<crate::raylib::ffi::Quaternion> for cgmath::Quaternion<f32> {
fn from(quat: crate::raylib::ffi::Quaternion) -> Self {
Self {
v: cgmath::Vector3::new(quat.x, quat.y, quat.z),
s: quat.w,
}
}
}
impl Into<crate::raylib::ffi::Matrix> for cgmath::Matrix4<f32> {
fn into(self) -> crate::raylib::ffi::Matrix {
crate::raylib::ffi::Matrix {
m0: self.x.x,
m1: self.x.y,
m2: self.x.z,
m3: self.x.w,
m4: self.y.x,
m5: self.y.y,
m6: self.y.z,
m7: self.y.w,
m8: self.z.x,
m9: self.z.y,
m10: self.z.z,
m11: self.z.w,
m12: self.w.x,
m13: self.w.y,
m14: self.w.z,
m15: self.w.w,
}
}
}

View File

@ -1,4 +1,5 @@
//! Translations between well-known Rust libraries and raylib
pub mod rgb;
pub mod rgb;
pub mod cgmath;