Skip to content

Instantly share code, notes, and snippets.

@hYdos
Created November 24, 2022 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hYdos/8f4c4bea934714be008d7157b1512c79 to your computer and use it in GitHub Desktop.
Save hYdos/8f4c4bea934714be008d7157b1512c79 to your computer and use it in GitHub Desktop.
#![allow(non_snake_case)]
use citro3d_sys::*;
use ctru::prelude::{Hid, KeyPad};
pub const fn color(red: u32, green: u32, blue: u32) -> u32 {
let r = red & 0xFF;
let g = green & 0xFF;
let b = blue & 0xFF;
let a = 0xFF;
u32::from_be_bytes([r as u8, g as u8, b as u8, a as u8])
}
pub fn spot_step(angle: f32, cutoff: f32) -> f32 {
if angle >= cutoff { 1.0 } else { 0.0 }
}
pub fn newMatrix() -> C3D_Mtx {
C3D_Mtx {
r: [
C3D_FVec { c: [0.0, 0.0, 0.0, 0.0] },
C3D_FVec { c: [0.0, 0.0, 0.0, 0.0] },
C3D_FVec { c: [0.0, 0.0, 0.0, 0.0] },
C3D_FVec { c: [0.0, 0.0, 0.0, 0.0] }
]
}
}
/**
* @brief Creates a matrix with the diagonal using the given parameters.
* @param[out] out Output matrix.
* @param[in] x The X component.
* @param[in] y The Y component.
* @param[in] z The Z component.
* @param[in] w The W component.
*/
#[inline(always)]
pub fn Mtx_Diagonal(out: &mut C3D_Mtx, x: f32, y: f32, z: f32, w: f32) {
unsafe {
out.r[0] = C3D_FVec { c: [x, 0.0, 0.0, 0.0] };
out.r[1] = C3D_FVec { c: [0.0, y, 0.0, 0.0] };
out.r[2] = C3D_FVec { c: [0.0, 0.0, z, 0.0] };
out.r[3] = C3D_FVec { c: [0.0, 0.0, 0.0, w] };
}
}
/**
* @brief Identity matrix
* @param[out] out Matrix to fill
*/
#[inline(always)]
pub fn Mtx_Identity(out: &mut C3D_Mtx) {
Mtx_Diagonal(out, 1.0, 1.0, 1.0, 1.0);
}
/**
* @brief Convert an angle from degrees to radians
* @param[in] _angle Angle in degrees
* @return Angle in radians
*/
#[inline(always)]
pub fn C3D_AngleFromDegrees(angle: f32) -> f32 {
angle * std::f32::consts::PI / 180.0
}
#[inline(always)]
pub unsafe fn LightLut_Phong(lut: &mut C3D_LightLut, shininess: f32) {
extern "C" fn powf(a: f32, b: f32) -> f32 {
a.powf(b)
}
LightLut_FromFunc(lut, Some(powf), shininess, false)
}
#[macro_export]
macro_rules! FVec4_New {
($x: expr, $y: expr, $z: expr, $w: expr) => {
C3D_FVec {c: [$x, $y, $z, $w] as [f32; 4]}
};
}
macro_rules! GPU_TEXTURE_MAG_FILTER {
($v:expr) => {((($v)&0x1)<<1)};
}
macro_rules! GPU_TEXTURE_MIN_FILTER {
($v:expr) => {((($v)&0x1)<<2)};
}
pub fn C3D_TexSetFilter(tex: &mut C3D_Tex, mag_filter: GPU_TEXTURE_FILTER_PARAM, min_filter: GPU_TEXTURE_FILTER_PARAM) {
tex.param &= !(GPU_TEXTURE_MAG_FILTER!(GPU_LINEAR) | GPU_TEXTURE_MIN_FILTER!(GPU_LINEAR));
tex.param |= GPU_TEXTURE_MAG_FILTER!(mag_filter) | GPU_TEXTURE_MIN_FILTER!(min_filter);
}
#[inline]
pub unsafe fn C3D_LightColor(light: *mut C3D_Light, r: f32, g: f32, b: f32)
{
C3D_LightDiffuse(light, r, g, b);
C3D_LightSpecular0(light, r, g, b);
C3D_LightSpecular1(light, r, g, b);
}
pub fn wait(hid: &Hid) {
println!("Paused. Press Start to continue.");
loop {
hid.scan_input();
// Continue key
if hid.keys_held().contains(KeyPad::KEY_START) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment