mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-10 01:28:41 -06:00
fuck
This commit is contained in:
parent
29166c3b95
commit
56c2f0de88
|
@ -1,4 +1,4 @@
|
|||
use glam::{Mat4, Vec3};
|
||||
use glam::{Mat4, Vec3, EulerRot};
|
||||
use shipyard::{Component, ViewMut, View, IntoIter, Workload, IntoWorkload};
|
||||
use std::f32::consts::PI;
|
||||
use crate::{transform::Transform, events::WindowResizedEvent};
|
||||
|
@ -40,8 +40,14 @@ fn update_view_matrix(
|
|||
) {
|
||||
for (camera, transform) in (&mut vm_camera, v_transform.inserted_or_modified()).iter() {
|
||||
let (_, rotation, translation) = transform.0.to_scale_rotation_translation();
|
||||
let dir = rotation * Vec3::Z; //this may be incorrect!
|
||||
camera.view_matrix = Mat4::look_to_rh(translation, dir, camera.up);
|
||||
//let direction = rotation * Vec3::Z; //this may be incorrect!
|
||||
let (yaw, pitch, _) = rotation.to_euler(EulerRot::YXZ);
|
||||
let direction= Vec3::new(
|
||||
yaw.cos() * pitch.cos(),
|
||||
pitch.sin(),
|
||||
yaw.sin() * pitch.cos()
|
||||
);
|
||||
camera.view_matrix = Mat4::look_to_rh(translation, direction, camera.up);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use glam::{Vec3, Mat4, EulerRot, Quat};
|
||||
use glam::{Vec3, Mat4, Quat, EulerRot};
|
||||
use shipyard::{Component, View, ViewMut, IntoIter, UniqueView};
|
||||
use crate::{transform::Transform, input::Inputs, settings::GameSettings};
|
||||
|
||||
|
@ -12,9 +12,24 @@ pub fn update_controllers(
|
|||
settings: UniqueView<GameSettings>,
|
||||
) {
|
||||
for (_, mut transform) in (&controllers, &mut transforms).iter() {
|
||||
let (scale, mut rotation, translation) = transform.0.to_scale_rotation_translation();
|
||||
let look = inputs.look * settings.mouse_sensitivity * -1.;
|
||||
rotation *= Quat::from_euler(EulerRot::YXZ, look.x, look.y, 0.);
|
||||
let (scale, mut rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
||||
let look = inputs.look * settings.mouse_sensitivity;
|
||||
|
||||
//rotation *= Quat::from_axis_angle(Vec3::Y, look.x);
|
||||
|
||||
//old way
|
||||
// rotation = rotation.normalize();
|
||||
// rotation *= Quat::from_euler(EulerRot::ZYX, 0., look.x, look.y).normalize();
|
||||
// rotation = rotation.normalize();
|
||||
|
||||
// let direction = (rotation * Vec3::Z).normalize();
|
||||
// let camera_right = Vec3::Y.cross(direction).normalize();
|
||||
// let camera_up = direction.cross(camera_right);
|
||||
// rotation *= Quat::from_axis_angle(Vec3::Y, look.x);
|
||||
// rotation *= Quat::from_axis_angle(camera_right, look.y);
|
||||
|
||||
//translation += (rotation * Vec3::X) / 4.;
|
||||
|
||||
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub trait AssetPaths {
|
|||
|
||||
#[derive(Clone, Copy, Debug, EnumIter)]
|
||||
#[repr(u8)]
|
||||
pub enum BlockTextures {
|
||||
pub enum BlockTexture {
|
||||
Stone = 0,
|
||||
Dirt = 1,
|
||||
GrassTop = 2,
|
||||
|
@ -30,7 +30,7 @@ pub enum BlockTextures {
|
|||
Snow = 11,
|
||||
GrassSideSnow = 12,
|
||||
}
|
||||
impl AssetPaths for BlockTextures {
|
||||
impl AssetPaths for BlockTexture {
|
||||
fn file_name(self) -> &'static str {
|
||||
match self {
|
||||
Self::Stone => "stone.png",
|
||||
|
@ -61,7 +61,7 @@ pub fn load_prefabs(
|
|||
renderer: NonSendSync<UniqueView<Renderer>>
|
||||
) {
|
||||
storages.add_unique_non_send_sync(BlockTexturesPrefab(
|
||||
load_texture2darray_prefab::<BlockTextures, _>(
|
||||
load_texture2darray_prefab::<BlockTexture, _>(
|
||||
"./assets/blocks/".into(),
|
||||
&renderer.display,
|
||||
MipmapsOption::AutoGeneratedMipmaps
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use strum::EnumIter;
|
||||
use crate::prefabs::BlockTexture;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter)]
|
||||
#[repr(u8)]
|
||||
|
@ -9,3 +10,75 @@ pub enum Block {
|
|||
Grass,
|
||||
Sand,
|
||||
}
|
||||
impl Block {
|
||||
pub const fn descriptor(self) -> BlockDescriptor {
|
||||
match self {
|
||||
Self::Air => BlockDescriptor {
|
||||
name: "air",
|
||||
render: RenderType::None,
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: false,
|
||||
},
|
||||
Self::Stone => BlockDescriptor {
|
||||
name: "stone",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Stone)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
},
|
||||
_ => todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct BlockDescriptor {
|
||||
pub name: &'static str,
|
||||
pub render: RenderType,
|
||||
pub collision: CollisionType,
|
||||
pub raycast_collision: bool,
|
||||
}
|
||||
impl BlockDescriptor {
|
||||
pub fn of(block: Block) -> Self {
|
||||
block.descriptor()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct CubeTexture {
|
||||
pub top: BlockTexture,
|
||||
pub bottom: BlockTexture,
|
||||
pub left: BlockTexture,
|
||||
pub right: BlockTexture,
|
||||
pub front: BlockTexture,
|
||||
pub back: BlockTexture,
|
||||
}
|
||||
impl CubeTexture {
|
||||
pub const fn top_sides_bottom(top: BlockTexture, sides: BlockTexture, bottom: BlockTexture) -> Self {
|
||||
Self {
|
||||
top,
|
||||
bottom,
|
||||
left: sides,
|
||||
right: sides,
|
||||
front: sides,
|
||||
back: sides,
|
||||
}
|
||||
}
|
||||
pub const fn horizontal_vertical(horizontal: BlockTexture, vertical: BlockTexture) -> Self {
|
||||
Self::top_sides_bottom(vertical, horizontal, vertical)
|
||||
}
|
||||
pub const fn all(texture: BlockTexture) -> Self {
|
||||
Self::horizontal_vertical(texture, texture)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum CollisionType {
|
||||
None,
|
||||
Solid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum RenderType {
|
||||
None,
|
||||
SolidBlock(CubeTexture)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ pub fn generate_world(_position: IVec3, _seed: u32) -> BlockData {
|
|||
blocks[0][0][0] = Block::Stone;
|
||||
blocks[1][0][0] = Block::Stone;
|
||||
blocks[0][1][0] = Block::Stone;
|
||||
blocks[0][2][0] = Block::Stone;
|
||||
blocks[0][0][1] = Block::Stone;
|
||||
//TODO actual world generation
|
||||
blocks
|
||||
|
|
Loading…
Reference in a new issue