Skip to main content

camera_demo/
camera_demo.rs

1//! Camera Demo - Orthographic and Perspective Cameras
2//!
3//! Demonstrates camera systems for 3D rendering:
4//! - Orthographic cameras (2D/UI, isometric games)
5//! - Perspective cameras (3D scenes)
6//! - View matrix construction
7//! - Projection matrix construction
8//! - Screen-to-world conversion
9//! - Camera movement and controls
10//!
11//! **Note:** This is a placeholder example demonstrating the Camera API structure.
12//! Full interactive camera controls are in development.
13
14use astrelis_core::logging;
15use astrelis_render::{Color, GraphicsContext, RenderTarget, RenderableWindow, WindowContextDescriptor, wgpu};
16use astrelis_winit::{
17    FrameTime, WindowId,
18    app::{App, AppCtx, run_app},
19    event::EventBatch,
20    window::{WinitPhysicalSize, WindowBackend, WindowDescriptor},
21};
22use std::sync::Arc;
23
24struct CameraDemo {
25    _context: Arc<GraphicsContext>,
26    window: RenderableWindow,
27    window_id: WindowId,
28}
29
30fn main() {
31    logging::init();
32
33    run_app(|ctx| {
34        let graphics_ctx = GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36        let window = ctx
37            .create_window(WindowDescriptor {
38                title: "Camera Demo - View & Projection".to_string(),
39                size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40                ..Default::default()
41            })
42            .expect("Failed to create window");
43
44        let window = RenderableWindow::new_with_descriptor(
45            window,
46            graphics_ctx.clone(),
47            WindowContextDescriptor {
48                format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
49                ..Default::default()
50            },
51        ).expect("Failed to create renderable window");
52
53        let window_id = window.id();
54
55        println!("\n═══════════════════════════════════════════════════════");
56        println!("  📹 CAMERA DEMO - View & Projection");
57        println!("═══════════════════════════════════════════════════════");
58        println!("\n  CAMERA API FEATURES:");
59        println!("    • Orthographic cameras (2D, UI, isometric)");
60        println!("    • Perspective cameras (3D scenes)");
61        println!("    • View matrix (position, rotation, look-at)");
62        println!("    • Projection matrix (FOV, aspect, near/far planes)");
63        println!("    • Screen-to-world coordinate conversion");
64        println!("    • Camera movement helpers");
65        println!("\n  CAMERA TYPES:");
66        println!("    • OrthographicCamera - 2D games, UI overlays");
67        println!("      camera.orthographic(left, right, bottom, top, near, far)");
68        println!("    • PerspectiveCamera - 3D scenes");
69        println!("      camera.perspective(fov, aspect, near, far)");
70        println!("\n  Camera API Usage:");
71        println!("    let camera = Camera::new()");
72        println!("        .position(Vec3::new(0.0, 5.0, 10.0))");
73        println!("        .look_at(Vec3::ZERO)");
74        println!("        .perspective(60.0, aspect, 0.1, 100.0);");
75        println!("    let view_proj = camera.view_projection_matrix();");
76        println!("═══════════════════════════════════════════════════════\n");
77
78        tracing::info!("Camera demo initialized");
79
80        Box::new(CameraDemo {
81            _context: graphics_ctx,
82            window,
83            window_id,
84        })
85    });
86}
87
88impl App for CameraDemo {
89    fn update(&mut self, _ctx: &mut AppCtx, _time: &FrameTime) {}
90
91    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
92        if window_id != self.window_id {
93            return;
94        }
95
96        events.dispatch(|event| {
97            if let astrelis_winit::event::Event::WindowResized(size) = event {
98                self.window.resized(*size);
99                astrelis_winit::event::HandleStatus::consumed()
100            } else {
101                astrelis_winit::event::HandleStatus::ignored()
102            }
103        });
104
105        let mut frame = self.window.begin_drawing();
106        frame.clear_and_render(
107            RenderTarget::Surface,
108            Color::from_rgb_u8(20, 30, 40),
109            |_pass| {},
110        );
111        frame.finish();
112    }
113}