Implement RNG module
This commit is contained in:
@@ -12,6 +12,7 @@ add_library(batomorph
|
||||
src/camera.c
|
||||
src/ff.c
|
||||
src/obj.c
|
||||
src/rng.c
|
||||
src/vec3.c
|
||||
)
|
||||
configure_target(batomorph)
|
||||
|
||||
5
demo.c
5
demo.c
@@ -1,6 +1,7 @@
|
||||
#include "camera.h"
|
||||
#include "ff.h"
|
||||
#include "obj.h"
|
||||
#include "rng.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -23,9 +24,13 @@ static pix_t pixbuf[W * H];
|
||||
|
||||
int main()
|
||||
{
|
||||
rng_init();
|
||||
|
||||
img_t img = { .pix = pixbuf };
|
||||
camera_t camera = camera_init(camera_pos, FOCAL_LEN, VIEWPORT_H, W, H);
|
||||
camera_render(&camera, scene, NELEMS(scene), &img);
|
||||
|
||||
ff_write(STDOUT_FILENO, img);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
11
include/rng.h
Normal file
11
include/rng.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef RNG_H
|
||||
#define RNG_H
|
||||
|
||||
#include "vec3.h"
|
||||
|
||||
void rng_init();
|
||||
|
||||
double rng_double();
|
||||
vec3_t rng_vec3();
|
||||
|
||||
#endif
|
||||
23
src/rng.c
Normal file
23
src/rng.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "rng.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void rng_init()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
srand(tv.tv_usec);
|
||||
}
|
||||
|
||||
double rng_double()
|
||||
{
|
||||
return 2.0 * (double)rand() / (double)INT_MAX - 1.0;
|
||||
}
|
||||
|
||||
vec3_t rng_vec3()
|
||||
{
|
||||
const vec3_t v = { rng_double(), rng_double(), rng_double() };
|
||||
return vec3_unit(v);
|
||||
}
|
||||
Reference in New Issue
Block a user