Code Monkey home page Code Monkey logo

vector's Introduction

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);

vector's People

Contributors

electriccoffee avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar

vector's Issues

Missing Vector3 methods to be added

The following methods in Vector3 have yet to be added:

  • distance(self, other: Self) -> f64 -- Returns the distance between two vectors.

  • slerp -- Spherical lerp

  • ortho_normalize(normal: &mut Vector3, tangent: &mut Vector3, binormal: Vector3) -- Normalizes normal. Normalizes tangent and makes sure it is orthogonal to normal. Normalizes binormal and makes sure it is orthogonal to both normal and tangent.

  • project -- Projects a vector onto another vector

  • project_on_plane -- Projects a vector onto a plane defined by a normal orthogonal to the plane.

  • rotate_towards -- Rotates a vector towards a target

No idea how move_towards should be implemented

This API is a bit incomplete as is.

I don't actually know how the fine folk at Unity implemented MoveTowards.

All the documentation says, is that it's similar to Lerp, but not in what way, or how.

I know that move_towards moves in discrete steps, rather than in percentage steps, but beyond that I'm at a loss.

Help wanted!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.