Struct gemini_engine::elements3d::view3d::Vec3D
source · pub struct Vec3D {
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
A point in 3D space, using f64s
Fields§
§x: f64X-coordinate
y: f64Y-coordinate
z: f64Z-coordinate
Implementations§
source§impl Vec3D
impl Vec3D
sourcepub const fn new(x: f64, y: f64, z: f64) -> Self
pub const fn new(x: f64, y: f64, z: f64) -> Self
Create a Vec3D from the provided f64 values
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
);
}sourcepub fn cross(&self, other: Self) -> Self
pub fn cross(&self, other: Self) -> Self
The cross product of two vectors is a vector perpendicular to both of them. See a more detailed explanation
Trait Implementations§
source§impl AddAssign for Vec3D
impl AddAssign for Vec3D
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moresource§impl DivAssign<f64> for Vec3D
impl DivAssign<f64> for Vec3D
source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
Performs the
/= operation. Read moresource§impl DivAssign for Vec3D
impl DivAssign for Vec3D
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/= operation. Read moresource§impl Mul<Vec3D> for Transform3D
impl Mul<Vec3D> for Transform3D
source§impl MulAssign<f64> for Vec3D
impl MulAssign<f64> for Vec3D
source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
Performs the
*= operation. Read moresource§impl MulAssign for Vec3D
impl MulAssign for Vec3D
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moresource§impl PartialEq for Vec3D
impl PartialEq for Vec3D
source§impl RemAssign for Vec3D
impl RemAssign for Vec3D
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
Performs the
%= operation. Read moresource§impl SubAssign for Vec3D
impl SubAssign for Vec3D
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl Copy for Vec3D
impl StructuralPartialEq for Vec3D
Auto Trait Implementations§
impl Freeze for Vec3D
impl RefUnwindSafe for Vec3D
impl Send for Vec3D
impl Sync for Vec3D
impl Unpin for Vec3D
impl UnwindSafe for Vec3D
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