Physics I guess
This commit is contained in:
@@ -70,6 +70,23 @@ void cameraPushMatrix(camera_t *camera) {
|
||||
view
|
||||
);
|
||||
break;
|
||||
|
||||
case CAMERA_VIEW_TYPE_2D:
|
||||
glm_mat4_identity(view);
|
||||
glm_translate(view, (vec3){
|
||||
-camera->_2d.position[0],
|
||||
-camera->_2d.position[1],
|
||||
0.0f
|
||||
});
|
||||
glm_scale(view, (vec3){
|
||||
camera->_2d.zoom,
|
||||
camera->_2d.zoom,
|
||||
1.0f
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Invalid camera view type");
|
||||
}
|
||||
|
||||
#if DISPLAY_SDL2
|
||||
|
@@ -18,7 +18,8 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
CAMERA_VIEW_TYPE_MATRIX,
|
||||
CAMERA_VIEW_TYPE_LOOKAT
|
||||
CAMERA_VIEW_TYPE_LOOKAT,
|
||||
CAMERA_VIEW_TYPE_2D
|
||||
} cameraviewtype_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -27,11 +28,17 @@ typedef struct {
|
||||
|
||||
union {
|
||||
mat4 view;
|
||||
|
||||
struct {
|
||||
float_t position[3];
|
||||
float_t target[3];
|
||||
float_t up[3];
|
||||
} lookat;
|
||||
|
||||
struct {
|
||||
float_t position[2];
|
||||
float_t zoom;
|
||||
} _2d;
|
||||
};
|
||||
|
||||
union {
|
||||
|
@@ -10,4 +10,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(overworld)
|
||||
add_subdirectory(overworld)
|
||||
add_subdirectory(test)
|
@@ -93,9 +93,9 @@ void sceneOverworldRenderEntity(const entity_t *entity) {
|
||||
// For now, just draw a placeholder quad.
|
||||
spriteBatchPush(
|
||||
&testAsset->paletteImage.texture,
|
||||
entity->x, entity->y,
|
||||
entity->x + TILESET_ENTITIES.tileWidth,
|
||||
entity->y + TILESET_ENTITIES.tileHeight,
|
||||
entity->position[0], entity->position[1],
|
||||
entity->position[0] + TILESET_ENTITIES.tileWidth,
|
||||
entity->position[1] + TILESET_ENTITIES.tileHeight,
|
||||
COLOR_WHITE,
|
||||
uv[0], uv[1], uv[2], uv[3]
|
||||
);
|
||||
|
@@ -25,6 +25,7 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
SCENE_TYPE_LOGO,
|
||||
SCENE_TYPE_TEST,
|
||||
SCENE_TYPE_OVERWORLD,
|
||||
|
||||
SCENE_TYPE_COUNT
|
||||
|
@@ -8,12 +8,20 @@
|
||||
#include "scenemanager.h"
|
||||
|
||||
#include "display/scene/overworld/sceneoverworld.h"
|
||||
#include "display/scene/test/scenetest.h"
|
||||
|
||||
scenemanager_t SCENE_MANAGER;
|
||||
|
||||
scene_t SCENE_MANAGER_SCENES[SCENE_TYPE_COUNT] = {
|
||||
[SCENE_TYPE_LOGO] = { 0 },
|
||||
|
||||
[SCENE_TYPE_TEST] = {
|
||||
.init = sceneTestInit,
|
||||
.update = sceneTestUpdate,
|
||||
.render = sceneTestRender,
|
||||
.dispose = sceneTestDispose
|
||||
},
|
||||
|
||||
[SCENE_TYPE_OVERWORLD] = {
|
||||
.init = sceneOverworldInit,
|
||||
.update = sceneOverworldUpdate,
|
||||
|
@@ -15,7 +15,22 @@ typedef struct {
|
||||
extern scenemanager_t SCENE_MANAGER;
|
||||
extern scene_t SCENE_MANAGER_SCENES[SCENE_TYPE_COUNT];
|
||||
|
||||
/**
|
||||
* Initializes the scene manager and the initial scene.
|
||||
*/
|
||||
errorret_t sceneManagerInit(void);
|
||||
|
||||
/**
|
||||
* Updates all active scenes.
|
||||
*/
|
||||
void sceneManagerUpdate(void);
|
||||
|
||||
/**
|
||||
* Renders all visible scenes.
|
||||
*/
|
||||
void sceneManagerRender(void);
|
||||
|
||||
/**
|
||||
* Disposes of all scenes.
|
||||
*/
|
||||
void sceneManagerDispose(void);
|
10
src/display/scene/test/CMakeLists.txt
Normal file
10
src/display/scene/test/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
scenetest.c
|
||||
)
|
48
src/display/scene/test/scenetest.c
Normal file
48
src/display/scene/test/scenetest.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scenetest.h"
|
||||
#include "display/scene/scenemanager.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
|
||||
scenetest_t SCENE_TEST;
|
||||
|
||||
errorret_t sceneTestInit(void) {
|
||||
cameraInit(&SCENE_TEST.camera);
|
||||
SCENE_TEST.camera.projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC;
|
||||
SCENE_TEST.camera.nearClip = -1.0f;
|
||||
SCENE_TEST.camera.farClip = 2.0f;
|
||||
|
||||
SCENE_TEST.camera.viewType = CAMERA_VIEW_TYPE_2D;
|
||||
SCENE_TEST.camera._2d.zoom = 2.0f;
|
||||
SCENE_TEST.camera._2d.position[0] = -150.0f;
|
||||
SCENE_TEST.camera._2d.position[1] = -50.0f;
|
||||
|
||||
scene_t *scene = &SCENE_MANAGER_SCENES[SCENE_TYPE_TEST];
|
||||
scene->flags |= SCENE_FLAG_ACTIVE | SCENE_FLAG_VISIBLE;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void sceneTestUpdate(void) {
|
||||
}
|
||||
|
||||
void sceneTestRender(void) {
|
||||
SCENE_TEST.camera.orthographic.left = 0.0f;
|
||||
SCENE_TEST.camera.orthographic.right = frameBufferGetWidth(FRAMEBUFFER_BOUND);
|
||||
SCENE_TEST.camera.orthographic.top = frameBufferGetHeight(FRAMEBUFFER_BOUND);
|
||||
SCENE_TEST.camera.orthographic.bottom = 0.0f;
|
||||
|
||||
cameraPushMatrix(&SCENE_TEST.camera);
|
||||
spriteBatchClear();
|
||||
|
||||
spriteBatchFlush();
|
||||
cameraPopMatrix();
|
||||
}
|
||||
|
||||
void sceneTestDispose(void) {
|
||||
}
|
36
src/display/scene/test/scenetest.h
Normal file
36
src/display/scene/test/scenetest.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/camera.h"
|
||||
#include "error/error.h"
|
||||
|
||||
typedef struct {
|
||||
camera_t camera;
|
||||
} scenetest_t;
|
||||
|
||||
extern scenetest_t SCENE_TEST;
|
||||
|
||||
/**
|
||||
* Initialize the test scene.
|
||||
*/
|
||||
errorret_t sceneTestInit(void);
|
||||
|
||||
/**
|
||||
* Update the test scene.
|
||||
*/
|
||||
void sceneTestUpdate(void);
|
||||
|
||||
/**
|
||||
* Render the test scene.
|
||||
*/
|
||||
void sceneTestRender(void);
|
||||
|
||||
/**
|
||||
* Dispose of the test scene.
|
||||
*/
|
||||
void sceneTestDispose(void);
|
Reference in New Issue
Block a user