#vector #unity #vector2 #vector3 #unity3d

vect

A library for providing vectors for game development that use a Unity-like API

5 releases (2 stable)

Uses old Rust 2015

2.0.0 Oct 28, 2018
1.0.0 Oct 28, 2018
0.2.0 Oct 28, 2018
0.1.1 Oct 28, 2018
0.1.0 Oct 28, 2018

#2126 in Rust patterns

BSD-3-Clause

22KB
421 lines

vect

Vect is a crate for providing simple and easy to use vectors for use in game development in the style of those found in the Unity game engine.

The library provides three things out of the box: the Vector trait, which contains methods like normalize, lerp, and zero, which are common across all vector implementations; the Vector2 struct, which provides a base-implementation for a 2D vector with f64 fields; and finally Vector3, which provides a base-implementation of a 3D vector, also with f64 fields.

As mentioned, the aim of this library is to be closely modeled to that found in Unity, to provide an easier transition for those already familiar. The things you can do in Unity:

var start = new Vector2(1f, 2f);
var end = new Vector2(3f, 8f);

var newVector = Vector2.lerp(start, end, t);

Should be directly translateable into this API:

use vect::prelude::*;

let start = Vector2::new(1.0, 2.0);
let end = Vector2::new(3.0, 8.0);

let newVector = Vector2::lerp(start, end, t);

And due to a quirk in how Rust handles methods, I've gone ahead and implemented all the "static methods" (aka associated functions) as actual methods, so you don't have to think about whether it's one or the other:

use vect::prelude::*;

let start = Vector2::new(1.0, 2.0);
let end = Vector2::new(3.0, 8.0);

let newVector = start.lerp(end, t);

No runtime deps