-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrend.h
104 lines (83 loc) · 3.59 KB
/
rend.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "gz.h"
#ifndef GZRENDER_
#define GZRENDER_
/* Camera defaults */
#define DEFAULT_FOV 35.0
#define DEFAULT_IM_Z (-10.0) /* world coords for image plane origin */
#define DEFAULT_IM_Y (5.0) /* default look-at point = 0,0,0 */
#define DEFAULT_IM_X (-10.0)
#define DEFAULT_AMBIENT {0.1, 0.1, 0.1}
#define DEFAULT_DIFFUSE {0.7, 0.6, 0.5}
#define DEFAULT_SPECULAR {0.2, 0.3, 0.4}
#define DEFAULT_SPEC 32
#define MATLEVELS 100 /* how many matrix pushes allowed */
#define MAX_LIGHTS 10 /* how many lights allowed */
class GzRender{ /* define a renderer */
public:
unsigned short xres;
unsigned short yres;
GzPixel *pixelbuffer; /* frame buffer array */
char* framebuffer;
GzCamera m_camera;
short matlevel; /* top of stack - current xform */
GzMatrix Ximage[MATLEVELS]; /* stack of xforms (Xsm) */
GzMatrix Xnorm[MATLEVELS]; /* xforms for norms (Xim) */
GzMatrix Xsp; /* NDC to screen (pers-to-screen) */
GzColor flatcolor; /* color state for flat shaded triangles */
int interp_mode;
int numlights;
GzLight lights[MAX_LIGHTS];
GzLight ambientlight;
GzColor Ka, Kd, Ks;
float spec; /* specular power */
GzTexture tex_fun; /* tex_fun(float u, float v, GzColor color) */
// Constructors
GzRender(int xRes, int yRes);
~GzRender();
// Function declaration
// HW1: Display methods
int GzDefault();
int GzBeginRender();
int GzPut(int i, int j, GzIntensity r, GzIntensity g, GzIntensity b, GzIntensity a, GzDepth z);
int GzGet(int i, int j, GzIntensity *r, GzIntensity *g, GzIntensity *b, GzIntensity *a, GzDepth *z);
int GzFlushDisplay2File(FILE* outfile);
int GzFlushDisplay2FrameBuffer();
// HW2: Render methods
int GzPutAttribute(int numAttributes, GzToken *nameList, GzPointer *valueList);
int GzPutTriangle(int numParts, GzToken *nameList, GzPointer *valueList);
// HW3
int GzPutCamera(GzCamera camera);
int GzPushMatrix(GzMatrix matrix, bool normIdentity = false);
int GzPopMatrix();
// Extra methods: NOT part of API - just for general assistance */
inline int ARRAY(int x, int y) { return (x + y * xres); } /* simplify fbuf indexing */
inline short ctoi(float color) { return(short)((int)(color * ((1 << 12) - 1))); } /* convert float color to GzIntensity short */
inline float itoc(short intensity) { return (float)intensity / ((1 << 12) - 1);}
template <typename T>
inline T clamp(T value, T minVal, T maxVal) {
return (value < minVal) ? minVal : (value > maxVal) ? maxVal : value;
}
// Helper Functions
void normalize(GzCoord vector);
void matrixMultiplyVector(const GzMatrix mat, const float input[4], float output[4]);
float* edgeVector(const float v1[], const float v2[]);
float* crossProduct(const float v1[], const float v2[]);
float dotProduct(const float v1[], const float v2[]);
void identity(GzMatrix mat);
float interpolate(const float vec1[], const float vec2[], const float vec3[], float n1, float n2, float n3, int x, int y);
void getColor(float normal[], float color[], float Kd[], float Ks[], float Ka[]);
// Xform helper functions
void setCamXiw(GzCamera* camera);
void setCamXpi(GzCamera* camera);
// Object Translation
int GzRotXMat(float degree, GzMatrix mat);
int GzRotYMat(float degree, GzMatrix mat);
int GzRotZMat(float degree, GzMatrix mat);
int GzTrxMat(GzCoord translate, GzMatrix mat);
int GzScaleMat(GzCoord scale, GzMatrix mat);
//Project functions
int GzSobelEdgeDetection();
bool isValidPixel(int x, int y);
float getGradient(int x, int y, GzPixel* edgeMap, int param = 1);
};
#endif