~zjm/Moon3D

e6657c589fe6585e0395c1ae85d88392cfd4f66f — Zack Michener a month ago 7bd666b
fix tests
M src/pool.h => src/pool.h +2 -0
@@ 1,5 1,7 @@
#pragma once

#include <stdlib.h>

#define MAX_SCENE_OBJECTS 1000
#define MAX_PARTICLES   1000
#define MAX_MESH_VERTICES 1000000

M src/renderer.c => src/renderer.c +1 -2
@@ 31,7 31,6 @@ aspect ratio.
	r->clip_planes.y_pos = Pl(V4D(0, 0, 0, 0), V4D( 0,  1,  0, -1));
	r->clip_planes.z_neg = Pl(V4D(0, 0, 0, 0), V4D( 0,  0, -1, -1));
	r->clip_planes.z_pos = Pl(V4D(0, 0, 0, 0), V4D( 0,  0,  1, -1));
	r->clip_planes.w_pos = Pl(V4D(0, 0, 0, 0), V4D( 0,  0,  0, -1));

	ClearScreen(r->viewport);
	return r;


@@ 92,7 91,7 @@ void Render(Renderable renderable, Renderer *renderer, Transform camera_transfor
	/* viewmap all vertices */
	// TODO: skip clipped vertices
	for (i = 0; i < PoolTotal(renderMesh.vertices); i++) {
		Homogenize(&renderMesh.vertices[i]);
		renderMesh.vertices[i] = Homogenize(renderMesh.vertices[i]);
		CommitTransform(renderer->deviceTransform, &renderMesh.vertices[i]);
	}


M src/vector.c => src/vector.c +9 -6
@@ 31,12 31,15 @@ Vector V4D(double x, double y, double z, double w)
  return v;
}

