Skip to main content

RaylibMode3DExt

Trait RaylibMode3DExt 

Source
pub trait RaylibMode3DExt
where Self: Sized,
{ // Provided methods fn begin_mode3D( &mut self, camera: impl Into<Camera3D>, ) -> RaylibMode3D<'_, Self> { ... } fn draw_mode3D<'a>( &'a mut self, camera: impl Into<Camera3D>, func: impl FnOnce(RaylibMode3D<'a, Self>), ) { ... } }
Expand description

Extension trait providing 3D camera mode entry on draw handles.

Implemented for every RaylibDraw surface. The two methods are alternative forms: begin_mode3D returns a RAII guard; draw_mode3D takes a closure and ends 3D mode automatically when the closure returns.

§Examples

Closure form:

use raylib::prelude::*;

let (mut rl, thread) = raylib::init().size(800, 600).title("demo").build();
let camera = Camera3D::perspective(
    Vector3::new(4.0, 4.0, 4.0),
    Vector3::new(0.0, 0.0, 0.0),
    Vector3::new(0.0, 1.0, 0.0),
    45.0,
);
while !rl.window_should_close() {
    let mut d = rl.begin_drawing(&thread);
    d.clear_background(Color::RAYWHITE);
    d.draw_mode3D(camera, |mut c| {
        c.draw_cube(Vector3::zero(), 2.0, 2.0, 2.0, Color::RED);
        c.draw_grid(10, 1.0);
    });
}

See RaylibMode3D for the equivalent guard-form example.

§See also

  • RaylibMode3D — RAII guard returned by begin_mode3D.
  • Camera3D — camera passed into both methods.
  • RaylibDraw3D — 3D-only draw methods exposed by the guard.

Provided Methods§

Source

fn begin_mode3D( &mut self, camera: impl Into<Camera3D>, ) -> RaylibMode3D<'_, Self>

Begin 3D mode with custom camera (3D). Prefer using the closure version, RaylibMode3DExt::draw_mode3D. This version returns a handle that calls raylib_sys::EndMode3D at the end of the scope and is provided as a fallback incase you run into issues with closures(such as lifetime or performance reasons)

Source

fn draw_mode3D<'a>( &'a mut self, camera: impl Into<Camera3D>, func: impl FnOnce(RaylibMode3D<'a, Self>), )

Begin 3D mode with custom camera (3D).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§