/* Functions to draw unit primitives.                                 */
/* Scaling/translation/rotation is left to GL co-ordinate operations. */
/* Philip Richard Boulain <prb102@ecs.soton.ac.uk> */

#include "getglut.h"

/* Colouring code removed; static draw method invocation allowed. */
/* WARNING: NORMALS ARE NOT GENERATED FOR SPHERES AND CONES, ONLY CYLINDERS! */

/* A cone (circle-based pyramid). */
/* The base has a diameter of one world unit. */
/* Arguments:
    segments -- number of faces per eighth of circular base
    colours  -- 0 is tip; 1 is centre of base;
                2 to (segments*8)+1 are around the base
    height   -- height in world units
*/
typedef struct primcone_s {
	void (*destroy) (struct primcone_s* c); /* Prepare to be free()'d */
	void (*draw)    (struct primcone_s* c); /* Draw (at origin of current co-ords) */
	int segments;
	GLfloat height;
	GLfloat* circle;
	int circlepoints;
} primcone;
void primcone_init(primcone* c, int segments, GLfloat height);
void primcone_draw(primcone* c);

/* A sphere. */
/* The diameter is one world unit. */
/* Arguments:
    segments -- number of faces per eighth of axis-aligned circle
    colours  -- 0 to (segments*4)-2 horizontal rings of verticies
*/
typedef struct primsphere_s {
	void (*destroy) (struct primsphere_s* s);
	void (*draw)    (struct primsphere_s* s);
	int segments;
	GLfloat* circle;
	int circlepoints;
} primsphere;
void primsphere_init(primsphere* s, int segments);
void primsphere_draw(primsphere* s);

/* A cylinder. */
/* One unit in diameter, one unit high. */
/* Arguments:
    segments -- number of faces per eighth of cross-section
    colours  -- 0 to (segments*8)-1 for the lower circle,
                (segments*8) to (segments*16)-1 for the upper
		(segments*16)   for the bottom centre vertex
		(segments*16)+1 for the top centre vertex
*/
typedef struct primcyl_s {
	void (*destroy) (struct primcyl_s* s);
	void (*draw)    (struct primcyl_s* s);
	int segments;
	GLfloat* circle;
	int circlepoints;
} primcylinder;
void primcylinder_init(primcylinder* s, int segments);
void primcylinder_draw(primcylinder* s);
void primcylinder_drawx(primcylinder *c, GLfloat s);
