Struct gemini_engine::elements3d::view3d::Transform3D
source · pub struct Transform3D {
pub translation: Vec3D,
pub rotation: Vec3D,
pub scale: Vec3D,
}Expand description
The Transform3D struct is used to manipulate the position of objects in 3D space
Fields§
§translation: Vec3DThe position of the object in 3D space
rotation: Vec3DThe rotation of the object, applied in radians
scale: Vec3DThe object’s scale
Implementations§
source§impl Transform3D
impl Transform3D
sourcepub const fn new_trs(translation: Vec3D, rotation: Vec3D, scale: Vec3D) -> Self
pub const fn new_trs(translation: Vec3D, rotation: Vec3D, scale: Vec3D) -> Self
Create a Transform3D with chosen translation, rotation and scale
sourcepub const fn new_tr(translation: Vec3D, rotation: Vec3D) -> Self
pub const fn new_tr(translation: Vec3D, rotation: Vec3D) -> Self
Create a Transform3D with chosen translation and rotation
Examples found in repository?
examples/spinning-cube.rs (line 14)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let mut view = View::new(200, 90, ColChar::BACKGROUND);
let viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 1.5, 4.0), Vec3D::new(-0.4, 0.0, 0.0)),
FOV,
view.center(),
);
let mut cube = Mesh3D::default_cube();
fps_gameloop!(
{
view.clear();
cube.transform.rotation.y -= 0.05;
},
{
view.blit(
&viewport.render(vec![&cube], DisplayMode::Solid),
Wrapping::Ignore,
);
let _ = view.display_render();
},
FPS,
|elapsed: gameloop::Duration, frame_skip| {
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
}
);
}More examples
examples/donut.rs (line 17)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() {
let mut view = View::new(82, 32, ColChar::EMPTY);
let viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 0.0, 20.0), Vec3D::ZERO),
FOV,
view.center(),
);
let lights = vec![
Light::new_ambient(0.3),
Light::new_directional(0.7, Vec3D::new(1.0, -1.0, -1.0)),
];
let mut donut = Mesh3D::torus(1.8, 1.0, 32, 16);
fps_gameloop!(
{
donut.transform.rotation.x += 0.05;
donut.transform.rotation.z += 0.05;
},
{
view.clear();
view.blit(
&viewport.render(
vec![&donut],
DisplayMode::Illuminated {
lights: lights.clone(),
},
),
Wrapping::Ignore,
);
let _ = view.display_render();
},
FPS
);
}Trait Implementations§
source§impl Clone for Transform3D
impl Clone for Transform3D
source§fn clone(&self) -> Transform3D
fn clone(&self) -> Transform3D
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for Transform3D
impl Debug for Transform3D
source§impl Default for Transform3D
impl Default for Transform3D
source§impl Mul<Vec3D> for Transform3D
impl Mul<Vec3D> for Transform3D
source§impl Mul for Transform3D
impl Mul for Transform3D
source§impl MulAssign for Transform3D
impl MulAssign for Transform3D
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moresource§impl Neg for Transform3D
impl Neg for Transform3D
impl Copy for Transform3D
Auto Trait Implementations§
impl Freeze for Transform3D
impl RefUnwindSafe for Transform3D
impl Send for Transform3D
impl Sync for Transform3D
impl Unpin for Transform3D
impl UnwindSafe for Transform3D
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more