Modularize + Refactoring code
This commit is contained in:
parent
813280350f
commit
00ab67b212
23 changed files with 2001 additions and 87 deletions
5
engine_math/Cargo.lock
generated
Normal file
5
engine_math/Cargo.lock
generated
Normal file
|
@ -0,0 +1,5 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "engine_math"
|
||||
version = "0.0.1"
|
9
engine_math/Cargo.toml
Normal file
9
engine_math/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "engine_math"
|
||||
version = "0.0.1"
|
||||
authors = ["Florian RICHER <florian.richer@unova.fr>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
5
engine_math/src/lib.rs
Normal file
5
engine_math/src/lib.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
mod tranform;
|
||||
mod vec2;
|
||||
|
||||
pub use tranform::Transform;
|
||||
pub use vec2::Vec2;
|
40
engine_math/src/tranform.rs
Normal file
40
engine_math/src/tranform.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use super::Vec2;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Transform {
|
||||
position: Vec2,
|
||||
rotation: Vec2,
|
||||
scale: Vec2
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
pub fn new() -> Transform {
|
||||
Transform {
|
||||
position: Vec2::new(),
|
||||
rotation: Vec2::new(),
|
||||
scale: Vec2::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_rotation(&self) -> &Vec2 {
|
||||
&self.rotation
|
||||
}
|
||||
|
||||
pub fn get_position(&self) -> &Vec2 {
|
||||
&self.position
|
||||
}
|
||||
|
||||
pub fn get_scale(&self) -> &Vec2 {
|
||||
&self.scale
|
||||
}
|
||||
|
||||
pub fn translate(&mut self, x: f64, y: f64) {
|
||||
self.position.x += x;
|
||||
self.position.y += y;
|
||||
}
|
||||
|
||||
pub fn rotate(&mut self, x: f64, y: f64) {
|
||||
self.rotation.x += x;
|
||||
self.rotation.y += y;
|
||||
}
|
||||
}
|
36
engine_math/src/vec2.rs
Normal file
36
engine_math/src/vec2.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
#[derive(Debug)]
|
||||
pub struct Vec2 {
|
||||
pub x: f64,
|
||||
pub y: f64
|
||||
}
|
||||
|
||||
impl Vec2 {
|
||||
pub fn new() -> Vec2 {
|
||||
Vec2 {
|
||||
x: 0.0,
|
||||
y: 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add<Vec2> for Vec2 {
|
||||
type Output = Vec2;
|
||||
|
||||
fn add(self, b: Vec2) -> Vec2 {
|
||||
Vec2 {
|
||||
x: self.x + b.x,
|
||||
y: self.y + b.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Sub<Vec2> for Vec2 {
|
||||
type Output = Vec2;
|
||||
|
||||
fn sub(self, b: Vec2) -> Vec2 {
|
||||
Vec2 {
|
||||
x: self.x - b.x,
|
||||
y: self.y - b.y
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue