create bevy_math crate and move math types there

This commit is contained in:
Carter Anderson 2020-07-16 16:51:45 -07:00
parent d9adea1b5e
commit 1110f9b877
56 changed files with 78 additions and 74 deletions

View File

@ -26,6 +26,7 @@ bevy_diagnostic = { path = "crates/bevy_diagnostic" }
bevy_ecs = { path = "crates/bevy_ecs" }
bevy_gltf = { path = "crates/bevy_gltf" }
bevy_input = { path = "crates/bevy_input" }
bevy_math = { path = "crates/bevy_math" }
bevy_pbr = { path = "crates/bevy_pbr" }
bevy_property = { path = "crates/bevy_property" }
bevy_render = { path = "crates/bevy_render" }
@ -37,7 +38,6 @@ bevy_ui = { path = "crates/bevy_ui" }
bevy_window = { path = "crates/bevy_window" }
bevy_wgpu = { path = "crates/bevy_wgpu", optional = true }
bevy_winit = { path = "crates/bevy_winit", optional = true }
glam = "0.8.7"
# other
log = { version = "0.4", features = ["release_max_level_info"] }

View File

@ -10,4 +10,4 @@ bevy_derive = { path = "../bevy_derive" }
bevy_ecs = { path = "../bevy_ecs" }
bevy_property = { path = "../bevy_property" }
bevy_type_registry = { path = "../bevy_type_registry" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }

View File

