use sevenx_engine::*;
use sevenx_engine::world::World;
use sevenx_engine::input::InputHandler;
struct Texture3DDemo {
renderer3d: Renderer3D,
meshes: Vec<Mesh3D>,
camera_angle: f32,
camera_distance: f32,
}
impl Texture3DDemo {
fn new() -> Self {
let renderer3d = Renderer3D::new(1280, 720);
let mut meshes = Vec::new();
let mut cube1 = Mesh3D::cube(2.0);
cube1.position = Vec3::new(-6.0, 0.0, 0.0);
let texture1 = Texture3D::checkerboard(64, [255, 0, 0, 255], [255, 255, 255, 255]);
cube1.set_material(Material3D::new([255, 255, 255, 255]).with_texture(texture1));
meshes.push(cube1);
let mut sphere = Mesh3D::sphere(1.0, 16);
sphere.position = Vec3::new(-3.0, 0.0, 0.0);
sphere.set_material(Material3D::metal());
meshes.push(sphere);
let mut cylinder = Mesh3D::cylinder(0.8, 2.0, 16);
cylinder.position = Vec3::new(0.0, 0.0, 0.0);
cylinder.set_material(Material3D::plastic().with_roughness(0.3));
meshes.push(cylinder);
let mut torus = Mesh3D::torus(1.0, 0.3, 16, 12);
torus.position = Vec3::new(3.0, 0.0, 0.0);
let gradient = Texture3D::gradient_horizontal(64, 64, [255, 0, 0, 255], [0, 0, 255, 255]);
torus.set_material(Material3D::new([255, 255, 255, 255]).with_texture(gradient));
meshes.push(torus);
let mut cone = Mesh3D::cone(1.0, 2.0, 16);
cone.position = Vec3::new(6.0, 0.0, 0.0);
cone.set_material(Material3D::emissive([255, 255, 0, 255], 2.0));
meshes.push(cone);
let mut ground = Mesh3D::plane(20.0, 20.0);
ground.position = Vec3::new(0.0, -2.0, 0.0);
let ground_tex = Texture3D::checkerboard(128, [100, 100, 100, 255], [150, 150, 150, 255]);
ground.set_material(Material3D::new([255, 255, 255, 255]).with_texture(ground_tex));
meshes.push(ground);
Self {
renderer3d,
meshes,
camera_angle: 0.0,
camera_distance: 15.0,
}
}
}
impl GameState for Texture3DDemo {
fn new() -> Self {
Self::new()
}
fn update(&mut self, dt: f32, input: &InputHandler, _world: &mut World) {
self.camera_angle += 20.0 * dt;
if input.is_key_pressed(KeyCode::ArrowLeft) {
self.camera_angle -= 60.0 * dt;
}
if input.is_key_pressed(KeyCode::ArrowRight) {
self.camera_angle += 60.0 * dt;
}
if input.is_key_pressed(KeyCode::ArrowUp) {
self.camera_distance -= 5.0 * dt;
}
if input.is_key_pressed(KeyCode::ArrowDown) {
self.camera_distance += 5.0 * dt;
}
for i in 0..self.meshes.len() - 1 {
self.meshes[i].rotation.y += 30.0 * dt;
self.meshes[i].rotation.x += 15.0 * dt;
}
let cam_x = self.camera_angle.to_radians().cos() * self.camera_distance;
let cam_z = self.camera_angle.to_radians().sin() * self.camera_distance;
self.renderer3d.camera.set_position(Vec3::new(cam_x, 5.0, cam_z));
self.renderer3d.camera.look_at(Vec3::new(0.0, 0.0, 0.0));
}
fn draw(&mut self, _world: &World, pixels: &mut [u8]) {
for pixel in pixels.chunks_exact_mut(4) {
pixel.copy_from_slice(&[20, 25, 35, 255]);
}
self.renderer3d.clear_zbuffer();
for mesh in &self.meshes {
self.renderer3d.render_mesh(mesh, pixels, 1280, 720);
}
let mut prims = Primitives2D::new(pixels, 1280, 720);
prims.draw_rect_filled(10, 10, 400, 120, [0, 0, 0, 180]);
}
}
fn main() {
println!("🎨 SevenX Engine v0.2.7 - Demo de Texturas 3D");
println!("Controles:");
println!(" Setas - Controlar câmera");
println!();
let config = EngineConfig::new()
.with_title("SevenX - Texturas 3D")
.with_size(1280, 720)
.with_gravity(0.0);
Engine::with_config(config).run::<Texture3DDemo>();
}