Crates.io | vext |
lib.rs | vext |
version | 0.1.20 |
source | src |
created_at | 2019-05-24 19:30:25.93567 |
updated_at | 2019-05-26 18:56:27.614308 |
description | Basic Physics 'Vector' Library |
homepage | |
repository | |
max_upload_size | |
id | 136761 |
size | 9,834 |
Basic Physics 'Vector' Library
Add the following to your Cargo.toml
:
[dependencies]
vext = "0.1.20"
and this to your crate root:
extern crate vext;
use vext::*;
fn main() {
let mut vec2 = Vector2::new(25.0, 50.0);
vec2.set(125.0, vec2.y()); // Sets x to 125 and y to previous y value: 50
let (x, _y) = vec2.get();
let vec3 = Vector3::new(x, 25.0, 100.0);
let vec3_2 = vec2.to_v3(5.0); // Creates Vector3 with xy of v2 and z of 5
let mut vec3_3 = Vector3::from(vec2); // Creates a Vector3 with xy of v2 and z of 0
vec3_3.set(vec3_3.x(), vec3_3.y(), 35.0); // Sets xy to previous and z to 35
let vec3_4 = vec3_2 + vec3_3;
let direction = vec3_4.normalize(); // Get pointing direction of Vector3
let string: String = direction.to_string(); // Not required for println!() but you can to_string() if needed
println!("vec2: {}\nvec3: {}\nmagnitude: {}", vec2, vec3, string); // Prints whole vectors
println!("vec3_2 x: {}", vec3_2.x()); // Prints single vector magnitude
}