Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

IVec3

struct IVec3 { x: int, y: int, z: int }

A 3D vector with int components x, y, and z. Create one with ivec3(x, y, z), IVec3::new(x, y, z) or a struct literal such as IVec3 { x = 0, y = 1, z = 0 }.

Implementations

new

fn new(x: int, y: int, z: int) -> IVec3

Creates a vector from its x, y and z components. A struct literal such as IVec3 { x = 1, y = 2, z = 3 } does the same.

use std::math::IVec3;

let v = IVec3::new(1, 2, 3);
let z = v.z; // 3

add

fn add(self, other: IVec3) -> IVec3

Returns the sum of the two vectors, adding them component by component.

use std::math::IVec3;

let v = IVec3::new(1, 2, 3).add(IVec3::new(1, 1, 1));
let z = v.z; // 4

sub

fn sub(self, other: IVec3) -> IVec3

Returns this vector minus other, component by component.

use std::math::IVec3;

let v = IVec3::new(4, 5, 6).sub(IVec3::new(1, 1, 1));
let z = v.z; // 5

scale

fn scale(self, by: int) -> IVec3

Returns the vector with every component multiplied by by.

use std::math::IVec3;

let v = IVec3::new(1, 2, 3).scale(2);
let z = v.z; // 6