-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrawElement.h
More file actions
111 lines (96 loc) · 2.28 KB
/
DrawElement.h
File metadata and controls
111 lines (96 loc) · 2.28 KB
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
105
106
107
108
109
110
111
#pragma once
#ifndef _DRAWELEMENT_H_
#define _DRAWELEMENT_H_
#include<Windows.h>
#include"Transform.h"
#include"MyMath.h"
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define TEXTURE_MODE 4
#define COLOR_MODE 2
#define WINDOWS_CLASS_NAME "DrawElement"
#define PI 3.1415926536
class Scanline {
public:
Scanline();
~Scanline();
int y;
double x;
double width;
point leftPoint, rightPoint;
point stepPoint;
vect oriLeftVect, oriRightVect;
vect oriStepVect;
};
class Trapezoid {
public:
Trapezoid();
~Trapezoid();
double top;
double bottom;
point left1, left2;
point right1, right2;
vect oriLeft1, oriLeft2;
vect oriRight1, oriRight2;
};
class PixelOutput {
public:
PixelOutput();
~PixelOutput();
vect normal;
vect color;
vect originPos;
};
class DrawElement {
public:
DrawElement();
~DrawElement();
HRESULT initDevice();
void clearBuffer();
void destoryDevice();
static LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void drawTriangle(point* v1, point* v2, point*v3);
int divideTriangle(point* finalV1, point* finalV2, point* finalV3, Trapezoid* trape1, Trapezoid* trape2, vect* oriV1, vect* oriV2, vect* oriV3);
void randerTriangle(Trapezoid* trape);
void initScanLine(Scanline *scline, int yPos, Trapezoid* trape);
void drawScanLine(Scanline *scline);
void updateScene();
void loadTexture(char* filename);
void getTextureColor(vect* out, point* nowPoint);
void drawDeferred();
UINT renderMode;
Transform transform;//矩阵变换
vect lightDiffuse;//
vect lightSpecular;
vect lightAmbient;
vect lightPos;
vect cameraPosition;
vect cameraTarget;
vect cameraUp;
HDC hMemDC;//一个兼容设备的设备描述句柄
HBITMAP hBITMAP;//一个位图句柄
HDC hdc;//windows设备描述句柄
LARGE_INTEGER startTick = {};
LARGE_INTEGER endTick = {};
LARGE_INTEGER frequency_ = {};
FLOAT fps_ = 60.0f;
bool isDeferred = false;
private:
float ks = 1;//高光系数
float kd = 1;//漫反射光系数
float ka = 1;//环境光系数
float ke = 0.1f; //自发射光系数
int shininess = 3;
int textureWidth;
int textureHeight;
int textureChannal;
HINSTANCE hinstSelf;
HWND hwnd;//windows 窗体句柄
BITMAPINFO bmpInfo;//需要画的位图信息
unsigned char *textureBuffer;
PixelOutput *gBuffer;
UINT32 *bmpBuffer_;
double *zBuffer_;
UINT backGroundColor;
};
#endif // !_DRAWELEMENT_H_