www.pudn.com > CG2Programs.rar > graphics.h


#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_


#include "device.h"

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif


/* ============================================================ */
/* Styles for lines */
/* ============================================================ */
typedef enum { SOLID, DASHED, DOTTED } pLineType;


/* ============================================================ */
/* Data Structure Types */
/* ============================================================ */

/* A two-dimensional point in world coordinates */
typedef struct {
  float x;
  float y;
} wcPt2;

/* A three-dimensional point in world coordinates */
typedef struct {
  float x;
  float y;
  float z;
} wcPt3;


/* A 3x3 matrix */
typedef float pMatrix3[3][3];

/* A 4x4 matrix */
typedef float pMatrix4[4][4];



/* ============================================================ */
/* Convenience routines for data structures */
/* ============================================================ */

extern void wcPt2Show (wcPt2 pt);
extern void wcPt3Show (wcPt3 pt);
extern void setWcPt2 (wcPt2 * pt, float x, float y);
extern void setWcPt3 (wcPt3 * pt, float x, float y, float z);

extern void matrix3x3Show (pMatrix3 m);
extern void matrix4x4Show (pMatrix4 m);


/* ============================================================ */
/* A PHIGS-like system stores a multitude of State variables */
/* ============================================================ */

typedef struct {
  /* style for drawing lines */
  pLineType lineType;
  /* current transformation matrix */
  pMatrix3 ctm;
} PhigsState;


extern void lineDDA (int xa, int ya, int xb, int yb);
extern void circleMidpoint (int xCenter, int yCenter, int radius);
extern void ellipseMidpoint (int xCenter, int yCenter, int Rx, int Ry);
extern void scanFill (int cnt, dcPt * pts);


/* ============================================================ */
/* PHIGS-like graphics routines */ 
/* ============================================================ */

extern void pSetLineType (pLineType typ);

extern void pPoint (float x, float y);
extern void pPolyline (int npts, wcPt2 * pts);
extern void pPolymarker (int npts, wcPt2 * pts);
extern void pFillArea (int npts, wcPt2 * pts);
extern void pText (wcPt2 position, char * outString);
extern void pCircle (wcPt2 center, float radius);
extern void pPolyline3 (int npts, wcPt3 * pts);

extern float pToRadians (float a);
extern void pMatrix3SetIdentity (pMatrix3 m);
extern void pMatrix3PreMultiply (pMatrix3 m, pMatrix3 t);
extern void pScale2 (float sx, float sy, wcPt2 refPt);
extern void pRotate2 (float a, wcPt2 refPt);
extern void pTranslate2 (int tx, int ty);
extern void pTransformPoints2 (int npts, wcPt2 * pts);

#endif