summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-11 23:00:26 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-11 23:00:26 +1000
commitb03bde3d412148cd573f5f14012cdd270f309947 (patch)
tree848af582079a60787cc5a5f8138e7ca6d508f2ee /examples
parent48a703e52490cb52fd32e54e3e37f7e70462a267 (diff)
starting work on immediate mode drawing
Diffstat (limited to 'examples')
-rw-r--r--examples/game_demo/game_demo.c24
-rw-r--r--examples/skinned_animation/ex_skinned_animation.c99
2 files changed, 41 insertions, 82 deletions
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c
index bc7e0f6..22af64e 100644
--- a/examples/game_demo/game_demo.c
+++ b/examples/game_demo/game_demo.c
@@ -7,10 +7,12 @@
#include "camera.h"
#include "core.h"
#include "grid.h"
+#include "immdraw.h"
#include "input.h"
#include "keys.h"
#include "loaders.h"
#include "maths.h"
+#include "maths_types.h"
#include "pbr.h"
#include "primitives.h"
#include "ral_types.h"
@@ -98,21 +100,23 @@ int main() {
// BEGIN Draw calls
RenderEnt_darray_clear(render_entities); // we re-extract every frame
- Quat rot = quat_from_axis_angle(VEC3_X, -HALF_PI, true);
+ // Quat rot = quat_from_axis_angle(VEC3_X, -HALF_PI, true);
// Mat4 affine = mat4_rotation(rot);
Mat4 affine = mat4_ident();
ModelExtractRenderEnts(render_entities, cube_handle, affine, REND_ENT_CASTS_SHADOWS);
// Shadow_Run(entities, entity_count);
-
- if (draw_debug) {
- // draw the player model with shadows
- Render_RenderEntities(render_entities->data, render_entities->len);
- // Render_DrawTerrain();
- Skybox_Draw(&skybox, cam);
- } else {
- Shadow_DrawDebugQuad();
- }
+ Quat rot = quat_from_axis_angle(VEC3_X, HALF_PI, true);
+ Immdraw_Sphere(transform_create(VEC3_ZERO, rot, 1.0), 1.0, vec4(1.0, 0.0, 0.0, 1.0), false);
+
+ // if (draw_debug) {
+ // // draw the player model with shadows
+ // Render_RenderEntities(render_entities->data, render_entities->len);
+ // // Render_DrawTerrain();
+ // Skybox_Draw(&skybox, cam);
+ // } else {
+ // Shadow_DrawDebugQuad();
+ // }
// Terrain_Draw(terrain);
// Grid_Draw();
diff --git a/examples/skinned_animation/ex_skinned_animation.c b/examples/skinned_animation/ex_skinned_animation.c
index c31e93c..7704b99 100644
--- a/examples/skinned_animation/ex_skinned_animation.c
+++ b/examples/skinned_animation/ex_skinned_animation.c
@@ -1,122 +1,77 @@
#include <assert.h>
#include <glfw3.h>
-#include "../example_scene.h"
-#include "animation.h"
#include "camera.h"
#include "core.h"
-#include "input.h"
-#include "keys.h"
+#include "loaders.h"
#include "log.h"
#include "maths.h"
#include "maths_types.h"
-#include "primitives.h"
-#include "render.h"
-#include "render_backend.h"
#include "render_types.h"
-typedef struct game_state {
- camera camera;
- vec3 camera_euler;
- bool first_mouse_update; // so the camera doesnt lurch when you run the first
- // process_camera_rotation
-} game_state;
-
-void update_camera_rotation(input_state* input, game_state* game, camera* cam);
-
int main() {
double currentFrame = glfwGetTime();
double lastFrame = currentFrame;
double deltaTime;
- core* core = core_bringup();
-
- model_handle handle =
- model_load_gltf(core, "assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf", false);
+ Core_Bringup("Skinned Animation", NULL);
- model* simple_skin = &core->models->data[handle.raw];
+ ModelHandle handle = ModelLoad_gltf("assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf", false);
+ Model* simple_skin = MODEL_GET(handle);
// Okay, right here we've loaded the model. let's assert some facts
- assert(simple_skin->animations->len == 1);
- assert(simple_skin->animations->data[0].rotation != NULL);
- assert(simple_skin->animations->data[0].translation == NULL);
- assert(simple_skin->animations->data[0].scale == NULL);
+ // assert(simple_skin->animations->len == 1);
+ // assert(simple_skin->animations->data[0].rotation != NULL);
+ // assert(simple_skin->animations->data[0].translation == NULL);
+ // assert(simple_skin->animations->data[0].scale == NULL);
- mesh* m = &simple_skin->meshes->data[0];
- assert(m->is_skinned);
- assert(m->bones->len == 2); // 1 root and 1 extra joint
+ // mesh* m = &simple_skin->meshes->data[0];
+ // assert(m->is_skinned);
+ // assert(m->bones->len == 2); // 1 root and 1 extra joint
// assert(false);
- model_upload_meshes(&core->renderer, simple_skin);
+ // model_upload_meshes(&core->renderer, simple_skin);
- scene our_scene = make_default_scene();
+ // scene our_scene = make_default_scene();
- vec3 cam_pos = vec3_create(0, 5, -8);
- game_state game = {
- .camera = camera_create(cam_pos, vec3_negate(cam_pos), VEC3_Y, deg_to_rad(45.0)),
- .camera_euler = vec3_create(90, 0, 0),
- .first_mouse_update = true,
- };
-
- print_vec3(game.camera.front);
+ Vec3 cam_pos = vec3_create(0, 5, -8);
+ Camera camera =
+ Camera_Create(cam_pos, vec3_normalise(vec3_negate(cam_pos)), VEC3_Y, deg_to_rad(45.0));
// Main loop
const f32 camera_lateral_speed = 0.2;
const f32 camera_zoom_speed = 0.10;
// animation
- animation_clip track = simple_skin->animations->data[0];
- f64 total_time = 0.0;
+ // animation_clip track = simple_skin->animations->data[0];
+ // f64 total_time = 0.0;
- while (!should_exit(core)) {
- input_update(&core->input);
+ while (!ShouldExit()) {
+ Frame_Begin();
currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
- total_time += deltaTime;
+ // total_time += deltaTime;
// printf("delta time %f\n", deltaTime);
- f64 t = fmod(total_time, track.rotation->max);
+ // f64 t = fmod(total_time, track.rotation->max);
// INFO("Total time: %f", t);
- vec3 translation = VEC3_ZERO;
- if (key_is_pressed(KEYCODE_W)) {
- translation = vec3_mult(game.camera.front, camera_zoom_speed);
- } else if (key_is_pressed(KEYCODE_KEY_UP)) {
- translation = vec3_mult(game.camera.up, camera_lateral_speed);
- } else if (key_is_pressed(KEYCODE_KEY_DOWN)) {
- translation = vec3_mult(game.camera.up, -camera_lateral_speed);
- } else if (key_is_pressed(KEYCODE_S) || key_is_pressed(KEYCODE_KEY_DOWN)) {
- translation = vec3_mult(game.camera.front, -camera_zoom_speed);
- } else if (key_is_pressed(KEYCODE_A) || key_is_pressed(KEYCODE_KEY_LEFT)) {
- vec3 lateral = vec3_normalise(vec3_cross(game.camera.front, game.camera.up));
- translation = vec3_mult(lateral, -camera_lateral_speed);
- } else if (key_is_pressed(KEYCODE_D) || key_is_pressed(KEYCODE_KEY_RIGHT)) {
- vec3 lateral = vec3_normalise(vec3_cross(game.camera.front, game.camera.up));
- translation = vec3_mult(lateral, camera_lateral_speed);
- }
- game.camera.position = vec3_add(game.camera.position, translation);
-
- render_frame_begin(&core->renderer);
-
// bone rotation
- quat rot = animation_sample(track.rotation, t).rotation;
+ // Quat rot = animation_sample(track.rotation, t).rotation;
- m->bones->data[1].transform_components.rotation = rot;
+ // 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);
- draw_skinned_model(&core->renderer, &game.camera, simple_skin, tf, &our_scene);
+ // draw_skinned_model(&core->renderer, &game.camera, simple_skin, tf, &our_scene);
- render_frame_end(&core->renderer);
+ Frame_End();
}
INFO("Shutting down");
- model_destroy(simple_skin);
-
- core_shutdown(core);
return 0;
}