pub struct Window { /* private fields */ }
Expand description
Structure representing a window and a 3D scene.
This is the main interface with the 3d engine.
Implementations
sourceimpl Window
impl Window
sourcepub fn should_close(&self) -> bool
pub fn should_close(&self) -> bool
Indicates whether this window should be closed.
sourcepub fn set_framerate_limit(&mut self, fps: Option<u64>)
pub fn set_framerate_limit(&mut self, fps: Option<u64>)
Sets the maximum number of frames per second. Cannot be 0. None
means there is no limit.
sourcepub fn set_icon(
&mut self,
icon: impl GenericImage<Pixel = impl Pixel<Subpixel = u8>>
)
pub fn set_icon(
&mut self,
icon: impl GenericImage<Pixel = impl Pixel<Subpixel = u8>>
)
Set the window icon. On wasm this does nothing.
window.set_icon(image::open("foo.ico")?);
sourcepub fn set_cursor_grab(&self, grab: bool)
pub fn set_cursor_grab(&self, grab: bool)
Set the cursor grabbing behaviour.
If cursor grabbing is on, the cursor is prevented from leaving the window. Does nothing on web platforms.
sourcepub fn set_cursor_position(&self, x: f64, y: f64)
pub fn set_cursor_position(&self, x: f64, y: f64)
Set the cursor position.
sourcepub fn hide_cursor(&self, hide: bool)
pub fn hide_cursor(&self, hide: bool)
Toggle the cursor visibility.
sourcepub fn hide(&mut self)
pub fn hide(&mut self)
Hides the window, without closing it. Use show
to make it visible again.
sourcepub fn set_background_color(&mut self, r: f32, g: f32, b: f32)
pub fn set_background_color(&mut self, r: f32, g: f32, b: f32)
Sets the background color.
sourcepub fn set_point_size(&mut self, pt_size: f32)
pub fn set_point_size(&mut self, pt_size: f32)
Set the size of all points that will be rendered.
Unfortunately, not all point sizes are supported by all graphics drivers.
sourcepub fn set_line_width(&mut self, line_width: f32)
pub fn set_line_width(&mut self, line_width: f32)
Set the width of all lines that will be rendered.
sourcepub fn draw_line(&mut self, a: &Point3<f32>, b: &Point3<f32>, color: &Point3<f32>)
pub fn draw_line(&mut self, a: &Point3<f32>, b: &Point3<f32>, color: &Point3<f32>)
Adds a 3D line to be drawn during the next render.
The line is being drawn only during the next frame after this call. Therefore, this call must be executed at as many frames as you want it to remain visible.
sourcepub fn draw_planar_line(
&mut self,
a: &Point2<f32>,
b: &Point2<f32>,
color: &Point3<f32>
)
pub fn draw_planar_line(
&mut self,
a: &Point2<f32>,
b: &Point2<f32>,
color: &Point3<f32>
)
Draws a 2D line to be drawn during the next render.
The line is being drawn only during the next frame after this call. Therefore, this call must be executed at as many frames as you want it to remain visible.
sourcepub fn draw_point(&mut self, pt: &Point3<f32>, color: &Point3<f32>)
pub fn draw_point(&mut self, pt: &Point3<f32>, color: &Point3<f32>)
Adds a point to be drawn during the next frame.
sourcepub fn draw_text(
&mut self,
text: &str,
pos: &Point2<f32>,
scale: f32,
font: &Rc<Font>,
color: &Point3<f32>
)
pub fn draw_text(
&mut self,
text: &str,
pos: &Point2<f32>,
scale: f32,
font: &Rc<Font>,
color: &Point3<f32>
)
Adds a string to be drawn during the next frame.
sourcepub fn remove(&mut self, sn: &mut SceneNode)
👎 Deprecated: Use remove_node
instead.
pub fn remove(&mut self, sn: &mut SceneNode)
Use remove_node
instead.
Removes an object from the scene.
sourcepub fn remove_node(&mut self, sn: &mut SceneNode)
pub fn remove_node(&mut self, sn: &mut SceneNode)
Removes an object from the scene.
sourcepub fn remove_planar_node(&mut self, sn: &mut PlanarSceneNode)
pub fn remove_planar_node(&mut self, sn: &mut PlanarSceneNode)
Removes a 2D object from the scene.
sourcepub fn add_group(&mut self) -> SceneNode
pub fn add_group(&mut self) -> SceneNode
Adds a group to the scene.
A group is a node not containing any object.
sourcepub fn add_planar_group(&mut self) -> PlanarSceneNode
pub fn add_planar_group(&mut self) -> PlanarSceneNode
Adds a 2D group to the scene.
A group is a node not containing any object.
sourcepub fn add_obj(
&mut self,
path: &Path,
mtl_dir: &Path,
scale: Vector3<f32>
) -> SceneNode
pub fn add_obj(
&mut self,
path: &Path,
mtl_dir: &Path,
scale: Vector3<f32>
) -> SceneNode
Adds an obj model to the scene.
Arguments
path
- relative path to the obj file.scale
- scale to apply to the model.
sourcepub fn add_mesh(
&mut self,
mesh: Rc<RefCell<Mesh>>,
scale: Vector3<f32>
) -> SceneNode
pub fn add_mesh(
&mut self,
mesh: Rc<RefCell<Mesh>>,
scale: Vector3<f32>
) -> SceneNode
Adds an unnamed mesh to the scene.
sourcepub fn add_planar_mesh(
&mut self,
mesh: Rc<RefCell<PlanarMesh>>,
scale: Vector2<f32>
) -> PlanarSceneNode
pub fn add_planar_mesh(
&mut self,
mesh: Rc<RefCell<PlanarMesh>>,
scale: Vector2<f32>
) -> PlanarSceneNode
Adds an unnamed planar mesh to the scene.
sourcepub fn add_trimesh(
&mut self,
descr: TriMesh<f32>,
scale: Vector3<f32>
) -> SceneNode
pub fn add_trimesh(
&mut self,
descr: TriMesh<f32>,
scale: Vector3<f32>
) -> SceneNode
Creates and adds a new object using the geometry generated by a given procedural generator. Creates and adds a new object using a mesh descriptor.
sourcepub fn add_geom_with_name(
&mut self,
geometry_name: &str,
scale: Vector3<f32>
) -> Option<SceneNode>
pub fn add_geom_with_name(
&mut self,
geometry_name: &str,
scale: Vector3<f32>
) -> Option<SceneNode>
Creates and adds a new object using the geometry registered as geometry_name
.
sourcepub fn add_cube(&mut self, wx: f32, wy: f32, wz: f32) -> SceneNode
pub fn add_cube(&mut self, wx: f32, wy: f32, wz: f32) -> SceneNode
Adds a cube to the scene. The cube is initially axis-aligned and centered at (0, 0, 0).
Arguments
wx
- the cube extent along the x axiswy
- the cube extent along the y axiswz
- the cube extent along the z axis
sourcepub fn add_sphere(&mut self, r: f32) -> SceneNode
pub fn add_sphere(&mut self, r: f32) -> SceneNode
Adds a sphere to the scene. The sphere is initially centered at (0, 0, 0).
Arguments
r
- the sphere radius
sourcepub fn add_cone(&mut self, r: f32, h: f32) -> SceneNode
pub fn add_cone(&mut self, r: f32, h: f32) -> SceneNode
Adds a cone to the scene. The cone is initially centered at (0, 0, 0) and points toward the
positive y
axis.
Arguments
h
- the cone heightr
- the cone base radius
sourcepub fn add_cylinder(&mut self, r: f32, h: f32) -> SceneNode
pub fn add_cylinder(&mut self, r: f32, h: f32) -> SceneNode
Adds a cylinder to the scene. The cylinder is initially centered at (0, 0, 0) and has its
principal axis aligned with the y
axis.
Arguments
h
- the cylinder heightr
- the cylinder base radius
sourcepub fn add_capsule(&mut self, r: f32, h: f32) -> SceneNode
pub fn add_capsule(&mut self, r: f32, h: f32) -> SceneNode
Adds a capsule to the scene. The capsule is initially centered at (0, 0, 0) and has its
principal axis aligned with the y
axis.
Arguments
r
- the capsule caps radiush
- the capsule height
sourcepub fn add_planar_capsule(&mut self, r: f32, h: f32) -> PlanarSceneNode
pub fn add_planar_capsule(&mut self, r: f32, h: f32) -> PlanarSceneNode
Adds a 2D capsule to the scene. The capsule is initially centered at (0, 0) and has its
principal axis aligned with the y
axis.
Arguments
r
- the capsule caps radiush
- the capsule height
sourcepub fn add_quad(
&mut self,
w: f32,
h: f32,
usubdivs: usize,
vsubdivs: usize
) -> SceneNode
pub fn add_quad(
&mut self,
w: f32,
h: f32,
usubdivs: usize,
vsubdivs: usize
) -> SceneNode
Adds a double-sided quad to the scene. The quad is initially centered at (0, 0, 0). The quad itself is composed of a user-defined number of triangles regularly spaced on a grid. This is the main way to draw height maps.
Arguments
w
- the quad width.h
- the quad height.wsubdivs
- number of horizontal subdivisions. This correspond to the number of squares which will be placed horizontally on each line. Must not be0
.hsubdivs
- number of vertical subdivisions. This correspond to the number of squares which will be placed vertically on each line. Must not be0
. update.
sourcepub fn add_quad_with_vertices(
&mut self,
vertices: &[Point3<f32>],
nhpoints: usize,
nvpoints: usize
) -> SceneNode
pub fn add_quad_with_vertices(
&mut self,
vertices: &[Point3<f32>],
nhpoints: usize,
nvpoints: usize
) -> SceneNode
Adds a double-sided quad with the specified vertices.
sourcepub fn add_texture(&mut self, path: &Path, name: &str) -> Rc<Texture>
pub fn add_texture(&mut self, path: &Path, name: &str) -> Rc<Texture>
Load a texture from a file and return a reference to it.
sourcepub fn add_rectangle(&mut self, wx: f32, wy: f32) -> PlanarSceneNode
pub fn add_rectangle(&mut self, wx: f32, wy: f32) -> PlanarSceneNode
Adds a rectangle to the scene. The rectangle is initially axis-aligned and centered at (0, 0, 0).
Arguments
wx
- the cube extent along the x axiswy
- the cube extent along the y axis
sourcepub fn add_circle(&mut self, r: f32) -> PlanarSceneNode
pub fn add_circle(&mut self, r: f32) -> PlanarSceneNode
Adds a circle to the scene. The circle is initially centered at (0, 0, 0).
Arguments
r
- the circle radius
sourcepub fn add_convex_polygon(
&mut self,
polygon: Vec<Point2<f32>>,
scale: Vector2<f32>
) -> PlanarSceneNode
pub fn add_convex_polygon(
&mut self,
polygon: Vec<Point2<f32>>,
scale: Vector2<f32>
) -> PlanarSceneNode
sourcepub fn scale_factor(&self) -> f64
pub fn scale_factor(&self) -> f64
The scale factor of this screen.
sourcepub fn new_with_size(title: &str, width: u32, height: u32) -> Window
pub fn new_with_size(title: &str, width: u32, height: u32) -> Window
Opens a window with a custom size then calls a user-defined procedure.
Arguments
title
- the window title.width
- the window width.height
- the window height.
sourcepub fn new_with_setup(
title: &str,
width: u32,
height: u32,
setup: CanvasSetup
) -> Window
pub fn new_with_setup(
title: &str,
width: u32,
height: u32,
setup: CanvasSetup
) -> Window
Opens a window with custom options for vsync and AA.
sourcepub fn scene_mut(&mut self) -> &mut SceneNode
pub fn scene_mut(&mut self) -> &mut SceneNode
Mutable reference to the scene associated with this window.
sourcepub fn snap(&self, out: &mut Vec<u8>)
pub fn snap(&self, out: &mut Vec<u8>)
Read the pixels currently displayed to the screen.
Arguments:
out
- the output buffer. It is automatically resized.
sourcepub fn snap_rect(
&self,
out: &mut Vec<u8>,
x: usize,
y: usize,
width: usize,
height: usize
)
pub fn snap_rect(
&self,
out: &mut Vec<u8>,
x: usize,
y: usize,
width: usize,
height: usize
)
Read a section of pixels from the screen
Arguments:
out
- the output buffer. It is automatically resizedx, y, width, height
- the rectangle to capture
sourcepub fn snap_image(&self) -> ImageBuffer<Rgb<u8>, Vec<u8>>
pub fn snap_image(&self) -> ImageBuffer<Rgb<u8>, Vec<u8>>
Get the current screen as an image
sourcepub fn events(&self) -> EventManager
pub fn events(&self) -> EventManager
Gets the events manager that gives access to an event iterator.
sourcepub fn cursor_pos(&self) -> Option<(f64, f64)>
pub fn cursor_pos(&self) -> Option<(f64, f64)>
Gets the last known position of the mouse.
The position of the mouse is automatically updated when the mouse moves over the canvas.
sourcepub fn render_loop<S: State>(self, state: S)
pub fn render_loop<S: State>(self, state: S)
Runs the render and event loop until the window is closed.
sourcepub fn render_with_state<S: State>(&mut self, state: &mut S) -> bool
pub fn render_with_state<S: State>(&mut self, state: &mut S) -> bool
Render one frame using the specified state.
sourcepub fn render(&mut self) -> bool
pub fn render(&mut self) -> bool
Renders the scene using the default camera.
Returns false
if the window should be closed.
sourcepub fn render_with_effect(
&mut self,
effect: &mut dyn PostProcessingEffect
) -> bool
pub fn render_with_effect(
&mut self,
effect: &mut dyn PostProcessingEffect
) -> bool
Render using a specific post processing effect.
Returns false
if the window should be closed.
sourcepub fn render_with_camera(&mut self, camera: &mut dyn Camera) -> bool
pub fn render_with_camera(&mut self, camera: &mut dyn Camera) -> bool
Render using a specific camera.
Returns false
if the window should be closed.
sourcepub fn render_with_cameras(
&mut self,
camera: &mut dyn Camera,
planar_camera: &mut dyn PlanarCamera
) -> bool
pub fn render_with_cameras(
&mut self,
camera: &mut dyn Camera,
planar_camera: &mut dyn PlanarCamera
) -> bool
Render using a specific 2D and 3D camera.
Returns false
if the window should be closed.
sourcepub fn render_with_camera_and_effect(
&mut self,
camera: &mut dyn Camera,
effect: &mut dyn PostProcessingEffect
) -> bool
pub fn render_with_camera_and_effect(
&mut self,
camera: &mut dyn Camera,
effect: &mut dyn PostProcessingEffect
) -> bool
Render using a specific camera and post processing effect.
Returns false
if the window should be closed.
sourcepub fn render_with_cameras_and_effect(
&mut self,
camera: &mut dyn Camera,
planar_camera: &mut dyn PlanarCamera,
effect: &mut dyn PostProcessingEffect
) -> bool
pub fn render_with_cameras_and_effect(
&mut self,
camera: &mut dyn Camera,
planar_camera: &mut dyn PlanarCamera,
effect: &mut dyn PostProcessingEffect
) -> bool
Render using a specific 2D and 3D camera and post processing effect.
Returns false
if the window should be closed.
sourcepub fn render_with(
&mut self,
camera: Option<&mut dyn Camera>,
planar_camera: Option<&mut dyn PlanarCamera>,
post_processing: Option<&mut dyn PostProcessingEffect>
) -> bool
pub fn render_with(
&mut self,
camera: Option<&mut dyn Camera>,
planar_camera: Option<&mut dyn PlanarCamera>,
post_processing: Option<&mut dyn PostProcessingEffect>
) -> bool
Draws the scene with the given camera and post-processing effect.
Returns false
if the window should be closed.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Window
impl !Send for Window
impl !Sync for Window
impl Unpin for Window
impl !UnwindSafe for Window
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.