~zjm/Moon3D

d3d27c091e9a71d8e68a18ab4abda11409afb229 — Zack Michener 4 months ago 89323f6
remove old DrawMesh functions
5 files changed, 6 insertions(+), 33 deletions(-)

M src/3d/light.c
M src/3d/light.h
M src/3d/render.c
M src/3d/render.h
M src/sketch.c
M src/3d/light.c => src/3d/light.c +1 -14
@@ 4,7 4,7 @@
#include <stdlib.h>
#include <math.h>

static double ambient = 0.5;
static double ambient = 0.2;

void AmbientLight(double amb)
{


@@ 20,19 20,6 @@ LightSource *DirectionLight(Vector direction, double intensity)
	return l;
}

double *LightMesh(Mesh *mesh)
{
	double *shades = NULL;
	LightSource **lights = NULL;
	list_push(lights, DirectionLight(V(0, 0, -1), 1));

	for (int i = 0; i < NumFacets(mesh); i++) {
		list_push(shades, LightPolygon(mesh->facets[i], mesh->color, lights));
	}

	return shades;
}

double LightPolygon(Polygon *polygon, Color color, LightSource **lights)
{
	return color * fmin((ambient + DiffuseLight(polygon, lights)), 1);

M src/3d/light.h => src/3d/light.h +0 -1
@@ 11,6 11,5 @@ typedef struct LightSource {

void AmbientLight(double amb);
LightSource *DirectionLight(Vector direction, double intensity);
double *LightMesh(Mesh *mesh);
double LightPolygon(Polygon *polygon, Color color, LightSource **lights);
double DiffuseLight(Polygon *polygon, LightSource **lights);

M src/3d/render.c => src/3d/render.c +0 -13
@@ 78,19 78,6 @@ void DrawObject(Object *object)
	list_free(lights);
}

void DrawMesh(Mesh *mesh)
{
	int i;

	double *shades = LightMesh(mesh);

	for (i = 0; i < list_count(mesh->facets); i++) {
		DrawPolygon(mesh->facets[i], shades[i]);
	}

	list_free(shades);
}

void DrawPolygon(Polygon *polygon, Color color)
{
	Polygon *image = ProjectPolygon(polygon);

M src/3d/render.h => src/3d/render.h +0 -1
@@ 27,7 27,6 @@ void SetViewport(Pixel *pixels, int width, int height);
Viewport GetViewport(void);
void ClearViewport(void);

void DrawMesh(Mesh *mesh);
void DrawPolygon(Polygon *polygon, Color color);
void DrawObject(Object *object);
void WireframePolygon(Polygon *polygon, Color color);

M src/sketch.c => src/sketch.c +5 -4
@@ 49,8 49,9 @@ void sketch_setup(Pixel *pixels)
	masterCube = NewCube(DK_GRAY);
	TranslateObj(masterCube, V(0, 2, 0));

	ob = NewObelisk(DK_GRAY, 15);
	TranslateObj(ob, V(0, -1, 0));
	ob = NewObelisk(DK_GRAY, 20);
	TranslateObj(ob, V(100, -1, 0));
	RotateObj(ob, 0, rand() % 360, 0);
}

void sketch_draw(long ticks)


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

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

	DrawObject(ob);