Fixed bug in orth matrix, UI is now nice

This commit is contained in:
Dennis Eichhorn 2024-09-30 20:23:38 +02:00
parent 0b945e07e9
commit fd39f1042d
7 changed files with 73 additions and 69 deletions

View File

@ -33,6 +33,9 @@ struct Camera {
float sensitivity; float sensitivity;
float zoom; float zoom;
uint16 viewport_width;
uint16 viewport_height;
float fov; float fov;
float znear; float znear;
float zfar; float zfar;
@ -202,29 +205,30 @@ void camera_movement(Camera* camera, CameraMovement* movement, float dt, bool re
} }
} }
// @question should we remove the fov for this or not, fov shouldn't matter for UI!?
inline inline
void camera_orth_matrix_lh(const Camera* __restrict camera, float* __restrict orth) void camera_orth_matrix_lh(const Camera* __restrict camera, float* __restrict orth)
{ {
mat4_identity_sparse(orth); mat4_identity_sparse(orth);
mat4_ortho_sparse_lh(
float ymax, xmax; orth,
ymax = camera->znear * tanf(camera->fov * 0.5f); 0, camera->viewport_width,
xmax = ymax * camera->aspect; 0, camera->viewport_height,
camera->znear,
mat4_ortho_sparse_lh(orth, -xmax, xmax, -ymax, ymax, camera->znear, camera->zfar); camera->zfar
);
} }
inline inline
void camera_orth_matrix_rh(const Camera* __restrict camera, float* __restrict orth) void camera_orth_matrix_rh(const Camera* __restrict camera, float* __restrict orth)
{ {
mat4_identity_sparse(orth); mat4_identity_sparse(orth);
mat4_ortho_sparse_rh(
float ymax, xmax; orth,
ymax = camera->znear * tanf(camera->fov * 0.5f); 0, camera->viewport_width,
xmax = ymax * camera->aspect; 0, camera->viewport_height,
camera->znear,
mat4_ortho_sparse_rh(orth, -xmax, xmax, -ymax, ymax, camera->znear, camera->zfar); camera->zfar
);
} }
inline inline

View File

