archivemuh

This commit is contained in:
2025-08-20 19:18:38 -05:00
parent 1411c2e96b
commit fbfcbe9578
173 changed files with 2802 additions and 13 deletions

View 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
camera.c
)

View File

@@ -0,0 +1,125 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "camera.h"
#include "display/render.h"
#include "world/overworld.h"
void cameraUIPush(void) {
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, RENDER_WIDTH, RENDER_HEIGHT);
mat4 ortho;
glm_ortho(
0.0f, (float_t)RENDER_WIDTH,
(float_t)RENDER_HEIGHT, 0.0f,
-1.0f, 1.0f,
ortho
);
glLoadMatrixf((const GLfloat*)ortho);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void cameraUIPop(void) {
glPopMatrix();
}
void cameraScreenPush(void) {
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
mat4 ortho;
#if RENDER_USE_FRAMEBUFFER
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(RENDER_WINDOW, &windowWidth, &windowHeight);
glViewport(0, 0, windowWidth, windowHeight);
glm_ortho(
0.0f, (float_t) windowWidth,
(float_t)windowHeight, 0.0f,
-1.0f, 1.0f,
ortho
);
#else
glm_ortho(
0.0f, (float_t)RENDER_WIDTH,
(float_t)RENDER_HEIGHT, 0.0f,
-1.0f, 1.0f,
ortho
);
#endif
glLoadMatrixf((const GLfloat*)ortho);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void cameraScreenPop(void) {
glPopMatrix();
}
void cameraOverworldPush(void) {
glPushMatrix();
glLoadIdentity();
#if RENDER_USE_FRAMEBUFFER
glViewport(0, 0, RENDER_WIDTH, RENDER_HEIGHT);
#endif
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
const float_t fov = glm_rad(75.0f);
const float_t camOffset = 12.0f;
const float_t aspect = (float_t)RENDER_WIDTH / (float_t)RENDER_HEIGHT;
const float_t pixelPerfectOffset = (
tanf((glm_rad(180) - fov) / 2.0f) *
((float_t)RENDER_HEIGHT/ 2.0f)
);
vec3 look = {
OVERWORLD_CAMERA_X,
OVERWORLD_CAMERA_Y,
0.0f
};
vec3 eye = {
look[0],
look[1] + camOffset,
look[2] + pixelPerfectOffset
};
vec3 up = { 0.0f, 1.0f, 0.0f };
mat4 proj;
glm_perspective(fov, aspect, 0.1f, 1000.0f, proj);
// Flips rendering on the Y axis, so that it is still right-down even in 3D;
proj[1][1] = -proj[1][1];
mat4 view;
glm_lookat(eye, look, up, view);
mat4 pv;
glm_mat4_mul(proj, view, pv);
glLoadMatrixf((const GLfloat*)pv);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void cameraOverworldPop(void) {
glPopMatrix();
}

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusksdl2.h"
/**
* Pushes the UI camera matrix onto the stack.
*/
void cameraUIPush(void);
/**
* Pops the UI camera matrix from the stack.
*/
void cameraUIPop(void);
/**
* Pushes the screen space camera matrix onto the stack.
*/
void cameraScreenPush(void);
/**
* Pops the screen space camera matrix.
*/
void cameraScreenPop(void);
/**
* Pushes the overworld camera matrix onto the stack.
*/
void cameraOverworldPush(void);
/**
* Pops the overworld camera matrix.
*/
void cameraOverworldPop(void);