Added camera

Moved some math types
Added some more vector types
Did the camera matrix calulations
Updated shaders to take push constants
This commit is contained in:
2025-10-05 02:40:59 +01:00
parent 2c67896cf2
commit 3b8c50a361
15 changed files with 355 additions and 70 deletions

View File

@@ -37,7 +37,6 @@ int main(int argc, char **argv) {
Vk_Setup(window);
G_State *game = 0;
G_Image *img = 0;
{
M_Arena *arena = M_ArenaAlloc(GB(64), .initial = MB(4));
game = M_ArenaPush(arena, G_State);
@@ -47,14 +46,17 @@ int main(int argc, char **argv) {
G_ImagesLoad(game);
G_PipelinesLoad(game);
for (U32 it = 0; it < game->n_images; ++it) {
if (Str8_Equal(game->images[it].name, S("saloon_ext"), 0)) {
img = &game->images[it];
break;
}
}
G_Camera *camera = &game->camera;
if (!img) { img = &game->images[0]; }
camera->x = (V3f) { 1, 0, 0 };
camera->y = (V3f) { 0, 1, 0 };
camera->z = (V3f) { 0, 0, 1 };
camera->p = (V3f) { 0, 0, 8 };
camera->fov = 60.0f;
camera->nearp = 0.01f;
camera->farp = 1000.0f;
Vk_Buffer *vbo = &game->vbo;
vbo->size = KB(4096);
@@ -65,13 +67,13 @@ int main(int argc, char **argv) {
G_Vertex *vertices = cast(G_Vertex *) vbo->data;
vertices[0] = (G_Vertex) { -0.25f, -0.25f, 1.0f, 1.0f, 0.0f, 0.0f, 0xFFFFFFFF, 1};
vertices[1] = (G_Vertex) { 0.25f, -0.25f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 1};
vertices[2] = (G_Vertex) { -0.25f, 0.25f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1};
vertices[0] = (G_Vertex) { -0.25f, -0.625f, 1.0f, 1.0f, 0.0f, 0.0f, 0xFFFFFFFF, 1};
vertices[1] = (G_Vertex) { 0.25f, -0.625f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 1};
vertices[2] = (G_Vertex) { -0.25f, 0.625f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1};
vertices[3] = (G_Vertex) { 0.25f, -0.25f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 1};
vertices[4] = (G_Vertex) { 0.25f, 0.25f, 1.0f, 1.0f, 1.0f, 1.0f, 0xFFFFFFFF, 1};
vertices[5] = (G_Vertex) { -0.25f, 0.25f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1};
vertices[3] = (G_Vertex) { 0.25f, -0.625f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 1};
vertices[4] = (G_Vertex) { 0.25f, 0.625f, 1.0f, 1.0f, 1.0f, 1.0f, 0xFFFFFFFF, 1};
vertices[5] = (G_Vertex) { -0.25f, 0.625f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1};
}
bool running = true;
@@ -97,10 +99,12 @@ int main(int argc, char **argv) {
.currentNavNode = 0
}
},
.navMesh = TestNavMesh,
.navMesh = &TestNavMesh,
.npcPOI = {100}
};
printf("%zu size in bytes\n", sizeof(TestNavMesh));
while (running)
{
SDL_Event e;
@@ -113,11 +117,13 @@ int main(int argc, char **argv) {
}
}
UpdateNPCs(1.0f / 60.0f, &world);
updateNPCs(1.0f / 60.0f, &world);
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
G_CalulateCamera(&game->camera, (F32) w / (F32) h);
Vk_Frame *frame = Vk_FrameBegin(window);
VkCommandBuffer cmd = frame->cmd;
@@ -128,19 +134,19 @@ int main(int argc, char **argv) {
clear_colour.color.float32[3] = 1.0f;
VkRenderingAttachmentInfo colour_attachment = {0};
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
colour_attachment.imageView = vk.swapchain.views[frame->image];
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
colour_attachment.imageView = vk.swapchain.views[frame->image];
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colour_attachment.clearValue = clear_colour;
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colour_attachment.clearValue = clear_colour;
VkRenderingInfo rendering_info = {0};
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
rendering_info.renderArea = (VkRect2D){0, 0, w, h};
rendering_info.layerCount = 1;
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
rendering_info.renderArea = (VkRect2D) { 0, 0, w, h };
rendering_info.layerCount = 1;
rendering_info.colorAttachmentCount = 1;
rendering_info.pColorAttachments = &colour_attachment;
rendering_info.pColorAttachments = &colour_attachment;
vk.CmdBeginRendering(cmd, &rendering_info);
@@ -191,6 +197,7 @@ int main(int argc, char **argv) {
vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, basic->handle);
vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, basic->layout.pipeline, 0, 1, &set, 0, 0);
vk.CmdPushConstants(cmd, basic->layout.pipeline, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(Mat4x4F), &game->camera.proj.fwd);
VkViewport viewport = { 0, 0, (F32) w, (F32) h, 0.0f, 1.0f };
VkRect2D scissor = { 0, 0, w, h };
@@ -202,7 +209,6 @@ int main(int argc, char **argv) {
vk.CmdEndRendering(cmd);
Vk_FrameEnd();
}