-
Notifications
You must be signed in to change notification settings - Fork 1
/
CGWorkView.h
executable file
·268 lines (233 loc) · 8.7 KB
/
CGWorkView.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// CGWorkView.h : interface of the CCGWorkView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_CGWORKVIEW_H__5857316D_EA60_11D5_9FD5_00D0B718E2CD__INCLUDED_)
#define AFX_CGWORKVIEW_H__5857316D_EA60_11D5_9FD5_00D0B718E2CD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "gl\gl.h" // Include the standard CGWork headers
#include "gl\glu.h" // Add the utility library
#include "Light.h"
#include "vec4.h"
#include "line.h"
#include <unordered_map>
#include "polygon.h"
#include <vector>
#include "model.h"
#include "PngWrapper.h"
class CCGWorkView : public CView
{
protected: // create from serialization only
CCGWorkView();
DECLARE_DYNCREATE(CCGWorkView)
// Attributes
public:
CCGWorkDoc* GetDocument();
// Operations
public:
private:
int m_nAxis; // Axis of Action, X Y or Z
int m_nAction; // Rotate, Translate, Scale
int m_nView; // Orthographic, perspective
int m_nLightView; // Point light view
int polygon_normal;
int vertex_normal;
bool given_polygon_normal;
bool given_vertex_normal;
bool m_bIsPerspective; // is the view perspective
int render_type; // rendering type
int m_render_target; // render to a file or to the screent
bool m_override_normals;
bool m_back_face_culling;
bool m_silhouette;
bool m_light_view;
double m_silhouette_thickness;
CString m_strItdFileName; // file name of IRIT data
int m_nLightShading; // shading: Flat, Gouraud.
double m_lMaterialAmbient; // The Ambient in the scene
double m_lMaterialDiffuse; // The Diffuse in the scene
double m_lMaterialSpecular; // The Specular in the scene
int m_nMaterialCosineFactor; // The cosine factor for the specular
class x_z_c_n_point {
friend bool operator<(const x_z_c_n_point& l, const x_z_c_n_point& r){
return (l.x < r.x);
}
public:
double x;
double z;
COLORREF c;
vec4 n;
};
// our functions
void DrawLine(double *z_arr, COLORREF *arr, vec4 &p1, vec4 &p2, COLORREF p1_color, vec4* p1_normal = NULL, COLORREF p2_color = NULL, vec4* p2_normal = NULL, std::unordered_map<int, std::vector<x_z_c_n_point>>* x_y = NULL);
void DrawBoundBox(double *z_arr, COLORREF *arr, model &m, mat4 cur_transform, COLORREF color);
void ScanConversion(double *z_arr, COLORREF *arr, polygon &p, mat4 cur_transform, COLORREF color);
void SetBackgound();
void RenderLightScene();
void set_light_pos(mat4 view_space_trans);
double LinePointDepth(vec4 &p1, vec4 &p2, int x, int y);
COLORREF ApplyLight(COLORREF in_color, vec4 normal, vec4 pos);
COLORREF m_color_wireframe;
COLORREF m_background_color;
COLORREF m_boundbox_color;
COLORREF m_vertex_norm_color;
COLORREF m_polygon_norm_color;
COLORREF m_silhouette_color;
LightParams m_lights[MAX_LIGHT]; //configurable lights array
LightParams m_ambientLight; //ambient light (only RGB is used)
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCGWorkView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
void OnWriteframeColor(); // The wireframe colour
protected:
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CCGWorkView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
BOOL InitializeCGWork();
BOOL SetupViewingFrustum(void);
BOOL SetupViewingOrthoConstAspect(void);
virtual void RenderScene();
virtual LRESULT OnMouseMovement(WPARAM wparam, LPARAM lparam);
mat4 m_tarnsform;
mat4 m_screen_space_trans;
mat4 m_prespective_trans;
mat4 m_screen_space_scale;
mat4 m_screen_space_translate;
vec4 m_camera_pos;
vec4 m_camera_at;
vec4 m_camera_up;
double m_presepctive_d;
double m_presepctive_alpha;
double m_ambient_k;
double m_diffuse_k;
double m_speculr_k;
double m_speculr_n;
int m_inverse = 1;
std::vector<bool> active_modules;
std::string m_pic_name;
PngWrapper m_pngHandle; // Png handle class for writing
PngWrapper m_pngBackground; // Png handle class for background
bool m_active_background;
bool m_valid_background;
int m_background_type;
int m_mouse_xpos;
int m_mouse_ypos;
bool m_object_space_trans;
bool m_bound_box;
HGLRC m_hRC; // holds the Rendering Context
HDC m_hDC;
CDC* m_pDC; // holds the Device Context
int m_WindowWidth; // hold the windows width
int m_WindowHeight; // hold the windows height
int m_OriginalWindowWidth; // hold the original window width
int m_OriginalWindowHeight; // hold the original window height
double m_AspectRatio; // hold the fixed Aspect Ration
double m_mouse_sensetivity;
COLORREF *m_screen;
double *z_buffer;
HBITMAP m_map;
// Generated message map functions
protected:
//{{AFX_MSG(CCGWorkView)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnFileLoad();
afx_msg void OnViewOrthographic();
afx_msg void OnUpdateViewOrthographic(CCmdUI* pCmdUI);
afx_msg void OnViewPerspective();
afx_msg void OnUpdateViewPerspective(CCmdUI* pCmdUI);
afx_msg void OnActionRotate();
afx_msg void OnUpdateActionRotate(CCmdUI* pCmdUI);
afx_msg void OnActionScale();
afx_msg void OnUpdateActionScale(CCmdUI* pCmdUI);
afx_msg void OnActionTranslate();
afx_msg void OnUpdateActionTranslate(CCmdUI* pCmdUI);
afx_msg void OnAxisX();
afx_msg void OnUpdateAxisX(CCmdUI* pCmdUI);
afx_msg void OnAxisY();
afx_msg void OnUpdateAxisY(CCmdUI* pCmdUI);
afx_msg void OnAxisZ();
afx_msg void OnUpdateAxisZ(CCmdUI* pCmdUI);
afx_msg void OnAxisXY();
afx_msg void OnUpdateAxisXY(CCmdUI* pCmdUI);
afx_msg void OnBoundBox();
afx_msg void OnUpdateBoundBox(CCmdUI* pCmdUI);
afx_msg void OnLightShadingFlat();
afx_msg void OnUpdateLightShadingFlat(CCmdUI* pCmdUI);
afx_msg void OnLightShadingGouraud();
afx_msg void OnUpdateLightShadingGouraud(CCmdUI* pCmdUI);
afx_msg void OnLightConstants();
afx_msg void OnActionToggleView();
afx_msg void OnUpdateActionToggleView(CCmdUI* pCmdUI);
afx_msg void OnActionResetView();
afx_msg void OnActionClearAll();
afx_msg void OnOptionMouseSensetivity();
afx_msg void OnOptionPrespectiveControl();
afx_msg void OnOptionOthers();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPolygonGiven();
afx_msg void OnPolygonCalculated();
afx_msg void OnUpdatePolygonCalculated(CCmdUI *pCmdUI);
afx_msg void OnUpdatePolygonGiven(CCmdUI *pCmdUI);
afx_msg void OnVertexGiven();
afx_msg void OnUpdateVertexGiven(CCmdUI *pCmdUI);
afx_msg void OnVertexCalculated();
afx_msg void OnUpdateVertexCalculated(CCmdUI *pCmdUI);
afx_msg void OnViewWireframe();
afx_msg void OnUpdateViewWireframe(CCmdUI *pCmdUI);
afx_msg void OnUpdateViewSolid(CCmdUI *pCmdUI);
afx_msg void OnViewSolid();
afx_msg void OnViewZ();
afx_msg void OnUpdateViewZ(CCmdUI *pCmdUI);
afx_msg void OnLightShadingPhong();
afx_msg void OnUpdateLightShadingPhong(CCmdUI *pCmdUI);
afx_msg void OnRenderTofile();
afx_msg void OnUpdateRenderTofile(CCmdUI *pCmdUI);
afx_msg void OnUpdateRenderToscreen(CCmdUI *pCmdUI);
afx_msg void OnRenderToscreen();
afx_msg void OnBackgroundSetimage();
afx_msg void OnBackgroundActive();
afx_msg void OnUpdateBackgroundActive(CCmdUI *pCmdUI);
afx_msg void OnBackgroundRepeat();
afx_msg void OnUpdateBackgroundRepeat(CCmdUI *pCmdUI);
afx_msg void OnBackgroundStretch();
afx_msg void OnUpdateBackgroundStretch(CCmdUI *pCmdUI);
afx_msg void OnOptionsBackfaceculling();
afx_msg void OnUpdateOptionsBackfaceculling(CCmdUI *pCmdUI);
afx_msg void OnOptionsNormalinverse();
afx_msg void OnUpdateOptionsNormalinverse(CCmdUI *pCmdUI);
afx_msg void OnUpdateOptionsOverridegivennormal(CCmdUI *pCmdUI);
afx_msg void OnOptionsOverridegivennormal();
afx_msg void OnOptionsAddsilhouette();
afx_msg void OnUpdateOptionsAddsilhouette(CCmdUI *pCmdUI);
afx_msg void OnLightLight1pov();
afx_msg void OnUpdateLightLight1pov(CCmdUI *pCmdUI);
afx_msg void OnLight1povZ();
afx_msg void OnLight1povY();
afx_msg void OnLight1povX();
afx_msg void OnLight1povNegX();
afx_msg void OnLight1povNegY();
afx_msg void OnLight1povNegZ();
};
#ifndef _DEBUG // debug version in CGWorkView.cpp
inline CCGWorkDoc* CCGWorkView::GetDocument()
{ return (CCGWorkDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CGWORKVIEW_H__5857316D_EA60_11D5_9FD5_00D0B718E2CD__INCLUDED_)