Compare commits
1 Commits
raycast
...
5cabf845b6
| Author | SHA1 | Date | |
|---|---|---|---|
|
5cabf845b6
|
@@ -160,4 +160,46 @@ Mat4x4FInv M4x4F_CameraView(V3f x, V3f y, V3f z, V3f p) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Random
|
||||
|
||||
Random Random_Seed(U64 seed) {
|
||||
Random result = { seed };
|
||||
return result;
|
||||
}
|
||||
|
||||
U64 Random_Next(Random *rnd) {
|
||||
U64 result = rnd->state;
|
||||
|
||||
result ^= (result << 13);
|
||||
result ^= (result >> 7);
|
||||
result ^= (result << 17);
|
||||
|
||||
rnd->state = result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
F32 Random_F32(Random *rnd, F32 min, F32 max) {
|
||||
F32 result = min + (Random_Unilateral(rnd) * (max - min));
|
||||
return result;
|
||||
}
|
||||
|
||||
F64 Random_F64(Random *rnd, F64 min, F64 max) {
|
||||
F64 result = min + (Random_Unilateral(rnd) * (max - min));
|
||||
return result;
|
||||
}
|
||||
|
||||
U32 Random_U32(Random *rnd, U32 min, U32 max) {
|
||||
U32 result = min + (U32) (Random_Unilateral(rnd) * (max - min));
|
||||
return result;
|
||||
}
|
||||
|
||||
F32 Random_Unilateral(Random *rnd) {
|
||||
F32 result = Random_Next(rnd) / (F32) U64_MAX;
|
||||
return result;
|
||||
}
|
||||
|
||||
F32 Random_Bilateral(Random *rnd) {
|
||||
F32 result = -1.0f + (2.0f * Random_Unilateral(rnd));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
#define PI_F32 (3.14159265358979323846264338f)
|
||||
#define TAU_F32 (2.0f * PI_F32)
|
||||
|
||||
typedef struct Random Random;
|
||||
struct Random {
|
||||
U64 state;
|
||||
};
|
||||
|
||||
typedef union V2f V2f;
|
||||
union V2f {
|
||||
struct {
|
||||
@@ -114,4 +119,18 @@ function V3f M4x4F_VMul3(Mat4x4F m, V3f v);
|
||||
function Mat4x4FInv M4x4F_Perspective(F32 fov, F32 aspect, F32 nearp, F32 farp);
|
||||
function Mat4x4FInv M4x4F_CameraView(V3f x, V3f y, V3f z, V3f p);
|
||||
|
||||
// Random
|
||||
|
||||
function Random Random_Seed(U64 seed);
|
||||
|
||||
function U64 Random_Next(Random *rnd);
|
||||
|
||||
function F32 Random_F32(Random *rnd, F32 min, F32 max);
|
||||
function F64 Random_F64(Random *rnd, F64 min, F64 max);
|
||||
|
||||
function U32 Random_U32(Random *rnd, U32 min, U32 max);
|
||||
|
||||
function F32 Random_Unilateral(Random *rnd);
|
||||
function F32 Random_Bilateral(Random *rnd);
|
||||
|
||||
#endif // LD_CORE_MATH_H_
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if !defined(LD_DRAW_CORE_H_)
|
||||
#define LD_DRAW_CORE_H_
|
||||
|
||||
#define D_MAX_RECTS 1024
|
||||
#define D_MAX_RECTS (262144)
|
||||
|
||||
typedef struct D_Image D_Image;
|
||||
struct D_Image {
|
||||
|
||||
12
code/first.c
12
code/first.c
@@ -63,13 +63,6 @@ int main(int argc, char **argv) {
|
||||
game->draw.camera = camera;
|
||||
}
|
||||
|
||||
Vk_Buffer rbo = { 0 };
|
||||
rbo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||
rbo.size = KB(4);
|
||||
rbo.host_visible = true;
|
||||
|
||||
Vk_BufferCreate(&rbo);
|
||||
|
||||
bool running = true;
|
||||
World world = {
|
||||
.npcCount = 2,
|
||||
@@ -108,7 +101,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
ProcessEvents(&e, &world);
|
||||
}
|
||||
UpdateWorld(1.0/60.0, &world);
|
||||
|
||||
UpdateWorld(1.0f / 60.0f, &world);
|
||||
|
||||
int w, h;
|
||||
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||
@@ -116,7 +110,7 @@ int main(int argc, char **argv) {
|
||||
game->draw.window_width = w;
|
||||
game->draw.window_height = h;
|
||||
|
||||
G_CalulateCamera(&game->camera, (F32) w / (F32) h);
|
||||
G_CalculateCamera(&game->camera, (F32) w / (F32) h);
|
||||
|
||||
Vk_Frame *frame = Vk_FrameBegin(window);
|
||||
VkCommandBuffer cmd = frame->cmd;
|
||||
|
||||
@@ -290,7 +290,7 @@ void G_PipelinesLoad(G_State *game) {
|
||||
Vk_PipelineCreate(basic);
|
||||
}
|
||||
|
||||
void G_CalulateCamera(G_Camera *camera, F32 aspect) {
|
||||
void G_CalculateCamera(G_Camera *camera, F32 aspect) {
|
||||
Mat4x4FInv proj = M4x4F_Perspective(camera->fov, aspect, camera->nearp, camera->farp);
|
||||
Mat4x4FInv view = M4x4F_CameraView(camera->x, camera->y, camera->z, camera->p);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ struct G_State {
|
||||
function void G_ImagesLoad(G_State *game);
|
||||
function void G_PipelinesLoad(G_State *game);
|
||||
|
||||
function void G_CalulateCamera(G_Camera *camera, F32 aspect);
|
||||
function void G_CalculateCamera(G_Camera *camera, F32 aspect);
|
||||
|
||||
#include "aabb.h"
|
||||
#include "player.h"
|
||||
|
||||
@@ -8,7 +8,7 @@ void UpdateWorld(F32 delta, World *world) {
|
||||
}
|
||||
|
||||
void UpdateNPCs(F32 delta, World *world) {
|
||||
for(int i = 0; i < world->npcCount; i++) {
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
updateNPC(delta, &world->npcs[i], world);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user