Source

pebble / cube / src / wireframe.c

Full commit
/** \file
 * Wireframe drawing routine.
 */
#include "wireframe.h"
#include "draw.h"
#include <string.h>

void
wireframe_draw(
	GContext * ctx,
	const camera_t * camera,
	const int num_vertices,
	const vertex_t * vertices,
	const int num_edges,
	const edge_t * edges,
	pixel_t * pixels,
	pixel_t * temp
)
{
	for (int i = 0 ; i < num_vertices ; i++)
		camera_project(camera, &vertices[i], &temp[i]);
	
	for (int i = 0 ; i < num_edges ; i++)
	{
		const edge_t * const e = &edges[i];
		const pixel_t * old_p0 = &pixels[e->v0];
		const pixel_t * old_p1 = &pixels[e->v1];

/*
		if (old_p0->x != (uint8_t) -1 && old_p1->x != (uint8_t) -1)
			graphics_draw_line(
				ctx,
				old_p0->x, old_p0->y,
				old_p1->x, old_p1->y
			);
*/

		const pixel_t * new_p0 = &temp[e->v0];
		const pixel_t * new_p1 = &temp[e->v1];

		if (new_p0->x != (uint8_t) -1
		&&  new_p1->x != (uint8_t) -1)
			graphics_draw_line(
				ctx,
				GPoint(new_p0->x, new_p0->y),
				GPoint(new_p1->x, new_p1->y)
			);
	}

	// Now copy the new locations to the permanent place
	memcpy(pixels, temp, num_vertices * sizeof(*pixels));
}