@ -1,4 +1,4 @@
use glam::{Mat4, Vec2, Vec3, Vec4};
use bevy_math::{Mat4, Vec2, Vec3, Vec4};
pub use bevy_derive::Bytes;
@ -172,7 +172,7 @@ where
mod tests {
use super::{Bytes, FromBytes};
use glam::{Mat4, Vec2, Vec3, Vec4};
use bevy_math::{Mat4, Vec2, Vec3, Vec4};
fn test_round_trip<T: Bytes + FromBytes + std::fmt::Debug + PartialEq>(value: T) {
let mut bytes = vec![0; value.byte_len()];

View File

@ -1,13 +1,12 @@
pub mod bytes;
pub mod float_ord;
pub mod time;
pub mod math;
use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_ecs::IntoQuerySystem;
use bevy_type_registry::RegisterType;
use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
use time::{time_system, timer_system, Time, Timer};
use bevy_math::{Vec3, Vec2, Mat3, Mat4, Quat};
#[derive(Default)]
pub struct CorePlugin;

View File

@ -7,4 +7,4 @@ edition = "2018"
[dependencies]
bevy_app = { path = "../bevy_app" }
bevy_ecs = { path = "../bevy_ecs" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }

View File

@ -2,7 +2,7 @@ use super::keyboard::ElementState;
use crate::Input;
use bevy_app::{EventReader, Events};
use bevy_ecs::{Res, ResMut};
use glam::Vec2;
use bevy_math::Vec2;
#[derive(Debug, Clone)]
pub struct MouseButtonInput {

View File

@ -0,0 +1,10 @@
[package]
name = "bevy_math"
version = "0.1.0"
authors = ["Carter Anderson <mcanders1@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
glam = { version = "0.8.7", features = ["serde"] }

View File

@ -1,4 +1,4 @@
use glam::{Mat4, Vec3};
use crate::{Mat4, Vec3};
pub trait FaceToward {
fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self;

View File

@ -1,3 +1,4 @@
mod face_toward;
pub use face_toward::*;
pub use glam::*;

View File

@ -16,4 +16,4 @@ bevy_property = { path = "../bevy_property" }
bevy_transform = { path = "../bevy_transform" }
bevy_window = { path = "../bevy_window" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }

View File

@ -2,7 +2,7 @@ use bevy_core::bytes::Byteable;
use bevy_property::Properties;
use bevy_render::{CameraProjection, Color, PerspectiveProjection};
use bevy_transform::components::Translation;
use glam::Mat4;
use bevy_math::Mat4;
use std::ops::Range;
#[derive(Properties)]

View File

@ -1,14 +1,14 @@
[package]
name = "bevy_property"
version = "0.1.0"
authors = ["Carter Anderson <mcanders1@gmail.com>"]
edition = "2018"
name = "bevy_property"
version = "0.1.0"
[dependencies]
serde = "1"
bevy_ecs = {path = "../bevy_ecs"}
bevy_math = {path = "../bevy_math"}
bevy_property_derive = {path = "bevy_property_derive"}
erased-serde = "0.3"
bevy_property_derive = { path = "bevy_property_derive" }
ron = { git = "https://github.com/ron-rs/ron", rev = "35355ba7eb495f07282162826c29873154c2fa14" }
glam = { version = "0.8.7", features = ["serde"] }
bevy_ecs = { path = "../bevy_ecs" }
smallvec = { version = "1.4", features = ["serde"] }
ron = {git = "https://github.com/ron-rs/ron", rev = "35355ba7eb495f07282162826c29873154c2fa14"}
serde = "1"
smallvec = {version = "1.4", features = ["serde"]}

View File

@ -1,5 +1,5 @@
use crate::impl_property;
use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
use bevy_math::{Mat3, Mat4, Quat, Vec2, Vec3};
impl_property!(Vec2);
impl_property!(Vec3);

View File

@ -26,7 +26,7 @@ png = "0.16.0"
# misc
log = { version = "0.4", features = ["release_max_level_info"] }
uuid = { version = "0.8", features = ["v4", "serde"] }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }
serde = { version = "1", features = ["derive"] }
bitflags = "1.0"
smallvec = "1.4.0"

View File

@ -3,7 +3,7 @@ use bevy_app::{EventReader, Events};
use bevy_ecs::{Component, Local, Query, Res};
use bevy_property::Properties;
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
use glam::Mat4;
use bevy_math::Mat4;
#[derive(Default, Debug, Properties)]
pub struct Camera {

View File

@ -1,5 +1,5 @@
use bevy_property::{Properties, Property};
use glam::Mat4;
use bevy_math::Mat4;
use serde::{Deserialize, Serialize};
pub trait CameraProjection {

View File

@ -6,7 +6,7 @@ use crate::{
use bevy_asset::Handle;
use bevy_core::bytes::{Byteable, Bytes};
use bevy_property::Property;
use glam::Vec4;
use bevy_math::Vec4;
use serde::{Deserialize, Serialize};
use std::ops::{Add, AddAssign};

View File

@ -11,7 +11,7 @@ use bevy_app::{EventReader, Events};
use bevy_asset::{AssetEvent, Assets, Handle};
use bevy_core::bytes::AsBytes;
use bevy_ecs::{Local, Query, Res, ResMut};
use glam::*;
use bevy_math::*;
use std::{borrow::Cow, collections::HashSet};
use thiserror::Error;
@ -169,7 +169,7 @@ impl Mesh {
pub mod shape {
use super::{Mesh, VertexAttribute};
use crate::pipeline::state_descriptors::PrimitiveTopology;
use glam::*;
use bevy_math::*;
pub struct Cube {
pub size: f32,

View File

@ -1,5 +1,5 @@
use crate::Color;
use glam::{Mat4, Vec2, Vec3, Vec4};
use bevy_math::{Mat4, Vec2, Vec3, Vec4};
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum VertexFormat {
Uchar2 = 1,

View File

@ -4,7 +4,7 @@ use bevy_asset::Handle;
use bevy_core::bytes::{Byteable, Bytes};
pub use bevy_derive::{RenderResource, RenderResources};
use glam::{Mat4, Vec2, Vec3, Vec4};
use bevy_math::{Mat4, Vec2, Vec3, Vec4};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum RenderResourceType {

View File

@ -1,7 +1,7 @@
use super::Texture;
use anyhow::Result;
use bevy_asset::AssetLoader;
use glam::Vec2;
use bevy_math::Vec2;
use std::path::Path;
#[derive(Clone, Default)]

View File

@ -6,7 +6,7 @@ use crate::{
use bevy_app::{EventReader, Events};
use bevy_asset::{AssetEvent, Assets, Handle};
use bevy_ecs::{Res, ResMut};
use glam::Vec2;
use bevy_math::Vec2;
use std::collections::HashSet;
pub const TEXTURE_ASSET_INDEX: usize = 0;

View File

@ -15,7 +15,7 @@ bevy_type_registry = { path = "../bevy_type_registry" }
bevy_render = { path = "../bevy_render" }
bevy_transform = { path = "../bevy_transform" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }
rectangle-pack = "0.1"
thiserror = "1.0"
guillotiere = "0.5.2"

View File

@ -1,4 +1,4 @@
use glam::{Vec2, Vec3};
use bevy_math::{Vec2, Vec3};
#[derive(Debug)]
pub enum Collision {

View File

@ -1,7 +1,7 @@
use crate::{Rect, TextureAtlas};
use bevy_asset::{Assets, Handle};
use bevy_render::texture::Texture;
use glam::Vec2;
use bevy_math::Vec2;
use guillotiere::{size2, AllocId, Allocation, AtlasAllocator};
use std::collections::HashMap;

View File

@ -24,7 +24,7 @@ use bevy_render::{
render_graph::RenderGraph,
shader::asset_shader_defs_system,
};
use glam::Vec2;
use bevy_math::Vec2;
use sprite::sprite_system;
#[derive(Default)]

View File

@ -1,5 +1,5 @@
use bevy_core::bytes::Byteable;
use glam::Vec2;
use bevy_math::Vec2;
/// A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere (top-left, bottom-left, etc)
#[repr(C)]

View File

@ -6,7 +6,7 @@ use bevy_render::{
render_resource::{RenderResource, RenderResources},
texture::Texture,
};
use glam::Vec2;
use bevy_math::Vec2;
#[repr(C)]
#[derive(Default, RenderResources, RenderResource)]

View File

@ -6,7 +6,7 @@ use bevy_render::{
texture::Texture,
Color,
};
use glam::Vec2;
use bevy_math::Vec2;
use std::collections::HashMap;
#[derive(RenderResources)]

View File

@ -1,7 +1,7 @@
use crate::{Rect, TextureAtlas};
use bevy_asset::{Assets, Handle};
use bevy_render::texture::Texture;
use glam::Vec2;
use bevy_math::Vec2;
use rectangle_pack::{
contains_smallest_box, pack_rects, volume_heuristic, GroupedRectsToPlace, PackedLocation,
RectToInsert, TargetBin,

View File

@ -14,5 +14,5 @@ bevy_render = { path = "../bevy_render" }
bevy_sprite = { path = "../bevy_sprite" }
ab_glyph = "0.2.2"
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }
anyhow = "1.0"

View File

@ -12,7 +12,7 @@ use bevy_render::{
Color,
};
use bevy_sprite::{TextureAtlas, TextureAtlasSprite};
use glam::{Mat4, Vec3};
use bevy_math::{Mat4, Vec3};
pub struct TextStyle {
pub font_size: f32,

View File

@ -1,6 +1,6 @@
use ab_glyph::{FontVec, Glyph, InvalidFont, OutlinedGlyph, Point, PxScale, ScaleFont};
use bevy_render::{texture::Texture, Color};
use glam::Vec2;
use bevy_math::Vec2;
pub struct Font {
pub font: FontVec,

View File

@ -1,7 +1,7 @@
use bevy_asset::{Assets, Handle};
use bevy_render::texture::Texture;
use bevy_sprite::{DynamicTextureAtlasBuilder, TextureAtlas};
use glam::Vec2;
use bevy_math::Vec2;
use std::collections::HashMap;
pub struct FontAtlas {

View File

@ -4,7 +4,7 @@ use bevy_asset::{Assets, Handle};
use bevy_core::float_ord::FloatOrd;
use bevy_render::texture::Texture;
use bevy_sprite::TextureAtlas;
use glam::Vec2;
use bevy_math::Vec2;
use std::collections::HashMap;
// work around rust's f32 order/hash limitations

View File

@ -11,7 +11,7 @@ bevy_app = { path = "../bevy_app"}
bevy_ecs = { path = "../bevy_ecs"}
bevy_property = { path = "../bevy_property" }
bevy_type_registry = { path = "../bevy_type_registry" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }
log = "0.4"
smallvec = { version = "1.4", features = ["serde"] }

View File

@ -1,4 +1,4 @@
use crate::math::Mat4;
use bevy_math::Mat4;
use bevy_property::Properties;
use std::fmt;

View File

@ -1,4 +1,4 @@
use crate::math::Vec3;
use bevy_math::Vec3;
use bevy_property::Properties;
use std::fmt;

View File

@ -1,4 +1,4 @@
use crate::math::Quat;
use bevy_math::Quat;
use bevy_property::Properties;
#[derive(Debug, PartialEq, Clone, Copy, Properties)]

View File

@ -1,4 +1,4 @@
use crate::math::Mat4;
use bevy_math::Mat4;
use bevy_property::Properties;
use std::fmt;

View File

@ -1,4 +1,4 @@
use crate::math::Vec3;
use bevy_math::Vec3;
use bevy_property::Properties;
#[derive(Debug, PartialEq, Clone, Copy, Properties)]

View File

@ -1,7 +1,5 @@
pub use glam as math;
pub mod hierarchy;
pub mod components;
pub mod hierarchy;
pub mod local_transform_systems;
pub mod transform_propagate_system;
pub mod transform_systems;

View File

@ -1,10 +1,8 @@
#![allow(dead_code)]
use crate::{
components::*,
math::{Mat4, Quat, Vec3},
};
use crate::components::*;
use bevy_ecs::{IntoQuerySystem, Query, System, Without};
use bevy_math::{Vec3, Mat4, Quat};
// TODO: "on changed" for all of these systems
pub fn local_transform_translation_system(
@ -180,7 +178,7 @@ pub fn local_transform_systems() -> Vec<Box<dyn System>> {
#[cfg(test)]
mod test {
use super::*;
use crate::math::{Mat4, Quat, Vec3};
use bevy_math::{Mat4, Quat, Vec3};
use bevy_ecs::{Resources, Schedule, World};
#[test]

View File

@ -72,7 +72,7 @@ mod test {
use super::*;
use crate::transform_systems;
use bevy_ecs::{Resources, Schedule, World};
use glam::{Mat4, Vec3};
use bevy_math::{Mat4, Vec3};
#[test]
fn did_propagate() {

View File

@ -1,10 +1,8 @@
#![allow(dead_code)]
use crate::{
components::*,
math::{Mat4, Quat, Vec3},
};
use crate::components::*;
use bevy_ecs::{IntoQuerySystem, Query, System, Without};
use bevy_math::{Mat4, Quat, Vec3};
// TODO: on changed for all of these systems
pub fn transform_translation_system(
@ -200,8 +198,8 @@ pub fn transform_systems() -> Vec<Box<dyn System>> {
#[cfg(test)]
mod test {
use super::*;
use crate::math::{Mat4, Quat, Vec3};
use bevy_ecs::{Resources, Schedule, World};
use bevy_math::{Mat4, Quat, Vec3};
#[test]
fn correct_world_transformation() {

View File

@ -16,4 +16,4 @@ bevy_transform = { path = "../bevy_transform" }
bevy_render = { path = "../bevy_render" }
bevy_window = { path = "../bevy_window" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }

View File

@ -1,7 +1,7 @@
use super::{Anchors, Margins};
use bevy_render::render_resource::RenderResources;
use bevy_transform::prelude::Translation;
use glam::{Vec2, Vec3};
use bevy_math::{Vec2, Vec3};
#[derive(Debug, Clone)]
enum MarginGrowDirection {

View File

@ -5,7 +5,7 @@ use bevy_transform::{
prelude::{Children, Parent, Translation},
};
use bevy_window::Windows;
use glam::Vec2;
use bevy_math::Vec2;
pub const UI_Z_STEP: f32 = 0.001;

View File

@ -7,5 +7,5 @@ edition = "2018"
[dependencies]
bevy_app = { path = "../bevy_app" }
bevy_ecs = { path = "../bevy_ecs" }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }
uuid = { version = "0.8", features = ["v4", "serde"] }

View File

@ -1,5 +1,5 @@
use super::{WindowDescriptor, WindowId};
use glam::Vec2;
use bevy_math::Vec2;
/// A window event that is sent whenever a window has been resized.
#[derive(Debug, Clone)]

View File

@ -11,5 +11,5 @@ bevy_input = { path = "../bevy_input" }
bevy_window = { path = "../bevy_window" }
winit = { git = "https://github.com/rust-windowing/winit/", default-features = false, features = ["x11"] }
glam = "0.8.7"
bevy_math = { path = "../bevy_math" }
log = { version = "0.4", features = ["release_max_level_info"] }

View File

@ -12,7 +12,7 @@ use bevy_ecs::Resources;
use bevy_window::{
CreateWindow, CursorMoved, Window, WindowCloseRequested, WindowCreated, WindowResized, Windows,
};
use glam::Vec2;
use bevy_math::Vec2;
use winit::{
event,
event::{DeviceEvent, WindowEvent},

View File

@ -13,6 +13,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// create a cube and a plane mesh
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
let plane_handle = meshes.add(Mesh::from(shape::Plane { size: 10.0 }));

View File

@ -8,6 +8,7 @@ impl AddDefaultPlugins for AppBuilder {
fn add_default_plugins(&mut self) -> &mut Self {
self.add_plugin(bevy_type_registry::TypeRegistryPlugin::default());
self.add_plugin(bevy_core::CorePlugin::default());
self.add_plugin(bevy_transform::TransformPlugin::default());
self.add_plugin(bevy_diagnostic::DiagnosticsPlugin::default());
self.add_plugin(bevy_input::InputPlugin::default());
self.add_plugin(bevy_window::WindowPlugin::default());

View File

@ -43,8 +43,6 @@ pub mod prelude;
pub use add_default_plugins::*;
pub use bevy_app as app;
pub use glam as math;
pub use bevy_asset as asset;
pub use bevy_audio as audio;
pub use bevy_core as core;
@ -52,6 +50,7 @@ pub use bevy_diagnostic as diagnostic;
pub use bevy_ecs as ecs;
pub use bevy_gltf as gltf;
pub use bevy_input as input;
pub use bevy_math as math;
pub use bevy_pbr as pbr;
pub use bevy_property as property;
pub use bevy_render as render;

View File

@ -7,7 +7,6 @@ pub use crate::{
audio::{AudioOutput, AudioSource},
core::{
time::{Time, Timer},
math::FaceToward,
},
diagnostic::DiagnosticsPlugin,
ecs::{
@ -16,7 +15,7 @@ pub use crate::{
World, WorldBuilderSource,
},
input::{keyboard::KeyCode, mouse::MouseButton, Input},
math::{self, Mat3, Mat4, Quat, Vec2, Vec3, Vec4},
math::{self, Mat3, Mat4, Quat, Vec2, Vec3, Vec4, FaceToward},
pbr::{entity::*, light::Light, material::StandardMaterial},
property::{DynamicProperties, Properties, PropertiesVal, Property, PropertyVal},
render::{