void Homogenize(Vector *v)
{
	v->x /= v->w;
	v->y /= v->w;
	v->z /= v->w;
	v->w = 1;
Vector Homogenize(Vector v)
{
	Vector h = {
		v.x/v.w,
		v.y/v.w,
		v.z/v.w,
		1
	};
	return h;
}

Vector *FromVector(Vector v)

M src/vector.h => src/vector.h +1 -1
@@ 10,7 10,7 @@ typedef struct Vertex {
	double x, y, z, w;
} Vector, Vertex;

void Homogenize(Vector *v);
Vector Homogenize(Vector h);
#define FromVertex(v) FromVector(v)
Vector *FromVector(Vector v);
bool VectorEqual(Vector a, Vector b);

M test/assertions.h => test/assertions.h +1 -1
@@ 1,7 1,7 @@
#pragma once

#include <stdbool.h>
#include "../src/vector.h"
#include "../src/moon3d.h"

extern bool gTestPassed;


M test/clipping.test.c => test/clipping.test.c +2 -2
@@ 1,5 1,5 @@
#include "tests.h"
#include "../src/everything.h"
#include "../src/moon3d.h"

void TestClipPolygonPlane(void)
{


@@ 36,7 36,7 @@ void TestClipPolygon(void)
  Vertex *vertex;
  Pixel *pixels = NewFrameBuffer(1, 1);
  Camera *camera = NewCamera(30, 1, 1, 10, NULL, NULL);
  Renderer *renderer = NewRenderer(pixels, 1, 1, camera);
  Renderer *renderer = NewRenderer(pixels, 1, 1);
  Mesh mesh;
  mesh.vertices = renderer->vertex_pool;
  mesh.faces = renderer->polygon_pool;

M test/data.test.c => test/data.test.c +1 -1
@@ 1,5 1,5 @@
#include "tests.h"
#include "../src/everything.h"
#include "../src/moon3d.h"

void TestMemoryPool(void)
{

M test/projection.test.c => test/projection.test.c +1 -1
@@ 1,5 1,5 @@
#include "tests.h"
#include "../src/everything.h"
#include "../src/moon3d.h"
#include <math.h>

void TestProjection(void)

M test/raster.test.c => test/raster.test.c +30 -30
@@ 1,27 1,27 @@
#include "tests.h"
#include "../src/everything.h"
#include "../src/moon3d.h"

void TestRasterLine(void)
{
	int x, y;
	Pixel *pixels = NewFrameBuffer(10, 10);
	Camera *camera = NewCamera(30, 1, 1, 10, NULL, NULL);
	Renderer *renderer = NewRenderer(pixels, 10, 10, camera);
	Viewport *viewport = NewViewport(pixels, WHITE, 10, 10);
	ClearScreen(viewport);

	for (y = 0; y < renderer->height; y++)
		for (x = 0; x < renderer->width; x++)
			AssertPixel(x, y, WHITE, renderer);
	for (y = 0; y < viewport->height; y++)
		for (x = 0; x < viewport->width; x++)
			AssertPixel(x, y, WHITE, viewport);

	RasterLine(V(0, 0, 0), V(9, 9, 0), BLACK, renderer);
	for (y = 0; y < renderer->height; y++)
		for (x = 0; x < renderer->width; x++)
			if (x == y) AssertPixel(x, y, BLACK, renderer);
			else AssertPixel(x, y, WHITE, renderer);
	ClearScreen(renderer);
	RasterLine(V(0, 0, 0), V(9, 9, 0), BLACK, viewport);
	for (y = 0; y < viewport->height; y++)
		for (x = 0; x < viewport->width; x++)
			if (x == y) AssertPixel(x, y, BLACK, viewport);
			else AssertPixel(x, y, WHITE, viewport);
	ClearScreen(viewport);

	RasterLine(V(0, 0, 0), V(9, 5, 0), BLACK, renderer);
	for (y = 0; y < renderer->height; y++) {
		for (x = 0; x < renderer->width; x++) {
	RasterLine(V(0, 0, 0), V(9, 5, 0), BLACK, viewport);
	for (y = 0; y < viewport->height; y++) {
		for (x = 0; x < viewport->width; x++) {
			if (
				(x == 0 && y == 0) ||
				(x == 1 && y == 1) ||


@@ 34,16 34,16 @@ void TestRasterLine(void)
				(x == 8 && y == 4) ||
				(x == 9 && y == 5)
			) {
				AssertPixel(x, y, BLACK, renderer);
				AssertPixel(x, y, BLACK, viewport);
			}
			else AssertPixel(x, y, WHITE, renderer);
			else AssertPixel(x, y, WHITE, viewport);
		}
	}
	ClearScreen(renderer);
	ClearScreen(viewport);

	RasterLine(V(2, 2, 0), V(4, 6, 0), BLACK, renderer);
	for (y = 0; y < renderer->height; y++) {
		for (x = 0; x < renderer->width; x++) {
	RasterLine(V(2, 2, 0), V(4, 6, 0), BLACK, viewport);
	for (y = 0; y < viewport->height; y++) {
		for (x = 0; x < viewport->width; x++) {
			if (
				(x == 2 && y == 2) ||
				(x == 2 && y == 3) ||


@@ 51,17 51,17 @@ void TestRasterLine(void)
				(x == 3 && y == 5) ||
				(x == 4 && y == 6)
			) {
				AssertPixel(x, y, BLACK, renderer);
				AssertPixel(x, y, BLACK, viewport);
			}
			else AssertPixel(x, y, WHITE, renderer);
			else AssertPixel(x, y, WHITE, viewport);
		}
	}
	ClearScreen(renderer);
	ClearScreen(viewport);


	RasterLine(V(4, 6, 0), V(2, 2, 0), BLACK, renderer);
	for (y = 0; y < renderer->height; y++) {
		for (x = 0; x < renderer->width; x++) {
	RasterLine(V(4, 6, 0), V(2, 2, 0), BLACK, viewport);
	for (y = 0; y < viewport->height; y++) {
		for (x = 0; x < viewport->width; x++) {
			if (
				(x == 2 && y == 2) ||
				(x == 2 && y == 3) ||


@@ 69,10 69,10 @@ void TestRasterLine(void)
				(x == 3 && y == 5) ||
				(x == 4 && y == 6)
			) {
				AssertPixel(x, y, BLACK, renderer);
				AssertPixel(x, y, BLACK, viewport);
			}
			else AssertPixel(x, y, WHITE, renderer);
			else AssertPixel(x, y, WHITE, viewport);
		}
	}
	ClearScreen(renderer);
	ClearScreen(viewport);
}
\ No newline at end of file

M test/tests.h => test/tests.h +1 -1
@@ 1,7 1,7 @@
#pragma once

#include "assertions.h"
#include "../src/everything.h"
#include "../src/moon3d.h"

typedef void (*TestFunc)(void);
void DoTest(TestFunc test);