~zjm/Moon3D

17ef74f5d680a78c2d8c3f68aeaa19db63d2ddf9 — Zack Michener 5 months ago ba1cd02
add an obelisk!
6 files changed, 29 insertions(+), 11 deletions(-)

M src/3d/3d.h
M src/3d/model.c
M src/3d/model.h
M src/sketch.c
M test/main.test.c
M test/tests.h
M src/3d/3d.h => src/3d/3d.h +0 -1
@@ 39,7 39,6 @@ typedef struct Polygon {
typedef struct Mesh {
	Vertex **vertices;	// list of vertices in all of the mesh's facets
	Polygon **facets;
	Color color;
} Mesh;

typedef struct Object {

M src/3d/model.c => src/3d/model.c +2 -3
@@ 135,12 135,11 @@ void FreePolygon(Polygon *p)
	free(p);
}

Mesh *NewMesh(Color color)
Mesh *NewMesh(void)
{
	Mesh *obj = malloc(sizeof(Mesh));
	obj->vertices = NULL;
	obj->facets = NULL;
	obj->color = color;
	return obj;
}



@@ 185,7 184,7 @@ int NumFacets(Mesh *mesh)

Object *NewCube(Color color)
{
	Mesh *geometry = NewMesh(color);
	Mesh *geometry = NewMesh();

	Polygon *front = NewPolygon();
	AddVertex(front, NewVector(1, 1, 1));

M src/3d/model.h => src/3d/model.h +1 -1
@@ 17,7 17,7 @@ Vector PolygonNormal(Polygon *polygon);
void HomogenizePolygon(Polygon *polygon);
void FreePolygon(Polygon *p);

Mesh *NewMesh(Color color);
Mesh *NewMesh(void);
void AddFacet(Mesh *object, Polygon *facet);
int NumFacets(Mesh *mesh);
Mesh *FromMesh(Mesh *object, Transform *transform);

M src/sketch.c => src/sketch.c +22 -6
@@ 6,23 6,27 @@
#include "arraylist.h"
#include "3d/rasterize.h"
#include <stdlib.h>
#include "3d/dither.h"
#include "obelisk.h"

Polygon *ground;
int debounce = 0;

int numCubes = 500;
Object **cubes = NULL;
bool dither = true;
bool dither = false;
Object *masterCube;
Object *ob;

int now, lastTime;

void sketch_setup(Pixel *pixels)
{
	ground = NewPolygon();
	AddVertex(ground, NewVector(1000, -2, 1000));
	AddVertex(ground, NewVector(1000, -2, -1000));
	AddVertex(ground, NewVector(-1000, -2, -1000));
	AddVertex(ground, NewVector(-1000, -2, 1000));
	AddVertex(ground, NewVector(1000, -1, 1000));
	AddVertex(ground, NewVector(1000, -1, -1000));
	AddVertex(ground, NewVector(-1000, -1, -1000));
	AddVertex(ground, NewVector(-1000, -1, 1000));

	SetViewport(pixels, 400, 240);
	// ShowZBuffer();


@@ 41,6 45,12 @@ void sketch_setup(Pixel *pixels)
		TranslateObj(cube, V(x, 0, z));
		list_push(cubes, cube);
	}

	masterCube = NewCube(DK_GRAY);
	TranslateObj(masterCube, V(0, 2, 0));

	ob = NewObelisk(DK_GRAY, 15);
	TranslateObj(ob, V(0, -1, 0));
}

void sketch_draw(long ticks)


@@ 56,8 66,14 @@ void sketch_draw(long ticks)
		DrawObject(cubes[i]);
	}

	if (dither)
	// RotateObj(masterCube, 0, 0.01*dt, 0);
	// DrawObject(masterCube);

	DrawObject(ob);

	if (dither) {
		Dither(GetViewport());
	}
}

void sketch_input(InputState input)

M test/main.test.c => test/main.test.c +1 -0
@@ 26,6 26,7 @@ int main(void)
	RenderTests();
	EndpointTests();
	RasterizationTests();
	LightTests();

	printf("=================================\n");
	printf("%d passed, %d failed.\n", gTestSuccesses, gTestFailures);

M test/tests.h => test/tests.h +3 -0
@@ 60,3 60,6 @@ void TestIncrementEndpoints(void);
void RasterizationTests(void);
void TestRasterLineShallow(void);
void TestRasterPolygon(void);

void LightTests(void);
void TestDiffuseLight(void);