@ -151,20 +151,6 @@ void debug_memory_reset()
} }
} }
#if DEBUG
#define DEBUG_MEMORY_INIT(start, size) debug_memory_init((start), (size))
#define DEBUG_MEMORY_READ(start, size) debug_memory_read((start), (size))
#define DEBUG_MEMORY_WRITE(start, size) debug_memory_write((start), (size))
#define DEBUG_MEMORY_DELETE(start, size) debug_memory_delete((start), (size))
#define DEBUG_MEMORY_RESET() debug_memory_reset()
#else
#define DEBUG_MEMORY_INIT(start, size) ((void) 0)
#define DEBUG_MEMORY_READ(start, size) ((void) 0)
#define DEBUG_MEMORY_WRITE(start, size) ((void) 0)
#define DEBUG_MEMORY_DELETE(start, size) ((void) 0)
#define DEBUG_MEMORY_RESET() ((void) 0)
#endif
byte* log_get_memory(uint64 size, byte aligned = 1, bool zeroed = false) byte* log_get_memory(uint64 size, byte aligned = 1, bool zeroed = false)
{ {
ASSERT_SIMPLE(size <= debug_container->log_memory.size); ASSERT_SIMPLE(size <= debug_container->log_memory.size);

View File

@ -46,4 +46,18 @@ struct DebugMemoryContainer {
DebugMemory* memory_stats; DebugMemory* memory_stats;
}; };
#if DEBUG
#define DEBUG_MEMORY_INIT(start, size) debug_memory_init((start), (size))
#define DEBUG_MEMORY_READ(start, size) debug_memory_read((start), (size))
#define DEBUG_MEMORY_WRITE(start, size) debug_memory_write((start), (size))
#define DEBUG_MEMORY_DELETE(start, size) debug_memory_delete((start), (size))
#define DEBUG_MEMORY_RESET() debug_memory_reset()
#else
#define DEBUG_MEMORY_INIT(start, size) ((void) 0)
#define DEBUG_MEMORY_READ(start, size) ((void) 0)
#define DEBUG_MEMORY_WRITE(start, size) ((void) 0)
#define DEBUG_MEMORY_DELETE(start, size) ((void) 0)
#define DEBUG_MEMORY_RESET() ((void) 0)
#endif
#endif #endif

View File

@ -778,36 +778,6 @@ void mat4_ortho_sparse_lh(
float tb_delta = top - bottom; float tb_delta = top - bottom;
float fn_delta = zfar - znear; float fn_delta = zfar - znear;
matrix[0] = 2.0f / rl_delta;
//matrix[1] = 0.0f;
//matrix[2] = 0.0f;
//matrix[3] = 0.0f;
//matrix[4] = 0.0f;
matrix[5] = 2.0f / tb_delta;
//matrix[6] = 0.0f;
//matrix[7] = 0.0f;
//matrix[8] = 0.0f;
//matrix[9] = 0.0f;
matrix[10] = -2.0f / fn_delta;
//matrix[11] = 0.0f;
matrix[12] = -(right + left) / rl_delta;
matrix[13] = -(top + bottom) / tb_delta;
matrix[14] = -(zfar + znear) / fn_delta;
matrix[15] = 1.0f;
}
void mat4_ortho_sparse_rh(
float *matrix,
float left, float right, float bottom, float top,
float znear, float zfar
) {
float rl_delta = right - left;
float tb_delta = top - bottom;
float fn_delta = zfar - znear;
matrix[0] = 2.0f / rl_delta; matrix[0] = 2.0f / rl_delta;
//matrix[1] = 0.0f; //matrix[1] = 0.0f;
//matrix[2] = 0.0f; //matrix[2] = 0.0f;
@ -829,6 +799,36 @@ void mat4_ortho_sparse_rh(
matrix[15] = 1.0f; matrix[15] = 1.0f;
} }
void mat4_ortho_sparse_rh(
float *matrix,
float left, float right, float bottom, float top,
float znear, float zfar
) {
float rl_delta = right - left;
float tb_delta = top - bottom;
float fn_delta = zfar - znear;
matrix[0] = 2.0f / rl_delta;
//matrix[1] = 0.0f;
//matrix[2] = 0.0f;
//matrix[3] = 0.0f;
//matrix[4] = 0.0f;
matrix[5] = 2.0f / tb_delta;
//matrix[6] = 0.0f;
//matrix[7] = 0.0f;
//matrix[8] = 0.0f;
//matrix[9] = 0.0f;
matrix[10] = -2.0f / fn_delta;
//matrix[11] = 0.0f;
matrix[12] = -(right + left) / rl_delta;
matrix[13] = -(top + bottom) / tb_delta;
matrix[14] = -(zfar + znear) / fn_delta;
matrix[15] = 1.0f;
}
void mat4_translate(float* matrix, float dx, float dy, float dz) void mat4_translate(float* matrix, float dx, float dy, float dz)
{ {
float temp[16]; float temp[16];

View File

@ -184,8 +184,8 @@ struct CSettings {
byte audio_volume_music = 128; byte audio_volume_music = 128;
byte audio_volume_speech = 128; byte audio_volume_speech = 128;
uint32 game_window1_dim[2] = {1024, 768}; uint16 game_window1_dim[2] = {1024, 768};
uint32 game_window1_pos[2]; uint16 game_window1_pos[2];
byte game_window1_mode = SETTING_TYPE_WINDOW_MODE_FULLSCREEN; byte game_window1_mode = SETTING_TYPE_WINDOW_MODE_FULLSCREEN;
byte game_zoom; byte game_zoom;

View File

@ -39,8 +39,8 @@ void monitor_resolution(const Window* __restrict w, v2_int32* __restrict resolut
inline inline
void monitor_resolution(Window* __restrict w) void monitor_resolution(Window* __restrict w)
{ {
w->width = GetDeviceCaps(w->hdc, HORZRES); w->width = (uint16) GetDeviceCaps(w->hdc, HORZRES);
w->height = GetDeviceCaps(w->hdc, VERTRES); w->height = (uint16) GetDeviceCaps(w->hdc, VERTRES);
} }
inline inline
@ -114,8 +114,8 @@ void window_create(Window* __restrict window, void* proc)
} }
if (window->is_fullscreen) { if (window->is_fullscreen) {
window->width = GetSystemMetrics(SM_CXSCREEN); window->width = (uint16) GetSystemMetrics(SM_CXSCREEN);
window->height = GetSystemMetrics(SM_CYSCREEN); window->height = (uint16) GetSystemMetrics(SM_CYSCREEN);
DEVMODE screen_settings; DEVMODE screen_settings;

View File

@ -13,22 +13,22 @@
#include "../../stdlib/Types.h" #include "../../stdlib/Types.h"
struct WindowState { struct WindowState {
uint64 style; uint16 width;
int32 width; uint16 height;
int32 height;
int32 x; int32 x;
int32 y; int32 y;
uint64 style;
}; };
struct Window { struct Window {
bool is_fullscreen; uint16 width;
int32 width; uint16 height;
int32 height;
int32 x; int32 x;
int32 y; int32 y;
bool is_fullscreen;
bool mouse_captured; bool mouse_captured;
HWND hwnd; HWND hwnd;