add a cube
This commit is contained in:
parent
2d7da84f8d
commit
d38ce455af
3
Makefile
3
Makefile
@ -2,11 +2,10 @@ SRCS = $(shell find ./src -type f -name *.c)
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
gcc -Wall -std=c99 $(SRCS) -lSDL2 -o renderer
|
gcc -Wall -std=c99 $(SRCS) -lSDL2 -o renderer
|
||||||
|
./renderer
|
||||||
|
|
||||||
run: build
|
run: build
|
||||||
./renderer
|
./renderer
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm renderer
|
rm renderer
|
||||||
|
|
||||||
all: clean build run
|
|
||||||
|
@ -10,7 +10,9 @@
|
|||||||
#define N_POINTS (9 * 9 * 9)
|
#define N_POINTS (9 * 9 * 9)
|
||||||
vec3_t cube_points[N_POINTS];
|
vec3_t cube_points[N_POINTS];
|
||||||
vec2_t projected_points[N_POINTS];
|
vec2_t projected_points[N_POINTS];
|
||||||
float fov_factor = 128;
|
|
||||||
|
vec3_t camera_position = {0, 0, -5};
|
||||||
|
float fov_factor = 640;
|
||||||
|
|
||||||
|
|
||||||
bool is_running = false;
|
bool is_running = false;
|
||||||
@ -59,8 +61,8 @@ void process_input(void) {
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
vec2_t project(vec3_t point) {
|
vec2_t project(vec3_t point) {
|
||||||
vec2_t projected_point = {
|
vec2_t projected_point = {
|
||||||
.x = (fov_factor * point.x),
|
.x = (fov_factor * point.x) / point.z,
|
||||||
.y = (fov_factor * point.y),
|
.y = (fov_factor * point.y) / point.z,
|
||||||
};
|
};
|
||||||
return projected_point;
|
return projected_point;
|
||||||
}
|
}
|
||||||
@ -69,6 +71,7 @@ vec2_t project(vec3_t point) {
|
|||||||
void update(void) {
|
void update(void) {
|
||||||
for (int i = 0; i < N_POINTS; i++){
|
for (int i = 0; i < N_POINTS; i++){
|
||||||
vec3_t point = cube_points[i];
|
vec3_t point = cube_points[i];
|
||||||
|
point.z -= camera_position.z;
|
||||||
vec2_t projected_point = project(point);
|
vec2_t projected_point = project(point);
|
||||||
|
|
||||||
projected_points[i] = projected_point;
|
projected_points[i] = projected_point;
|
||||||
|
Loading…
Reference in New Issue
Block a user