Rust: Color pub u8
This commit is contained in:
100
bench/programs_rust/rot-cube/src/main.rs
Normal file
100
bench/programs_rust/rot-cube/src/main.rs
Normal file
@@ -0,0 +1,100 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::{
|
||||
arch::asm,
|
||||
ops::{Add, Mul, Sub},
|
||||
};
|
||||
|
||||
use fpga_lib::{
|
||||
interface::{Buttons, Leds},
|
||||
panic_handler,
|
||||
register::X31,
|
||||
vga::{BLACK, BLUE, Color, FONT_WIDTH, GREEN, HEIGHT, RED, VGA, WHITE, WIDTH},
|
||||
};
|
||||
|
||||
panic_handler! {}
|
||||
|
||||
pub struct Vec3(f32, f32, f32);
|
||||
pub struct Mat3x3([[f32; 3]; 3]);
|
||||
|
||||
impl Mul<Mat3x3> for Mat3x3
|
||||
{
|
||||
type Output = Mat3x3;
|
||||
|
||||
fn mul(self, rhs: Mat3x3) -> Self::Output
|
||||
{
|
||||
Mat3x3([
|
||||
[
|
||||
rhs.0[0][0] * self.0[0][0],
|
||||
rhs.0[0][1] * self.0[1][0],
|
||||
rhs.0[0][2] * self.0[2][0],
|
||||
],
|
||||
[
|
||||
rhs.0[1][0] * self.0[0][1],
|
||||
rhs.0[1][1] * self.0[1][1],
|
||||
rhs.0[1][2] * self.0[2][1],
|
||||
],
|
||||
[
|
||||
rhs.0[2][0] * self.0[0][2],
|
||||
rhs.0[2][1] * self.0[1][2],
|
||||
rhs.0[2][2] * self.0[2][2],
|
||||
],
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Vec3> for Mat3x3
|
||||
{
|
||||
type Output = Vec3;
|
||||
|
||||
fn mul(self, rhs: Vec3) -> Self::Output
|
||||
{
|
||||
Vec3(
|
||||
self.0[0][0] * rhs.0 + self.0[0][1] * rhs.1 + self.0[0][2] * rhs.2,
|
||||
self.0[1][0] * rhs.0 + self.0[1][1] * rhs.1 + self.0[1][2] * rhs.2,
|
||||
self.0[2][0] * rhs.0 + self.0[2][1] * rhs.1 + self.0[2][2] * rhs.2,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const CUBE: [Vec3; 8] = [
|
||||
Vec3(1., 1., 1.),
|
||||
Vec3(1., 1., -1.),
|
||||
Vec3(1., -1., -1.),
|
||||
Vec3(1., -1., 1.),
|
||||
Vec3(-1., 1., 1.),
|
||||
Vec3(-1., 1., -1.),
|
||||
Vec3(-1., -1., -1.),
|
||||
Vec3(-1., -1., 1.),
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
const LINES: [usize; 24] = [
|
||||
// Face 1
|
||||
0, 1,
|
||||
1, 2,
|
||||
2, 3,
|
||||
3, 0,
|
||||
|
||||
// Face 2
|
||||
4, 5,
|
||||
5, 6,
|
||||
6, 7,
|
||||
7, 4,
|
||||
|
||||
// Cross faces
|
||||
0, 4,
|
||||
1, 5,
|
||||
2, 6,
|
||||
3, 7
|
||||
];
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn main() -> !
|
||||
{
|
||||
loop
|
||||
{
|
||||
core::hint::spin_loop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user