diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-12 00:15:33 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-12 00:15:33 +1000 |
commit | 72b8d26fcfcee36ca67f963b9c6a4b616e2d5d4d (patch) | |
tree | 76ab2c18db5a834c6282ab4e2afa2db33f70be27 | |
parent | a8f98ddcf5ddeb3588492f4ad8f9a289147ad7ec (diff) |
scale is a vec3 now instead of float.
-rw-r--r-- | bindgen/rust/celeritas-sys/build.rs | 13 | ||||
-rw-r--r-- | bindgen/rust/celeritas-sys/examples/glfw.rs | 227 | ||||
-rw-r--r-- | bindgen/rust/celeritas-sys/examples/main_loop.rs | 190 | ||||
-rw-r--r-- | bindgen/rust/celeritas-sys/src/lib.rs | 23 | ||||
-rw-r--r-- | bindgen/rust/examples/shaders.rs | 3 | ||||
-rw-r--r-- | bindgen/rust/src/lib.rs | 2 | ||||
-rw-r--r-- | bindgen/rust/src/ral.rs | 8 | ||||
-rw-r--r-- | examples/game_demo/game_demo.c | 9 | ||||
-rw-r--r-- | examples/skinned_animation/ex_skinned_animation.c | 2 | ||||
-rw-r--r-- | include/amalgamation.h | 1 | ||||
-rw-r--r-- | src/collision.c | 9 | ||||
-rw-r--r-- | src/collision.h | 20 | ||||
-rw-r--r-- | src/core/core.c | 4 | ||||
-rw-r--r-- | src/maths/maths.h | 10 | ||||
-rw-r--r-- | src/maths/maths_types.h | 2 | ||||
-rw-r--r-- | src/physics.h | 23 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 3 | ||||
-rw-r--r-- | src/render/immdraw.c | 10 |
18 files changed, 175 insertions, 384 deletions
diff --git a/bindgen/rust/celeritas-sys/build.rs b/bindgen/rust/celeritas-sys/build.rs index de12094..f0a1d36 100644 --- a/bindgen/rust/celeritas-sys/build.rs +++ b/bindgen/rust/celeritas-sys/build.rs @@ -3,23 +3,26 @@ use std::path::PathBuf; use bindgen::callbacks::ParseCallbacks; -const SERIALIZABLE_TYPES: &[&'static str] = &[ +const SERIALIZABLE_TYPES: &[&str] = &[ "Vec2", "Vec3", "Vec4", "Mat4", "Quat", "Transform", + "Bbox_3D", + "OBB", "DirectionalLight", "PointLight", ]; -const EQ_TYPES: &[&'static str] = &[ +const EQ_TYPES: &[&str] = &[ "BufferHandle", "TextureHandle", "MeshHandle", "MaterialHandle", "ModelHandle", ]; +const DEFAULT_TYPES: &[&str] = &["ShaderDataLayout"]; #[derive(Debug)] struct AdditionalDerives; @@ -32,6 +35,9 @@ impl ParseCallbacks for AdditionalDerives { if EQ_TYPES.contains(&info.name) { derives.extend_from_slice(&["PartialEq".to_string()]); } + if DEFAULT_TYPES.contains(&info.name) { + derives.push("Default".to_string()); + } derives } } @@ -44,8 +50,7 @@ fn main() { // println!("cargo:rustc-link-search=../../build/windows/x64/debug"); let static_lib_path = - "/Users/josh/code/CodenameVentus/deps/celeritas-core/build/macosx/arm64/debug" - .to_string(); + "/Users/josh/code/CodenameVentus/deps/celeritas-core/build/macosx/arm64/debug".to_string(); // let static_lib_path = std::env::var("CELERITAS_CORE_LIB") // .unwrap_or("../../../build/macosx/arm64/debug".to_string()); diff --git a/bindgen/rust/celeritas-sys/examples/glfw.rs b/bindgen/rust/celeritas-sys/examples/glfw.rs deleted file mode 100644 index 36abd8f..0000000 --- a/bindgen/rust/celeritas-sys/examples/glfw.rs +++ /dev/null @@ -1,227 +0,0 @@ -use std::ffi::CString; -use std::ptr::addr_of_mut; - -use celeritas_sys::*; -use egui_backend::egui::{vec2, Pos2, Rect}; -use egui_glfw as egui_backend; -use egui_glfw::glfw::{fail_on_errors, Context}; - -use egui_glfw::glfw; - -const SCREEN_WIDTH: u32 = 1000; -const SCREEN_HEIGHT: u32 = 1000; - -fn main() { - unsafe { - let mut glfw = glfw::init(glfw::fail_on_errors!()).unwrap(); - glfw.window_hint(glfw::WindowHint::ContextVersion(4, 1)); - glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true)); - glfw.window_hint(glfw::WindowHint::OpenGlProfile( - glfw::OpenGlProfileHint::Core, - )); - glfw.window_hint(glfw::WindowHint::DoubleBuffer(true)); - glfw.window_hint(glfw::WindowHint::Resizable(false)); - - let (mut window, events) = glfw - .create_window( - SCREEN_WIDTH, - SCREEN_HEIGHT, - "Egui in GLFW!", - glfw::WindowMode::Windowed, - ) - .expect("Failed to create GLFW window."); - - window.set_all_polling(true); - window.make_current(); - // glfw.set_swap_interval(glfw::SwapInterval::None); - glfw.set_swap_interval(glfw::SwapInterval::Adaptive); - - gl::load_with(|symbol| window.get_proc_address(symbol) as *const _); - - let window_ptr = window.window_ptr(); - unsafe { - // Cast the window pointer to the expected type - let window_ptr = window_ptr as *mut celeritas_sys::GLFWwindow; - Core_Bringup(window_ptr); - }; - - let mut painter = egui_backend::Painter::new(&mut window); - let egui_ctx = egui::Context::default(); - - let (width, height) = window.get_framebuffer_size(); - let native_pixels_per_point = window.get_content_scale().0; - let native_pixels_per_point = 2.0; - egui_ctx.set_pixels_per_point(2.0); - - let mut egui_input_state = egui_backend::EguiInputState::new(egui::RawInput { - screen_rect: Some(Rect::from_min_size( - Pos2::new(0f32, 0f32), - vec2(width as f32, height as f32) / native_pixels_per_point, - )), - ..Default::default() - }); - - egui_input_state.input.time = Some(0.01); - - // let triangle = triangle::Triangle::new(); - let slider = &mut 0.0; - - // C data - let camera_pos = Vec3 { - x: 18.9, - y: 10.6, - z: 11.6, - }; - let camera_front = Vec3 { - x: -0.6, - y: -0.2, - z: -0.7, - }; - let mut camera = Camera_Create( - camera_pos, - camera_front, - Vec3 { - x: 0.0, - y: 1.0, - z: 0.0, - }, - 45.0, - ); - SetCamera(camera); - - let mut cube_geo = Geo_CreateCuboid(f32x3 { - x: 2.0, - y: 2.0, - z: 2.0, - }); - let mut crate_mesh = Mesh_Create(addr_of_mut!(cube_geo), false); - let albedo_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_basecolor.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let roughness_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_roughness.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let normal_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_normal.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let ao_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_ambientOcclusion.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let name: [i8; 64] = [0; 64]; - let mut crate_mat = Material { - name: name, - kind: 0, - param_albedo: Vec3 { - x: 0.0, - y: 0.0, - z: 0.0, - }, - param_metallic: 0.0, - param_roughness: 0.0, - param_ao: 0.0, - pbr_albedo_map: albedo_map, - pbr_normal_map: normal_map, - metal_roughness_combined: true, - pbr_metallic_map: TextureHandle { raw: 99999 }, - pbr_roughness_map: roughness_map, - pbr_ao_map: ao_map, - }; - let crate_renderent = RenderEnt { - mesh: addr_of_mut!(crate_mesh), - material: addr_of_mut!(crate_mat), - affine: mat4_ident(), - casts_shadows: true, - }; - let mut render_ents: [RenderEnt; 1] = [crate_renderent]; - let mut skybox = Skybox_Default(); - - // Main rendering loop - while !window.should_close() { - glfw.poll_events(); - - egui_ctx.begin_frame(egui_input_state.input.take()); - - unsafe { - gl::ClearColor(0.455, 0.302, 0.663, 1.0); - gl::Clear(gl::COLOR_BUFFER_BIT); - gl::Clear(gl::DEPTH_TEST); - } - - Frame_Begin(); - gl::Enable(gl::DEPTH_TEST); - gl::Enable(gl::CULL_FACE); - - Camera_Update(addr_of_mut!(camera)); - SetCamera(camera); - - Skybox_Draw(addr_of_mut!(skybox), camera); - Render_RenderEntities(render_ents.as_mut_ptr(), render_ents.len()); - - // Frame_End(); - - // triangle.draw(); - - gl::Disable(gl::DEPTH_TEST); - gl::Disable(gl::CULL_FACE); - - egui::Window::new("Egui with GLFW").show(&egui_ctx, |ui| { - ui.label("Celeritas in-game editor"); - let btn_m = &mut ui.button("-"); - let btn_p = &mut ui.button("+"); - - ui.add(egui::Slider::new(slider, 0.0..=100.0).text("My value")); - - if btn_m.clicked() && *slider > 0.0 { - *slider -= 1.0; - } - - if btn_p.clicked() && *slider < 100.0 { - *slider += 1.0; - } - }); - - let egui::FullOutput { - platform_output, - textures_delta, - shapes, - .. - } = egui_ctx.end_frame(); - - //Handle cut, copy text from egui - if !platform_output.copied_text.is_empty() { - egui_backend::copy_to_clipboard(&mut egui_input_state, platform_output.copied_text); - } - - //Note: passing a bg_color to paint_jobs will clear any previously drawn stuff. - //Use this only if egui is being used for all drawing and you aren't mixing your own Open GL - //drawing calls with it. - //Since we are custom drawing an OpenGL Triangle we don't need egui to clear the background. - - let clipped_shapes = egui_ctx.tessellate(shapes, native_pixels_per_point); - painter.paint_and_update_textures( - native_pixels_per_point, - &clipped_shapes, - &textures_delta, - ); - - for (_, event) in glfw::flush_messages(&events) { - match event { - glfw::WindowEvent::Close => window.set_should_close(true), - _ => { - egui_backend::handle_event(event, &mut egui_input_state); - } - } - } - - window.swap_buffers(); - } - } -} diff --git a/bindgen/rust/celeritas-sys/examples/main_loop.rs b/bindgen/rust/celeritas-sys/examples/main_loop.rs index 65f4137..6bb923f 100644 --- a/bindgen/rust/celeritas-sys/examples/main_loop.rs +++ b/bindgen/rust/celeritas-sys/examples/main_loop.rs @@ -1,108 +1,108 @@ -use std::{ - ffi::CString, - ptr::{self, addr_of_mut}, -}; +// use std::{ +// ffi::CString, +// ptr::{self, addr_of_mut}, +// }; -use celeritas::*; +// use celeritas::*; -unsafe fn run_game() { - // init - let p: *mut GLFWwindow = ptr::null_mut(); - Core_Bringup(p); +// unsafe fn run_game() { +// // init +// let p: *mut GLFWwindow = ptr::null_mut(); +// Core_Bringup(p); - let core = get_global_core(); - let glfw_window_ptr = Core_GetGlfwWindowPtr(core); +// let core = get_global_core(); +// let glfw_window_ptr = Core_GetGlfwWindowPtr(core); - // cam pos: 18.871811 10.658584 11.643305 cam frontL -0.644326 -0.209243 -0.735569 - let camera_pos = Vec3 { - x: 18.9, - y: 10.6, - z: 11.6, - }; - let camera_front = Vec3 { - x: -0.6, - y: -0.2, - z: -0.7, - }; - let camera = Camera_Create( - camera_pos, - camera_front, - Vec3 { - x: 0.0, - y: 1.0, - z: 0.0, - }, - 45.0, - ); - SetCamera(camera); +// // cam pos: 18.871811 10.658584 11.643305 cam frontL -0.644326 -0.209243 -0.735569 +// let camera_pos = Vec3 { +// x: 18.9, +// y: 10.6, +// z: 11.6, +// }; +// let camera_front = Vec3 { +// x: -0.6, +// y: -0.2, +// z: -0.7, +// }; +// let camera = Camera_Create( +// camera_pos, +// camera_front, +// Vec3 { +// x: 0.0, +// y: 1.0, +// z: 0.0, +// }, +// 45.0, +// ); +// SetCamera(camera); - let mut cube_geo = Geo_CreateCuboid(f32x3 { - x: 2.0, - y: 2.0, - z: 2.0, - }); - let mut crate_mesh = Mesh_Create(addr_of_mut!(cube_geo), false); - let albedo_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_basecolor.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let roughness_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_roughness.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let normal_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_normal.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let ao_map = TextureLoadFromFile( - CString::new("assets/demo/crate/Wood_Crate_001_ambientOcclusion.jpg") - .unwrap() - .as_ptr() as *const i8, - ); - let name: [i8; 64] = [0; 64]; - let mut crate_mat = Material { - name: name, - kind: 0, - param_albedo: Vec3 { - x: 0.0, - y: 0.0, - z: 0.0, - }, - param_metallic: 0.0, - param_roughness: 0.0, - param_ao: 0.0, - pbr_albedo_map: albedo_map, - pbr_normal_map: normal_map, - metal_roughness_combined: true, - pbr_metallic_map: TextureHandle { raw: 99999 }, - pbr_roughness_map: roughness_map, - pbr_ao_map: ao_map, - }; - let crate_renderent = RenderEnt { - mesh: addr_of_mut!(crate_mesh), - material: addr_of_mut!(crate_mat), - affine: mat4_ident(), - casts_shadows: true, - }; - let mut render_entities: [RenderEnt; 1] = [crate_renderent]; +// let mut cube_geo = Geo_CreateCuboid(f32x3 { +// x: 2.0, +// y: 2.0, +// z: 2.0, +// }); +// let mut crate_mesh = Mesh_Create(addr_of_mut!(cube_geo), false); +// let albedo_map = TextureLoadFromFile( +// CString::new("assets/demo/crate/Wood_Crate_001_basecolor.jpg") +// .unwrap() +// .as_ptr() as *const i8, +// ); +// let roughness_map = TextureLoadFromFile( +// CString::new("assets/demo/crate/Wood_Crate_001_roughness.jpg") +// .unwrap() +// .as_ptr() as *const i8, +// ); +// let normal_map = TextureLoadFromFile( +// CString::new("assets/demo/crate/Wood_Crate_001_normal.jpg") +// .unwrap() +// .as_ptr() as *const i8, +// ); +// let ao_map = TextureLoadFromFile( +// CString::new("assets/demo/crate/Wood_Crate_001_ambientOcclusion.jpg") +// .unwrap() +// .as_ptr() as *const i8, +// ); +// let name: [i8; 64] = [0; 64]; +// let mut crate_mat = Material { +// name: name, +// kind: 0, +// param_albedo: Vec3 { +// x: 0.0, +// y: 0.0, +// z: 0.0, +// }, +// param_metallic: 0.0, +// param_roughness: 0.0, +// param_ao: 0.0, +// pbr_albedo_map: albedo_map, +// pbr_normal_map: normal_map, +// metal_roughness_combined: true, +// pbr_metallic_map: TextureHandle { raw: 99999 }, +// pbr_roughness_map: roughness_map, +// pbr_ao_map: ao_map, +// }; +// let crate_renderent = RenderEnt { +// mesh: addr_of_mut!(crate_mesh), +// material: addr_of_mut!(crate_mat), +// affine: mat4_ident(), +// casts_shadows: true, +// }; +// let mut render_entities: [RenderEnt; 1] = [crate_renderent]; - // main loop - while !ShouldExit() { - Frame_Begin(); +// // main loop +// while !ShouldExit() { +// Frame_Begin(); - Render_RenderEntities(render_entities.as_mut_ptr(), render_entities.len()); +// Render_RenderEntities(render_entities.as_mut_ptr(), render_entities.len()); - Frame_End(); - } -} +// Frame_End(); +// } +// } fn main() { println!("Running from Rust!"); - unsafe { - run_game(); - } + // unsafe { + // run_game(); + // } } diff --git a/bindgen/rust/celeritas-sys/src/lib.rs b/bindgen/rust/celeritas-sys/src/lib.rs index 90a5914..048e9f7 100644 --- a/bindgen/rust/celeritas-sys/src/lib.rs +++ b/bindgen/rust/celeritas-sys/src/lib.rs @@ -2,8 +2,6 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] -use std::ffi::c_void; - use serde::{Deserialize, Serialize}; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); @@ -81,7 +79,11 @@ impl Transform { z: 0., w: 1.0, }, - scale: 1., + scale: Vec3 { + x: 1., + y: 1., + z: 1., + }, is_dirty: true, } } @@ -116,15 +118,6 @@ impl Default for ShaderBinding { } } -impl Default for ShaderDataLayout { - fn default() -> Self { - Self { - bindings: [ShaderBinding::default(); 8], - binding_count: 0, - } - } -} - impl Default for Camera { fn default() -> Self { let camera_pos = Vec3 { @@ -137,7 +130,8 @@ impl Default for Camera { y: -0.2, z: -0.7, }; - let camera = unsafe { + + unsafe { Camera_Create( camera_pos, camera_front, @@ -148,8 +142,7 @@ impl Default for Camera { }, 45.0, ) - }; - camera + } } } diff --git a/bindgen/rust/examples/shaders.rs b/bindgen/rust/examples/shaders.rs index ad0b35f..0dede8f 100644 --- a/bindgen/rust/examples/shaders.rs +++ b/bindgen/rust/examples/shaders.rs @@ -6,6 +6,7 @@ use celeritas_sys::{ ShaderVisibility_VISIBILITY_FRAGMENT, ShaderVisibility_VISIBILITY_VERTEX, }; +#[allow(clippy::upper_case_acronyms)] #[repr(C)] struct MVP { model: Mat4, @@ -13,7 +14,7 @@ struct MVP { proj: Mat4, } -fn shader_vis_all() -> u32 { +pub fn shader_vis_all() -> u32 { ShaderVisibility_VISIBILITY_VERTEX | ShaderVisibility_VISIBILITY_FRAGMENT | ShaderVisibility_VISIBILITY_COMPUTE diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs index dd83293..4d6cb7f 100644 --- a/bindgen/rust/src/lib.rs +++ b/bindgen/rust/src/lib.rs @@ -22,7 +22,7 @@ use std::{ }; use celeritas_sys::{ - Core_Bringup, Core_Shutdown, DirectionalLight, Material, Material_Insert, Model, PointLight, + Core_Bringup, Core_Shutdown, DirectionalLight, Material, Material_Insert, PointLight, TextureHandle, Transform, }; use serde::{Deserialize, Serialize}; diff --git a/bindgen/rust/src/ral.rs b/bindgen/rust/src/ral.rs index 3ea69e2..5f7c7d1 100644 --- a/bindgen/rust/src/ral.rs +++ b/bindgen/rust/src/ral.rs @@ -1,6 +1,6 @@ //! Wrapper around the RAL code in celeritas-core -use std::ffi::{c_void, CString}; +use std::ffi::c_void; use celeritas_sys::{ BufferHandle, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender, @@ -319,8 +319,8 @@ mod test { use super::*; struct TestData { - a: [f32; 2], - b: [f32; 4], + _a: [f32; 2], + _b: [f32; 4], } impl ShaderData for TestData { fn layout() -> ShaderDataLayout { @@ -338,7 +338,7 @@ mod test { .add_attr("position", VertexAttrKind::Floatx2) .add_attr("color", VertexAttrKind::Floatx4); - let mut builder = PipelineBuilder::new("Test Pipeline".into()) + let builder = PipelineBuilder::new("Test Pipeline".into()) .add_shader_layout::<TestData>() .add_vertex_desc(vertex_desc); diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c index b3fa70d..b5db6cd 100644 --- a/examples/game_demo/game_demo.c +++ b/examples/game_demo/game_demo.c @@ -107,15 +107,16 @@ int main() { // Shadow_Run(entities, entity_count); // Quat rot = quat_from_axis_angle(VEC3_X, HALF_PI, true); - // Immdraw_Sphere(transform_create(VEC3_ZERO, quat_ident(), 0.5), vec4(1.0, 0.0, 0.0, 1.0), - // false); Immdraw_Cuboid(transform_create(vec3(2.0, 0.0, 0.0), quat_ident(), 1.0), - // vec4(1.0, 0.0, 0.0, 1.0), false); + Immdraw_Sphere(transform_create(VEC3_ZERO, quat_ident(), vec3(1.0, 3.0, 1.0)), + vec4(1.0, 0.0, 0.0, 1.0), true); + Immdraw_Cuboid(transform_create(vec3(4.0, 0.0, 0.0), quat_ident(), vec3(3.0, 0.5, 3.0)), + vec4(1.0, 0.0, 0.0, 1.0), true); if (draw_debug) { // draw the player model with shadows Render_RenderEntities(render_entities->data, render_entities->len); // Render_DrawTerrain(); - Skybox_Draw(&skybox, cam); + // Skybox_Draw(&skybox, cam); } else { Shadow_DrawDebugQuad(); } diff --git a/examples/skinned_animation/ex_skinned_animation.c b/examples/skinned_animation/ex_skinned_animation.c index 25fc097..672e0d2 100644 --- a/examples/skinned_animation/ex_skinned_animation.c +++ b/examples/skinned_animation/ex_skinned_animation.c @@ -64,7 +64,7 @@ int main() { // m->bones->data[1].transform_components.rotation = rot; // quat rot = quat_ident(); - Transform tf = transform_create(VEC3_ZERO, quat_ident(), 1.0); + // Transform tf = transform_create(VEC3_ZERO, quat_ident(), 1.0); // TODO: Drawing should still just use the PBR pipeline diff --git a/include/amalgamation.h b/include/amalgamation.h index 51ea382..f13796a 100644 --- a/include/amalgamation.h +++ b/include/amalgamation.h @@ -14,6 +14,7 @@ #include "immdraw.h" #include "maths_types.h" #include "maths.h" +#include "physics.h" #include "skybox.h" #include "shadows.h" #include "loaders.h" diff --git a/src/collision.c b/src/collision.c new file mode 100644 index 0000000..81cbcfc --- /dev/null +++ b/src/collision.c @@ -0,0 +1,9 @@ +#include "immdraw.h" +#include "maths.h" +#include "maths_types.h" +#include "physics.h" + +PUB void Debug_DrawOBB(OBB obb) { + Transform t = transform_create(obb.center, obb.rotation, vec3_sub(obb.bbox.max, obb.bbox.min)); + Immdraw_Cuboid(t, vec4(0.0, 0.8, 0.1, 1.0), true); +} diff --git a/src/collision.h b/src/collision.h deleted file mode 100644 index 4ac9ec3..0000000 --- a/src/collision.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "geometry.h" - -enum ColliderType { - CuboidCollider, - SphereCollider, -}; - -/** @brief generic collider structure */ -typedef struct Collider { - u64 id; // ? Replace with handle? - enum ColliderType shape; - union collider_data { - Cuboid cuboid; - Sphere sphere; - } geometry; - Transform transform; - u8 layer; - bool on_ground; -} Collider; diff --git a/src/core/core.c b/src/core/core.c index af7daeb..64f59f3 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -76,8 +76,6 @@ Core* get_global_core() { return &g_core; } GLFWwindow* Core_GetGlfwWindowPtr(Core* core) { return g_core.window; } -struct Renderer* Core_GetRenderer(Core* core) { - return core->renderer; -} +struct Renderer* Core_GetRenderer(Core* core) { return core->renderer; } Model* Model_Get(ModelHandle h) { return Model_pool_get(&g_core.models, h); } diff --git a/src/maths/maths.h b/src/maths/maths.h index 9e71f79..fc23517 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -147,11 +147,11 @@ static Mat4 mat4_translation(Vec3 position) { return out_matrix; } -static Mat4 mat4_scale(f32 scale) { +static Mat4 mat4_scale(Vec3 scale) { Mat4 out_matrix = mat4_ident(); - out_matrix.data[0] = scale; - out_matrix.data[5] = scale; - out_matrix.data[10] = scale; + out_matrix.data[0] = scale.x; + out_matrix.data[5] = scale.y; + out_matrix.data[10] = scale.z; return out_matrix; } @@ -307,7 +307,7 @@ static inline Mat4 mat4_look_at(Vec3 position, Vec3 target, Vec3 up) { .scale = 1.0, \ .is_dirty = false }) -static Transform transform_create(Vec3 pos, Quat rot, f32 scale) { +static Transform transform_create(Vec3 pos, Quat rot, Vec3 scale) { return (Transform){ .position = pos, .rotation = rot, .scale = scale, .is_dirty = true }; } diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h index 2f84774..ef1fe4a 100644 --- a/src/maths/maths_types.h +++ b/src/maths/maths_types.h @@ -53,7 +53,7 @@ typedef Bbox_3D Aabb_3D; typedef struct Transform { Vec3 position; Quat rotation; - f32 scale; + Vec3 scale; bool is_dirty; } Transform; diff --git a/src/physics.h b/src/physics.h index e0e3b89..3485d1b 100644 --- a/src/physics.h +++ b/src/physics.h @@ -20,4 +20,25 @@ physics_world physics_init(physics_settings settings); void physics_shutdown(physics_world* phys_world); /** @brief perform one or more simulation steps */ -void physics_system_update(physics_world* phys_world, f64 deltatime);
\ No newline at end of file +void physics_system_update(physics_world* phys_world, f64 deltatime); + +// enum ColliderType { +// CuboidCollider, +// SphereCollider, +// }; + +/** @brief Oriented Bounding Box */ +typedef struct OBB { + Vec3 center; + Bbox_3D bbox; + Quat rotation; +} OBB; + +PUB void Debug_DrawOBB(OBB obb); + +/** @brief generic collider structure */ +typedef struct Collider { + u64 id; // ? Replace with handle? + OBB shape; // NOTE: We're only supporting the one collider type for now + bool on_ground; +} Collider; diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index 97fd362..3822220 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -57,8 +57,7 @@ bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, } // All of these are no-ops in OpenGL -void GPU_Backend_Shutdown() { /* TODO */ -} +void GPU_Backend_Shutdown() { /* TODO */ } bool GPU_Device_Create(GPU_Device* out_device) { return true; } void GPU_Device_Destroy(GPU_Device* device) {} bool GPU_Swapchain_Create(GPU_Swapchain* out_swapchain) { return true; } diff --git a/src/render/immdraw.c b/src/render/immdraw.c index cb823d3..142087a 100644 --- a/src/render/immdraw.c +++ b/src/render/immdraw.c @@ -86,6 +86,16 @@ void Immdraw_Primitive(Transform tf, f32 size, Vec4 colour, bool wireframe, Mesh // bind pipeline GPU_EncodeBindPipeline(enc, imm->colour_pipeline); + // TODO: implement wireframe in other apis +#if defined(CEL_REND_BACKEND_OPENGL) +#include <glad/glad.h> + if (wireframe) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } +#endif + // update uniforms ImmediateUniforms uniforms = { .model = transform_to_mat(&tf), |