-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifierView.cpp
800 lines (740 loc) · 16.7 KB
/
verifierView.cpp
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
// verifierView.cpp: CverifierView 类的实现
//
#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "verifier.h"
#endif
#include "verifierDoc.h"
#include "verifierView.h"
#include "gl/gl.h"
#include "gl/glu.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
constexpr auto FACE_1 = 1;
constexpr auto FACE_2 = 2;
constexpr auto FACE_3 = 3;
constexpr auto FACE_4 = 4;
constexpr auto FACE_5 = 5;
constexpr auto FACE_6 = 6;
constexpr auto FACE_7 = 7;
constexpr auto FACE_8 = 8;
constexpr auto FACE_9 = 9;
constexpr auto FACE_10 = 10;
constexpr auto FACE_11 = 11;
constexpr auto FACE_12 = 12;
// CverifierView
IMPLEMENT_DYNCREATE(CverifierView, CView)
BEGIN_MESSAGE_MAP(CverifierView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CverifierView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
// CverifierView 构造/析构
CverifierView::CverifierView() noexcept
{
m_moveStart = false;// TODO: 在此处添加构造代码
m_anglex = 0;
m_angley = 0;
m_moveX = 0;
m_moveY = 0;
camera_x = 15;
camera_y = 15;
camera_z = 35;
SetCutPosition(cut_position);
srand(time(0));
init_anglex = 10 + rand() % 7 * 10;
init_angley = 10 + rand() % 7 * 10;
}
CverifierView::~CverifierView()
{
}
BOOL CverifierView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// CverifierView 绘图
void CverifierView::RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int now_drawing_num = 0;//当前在绘制的编号
int drawn = 0;//已经绘制标记
int whole_num = 1000;
while (now_drawing_num < whole_num)//绘制whole_num个立方体
{
for (int k = 0; k < 50; k++)//绘制切割出的立方体
{
if (now_drawing_num == cut_position[k])
{
draw_cut_cube(now_drawing_num);
drawn = 1;
break;
}
if (now_drawing_num == cut_position[k] - 1)//绘制提示性立方体
{
draw_white_cube(now_drawing_num);
drawn = 1;
break;
}
}
if (drawn == 0)//绘制默认立方体
{
glColor3f(1, 0, 0);
draw_red_cube(now_drawing_num);
}
now_drawing_num++;
drawn = 0;
}
}
//设置像素格式和渲染环境
void CverifierView::GLInit()
{
m_hDC = ::GetDC(m_hWnd);
static PIXELFORMATDESCRIPTOR pfdWnd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,
0,0,0,0,0,0,0,
32,
0,0,
PFD_MAIN_PLANE,
0,
0,0,0
};
int pixelformat;
pixelformat = ChoosePixelFormat(m_hDC, &pfdWnd);
SetPixelFormat(m_hDC, pixelformat, &pfdWnd);
m_hRC = wglCreateContext(m_hDC);
wglMakeCurrent(m_hDC, m_hRC);
GLSetupRC(m_hDC);
}
// 清除渲染环境
void CverifierView::GlRelease()
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hRC);
::ReleaseDC(m_hWnd, m_hDC);
}
//处理窗口尺寸的变化
void CverifierView::GlResize(int cx, int cy)
{
double nRange = 3;
if (cy == 0) cy = 1;
glViewport(0, 0, cx, cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double)cx / cy, 0.1, 50 * nRange);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(camera_x, camera_y, camera_z, 0, 0, 0, 0, 1, 0);
}
//设置渲染环境的光照、颜色和物体的材质等
void CverifierView::GLSetupRC(HDC hdc)
{
//lighting
GLfloat ambientLight[] = { 0.2f,0.2f,0.2f,1.0f };
GLfloat diffuseLight[] = { 0.6f,0.6f,0.6f,1.0f };
GLfloat specular[] = { 1.0f,1.0f,1.0f,1.0f };
GLfloat lightPos[] = { -10.0f,10.0f,10.0f,1.0f };
//light 0
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glEnable(GL_LIGHT0);
//color material
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
//背景色
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//color
glColor3f(1, 0, 0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
void CverifierView::draw_red_cube(int name_point)
{
int x = name_point / 100;
int y = (name_point - x * 100) / 10;
int z = name_point % 10;
glInitNames();
glPushName(0);
//front face
glLoadName(FACE_7);
glBegin(GL_POLYGON);
glNormal3f(0, 0, 1);
glVertex3f(x, y, z + 1);
glVertex3f(x + 1, y, z + 1);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x, y + 1, z + 1);
glEnd();
// bottom face
glLoadName(FACE_8);
glBegin(GL_POLYGON);
glNormal3f(0, -1, 0);
glVertex3f(x, y, z);
glVertex3f(x + 1, y, z);
glVertex3f(x + 1, y, z + 1);
glVertex3f(x, y, z + 1);
glEnd();
//right face
glLoadName(FACE_9);
glBegin(GL_POLYGON);
glNormal3f(1, 0, 0);
glVertex3f(x + 1, y, z);
glVertex3f(x + 1, y + 1, z);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x + 1, y, z + 1);
glEnd();
//left face
glLoadName(FACE_10);
glBegin(GL_POLYGON);
glNormal3f(-1, 0, 0);
glVertex3f(x, y, z);
glVertex3f(x, y, z + 1);
glVertex3f(x, y + 1, z + 1);
glVertex3f(x, y + 1, z);
glEnd();
//top face
glLoadName(FACE_11);
glBegin(GL_POLYGON);
glNormal3f(0, 1, 0);
glVertex3f(x, y + 1, z);
glVertex3f(x, y + 1, z + 1);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x + 1, y + 1, z);
glEnd();
// back face
glLoadName(FACE_12);
glColor3f(1, 0, 0);
glBegin(GL_POLYGON);
glNormal3f(0, 0, -1);
glVertex3f(x, y, z);
glVertex3f(x, y + 1, z);
glVertex3f(x + 1, y + 1, z);
glVertex3f(x + 1, y, z);
glEnd();
glFlush();
}
void CverifierView::draw_white_cube(int name_point)
{
int x = name_point / 100;
int y = (name_point - x * 100) / 10;
int z = name_point % 10;
glInitNames();
glPushName(0);
//front face
glColor3f(1, 1, 1);
glLoadName(FACE_7);
glBegin(GL_POLYGON);
glNormal3f(0, 0, 1);
glVertex3f(x, y, z + 1);
glVertex3f(x + 1, y, z + 1);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x, y + 1, z + 1);
glEnd();
// bottom face
glColor3f(1, 0, 0);
glLoadName(FACE_8);
glBegin(GL_POLYGON);
glNormal3f(0, -1, 0);
glVertex3f(x, y, z);
glVertex3f(x + 1, y, z);
glVertex3f(x + 1, y, z + 1);
glVertex3f(x, y, z + 1);
glEnd();
//right face
glLoadName(FACE_9);
glBegin(GL_POLYGON);
glNormal3f(1, 0, 0);
glVertex3f(x + 1, y, z);
glVertex3f(x + 1, y + 1, z);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x + 1, y, z + 1);
glEnd();
//left face
glLoadName(FACE_10);
glBegin(GL_POLYGON);
glNormal3f(-1, 0, 0);
glVertex3f(x, y, z);
glVertex3f(x, y, z + 1);
glVertex3f(x, y + 1, z + 1);
glVertex3f(x, y + 1, z);
glEnd();
//top face
glLoadName(FACE_11);
glBegin(GL_POLYGON);
glNormal3f(0, 1, 0);
glVertex3f(x, y + 1, z);
glVertex3f(x, y + 1, z + 1);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x + 1, y + 1, z);
glEnd();
// back face
glLoadName(FACE_12);
glColor3f(1, 0, 0);
glBegin(GL_POLYGON);
glNormal3f(0, 0, -1);
glVertex3f(x, y, z);
glVertex3f(x, y + 1, z);
glVertex3f(x + 1, y + 1, z);
glVertex3f(x + 1, y, z);
glEnd();
glFlush();
}
void CverifierView::draw_cut_cube(int name_point)
{
int r, g, b;
if (m_selected_names.size() > 0)
{
r = 0, g = 0, b = 1;
}
else {
r = 0, g = 1, b = 1;
}
int x = name_point / 100;
int y = (name_point - x * 100) / 10;
int z = name_point % 10;
glPushMatrix();
glRotatef(init_anglex, 0, 1, 0);
glRotatef(init_angley, 0, 0, 1);
glTranslated(-15, 0, 0);
glTranslatef(m_moveX, 0, 0);
glTranslatef(0, -m_moveY, 0);
glRotatef(m_angley, 0, 0, 1);
glRotatef(m_anglex, 0, 1, 0);
glInitNames();
glPushName(0);
//front face
glLoadName(FACE_1);
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glNormal3f(0, 0, 1);
glVertex3f(x, y, z + 1);
glVertex3f(x + 1, y, z + 1);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x, y + 1, z + 1);
glEnd();
// bottom face
glLoadName(FACE_2);
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glNormal3f(0, -1, 0);
glVertex3f(x, y, z);
glVertex3f(x + 1, y, z);
glVertex3f(x + 1, y, z + 1);
glVertex3f(x, y, z + 1);
glEnd();
//right face
glLoadName(FACE_3);
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glNormal3f(1, 0, 0);
glVertex3f(x + 1, y, z);
glVertex3f(x + 1, y + 1, z);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x + 1, y, z + 1);
glEnd();
//left face
glLoadName(FACE_4);
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glNormal3f(-1, 0, 0);
glVertex3f(x, y, z);
glVertex3f(x, y, z + 1);
glVertex3f(x, y + 1, z + 1);
glVertex3f(x, y + 1, z);
glEnd();
//top face
glLoadName(FACE_5);
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glNormal3f(0, 1, 0);
glVertex3f(x, y + 1, z);
glVertex3f(x, y + 1, z + 1);
glVertex3f(x + 1, y + 1, z + 1);
glVertex3f(x + 1, y + 1, z);
glEnd();
// back face
glLoadName(FACE_6);
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glNormal3f(0, 0, -1);
glVertex3f(x, y, z);
glVertex3f(x, y + 1, z);
glVertex3f(x + 1, y + 1, z);
glVertex3f(x + 1, y, z);
glEnd();
glPopMatrix();
glFlush();
}
void CverifierView::ProcessSelection(int Xpos, int Ypos)
{
GLuint SelectBuffer[64]{};
GLint hits = 0, viewport[4]{};
//建立选择缓冲区
glSelectBuffer(64, SelectBuffer);
//获得当前视窗信息
glGetIntegerv(GL_VIEWPORT, viewport);
CRect rect;
GetClientRect(rect);
Ypos = rect.Height() - Ypos;
//设置投影变换
glMatrixMode(GL_PROJECTION);
glPushMatrix();
//切换到选择模式
glRenderMode(GL_SELECT);
//定义选择视景体
//根据鼠标位置定义选择矩阵
//拾取区域的宽和高都是1
glLoadIdentity();
gluPickMatrix(Xpos, Ypos, 1, 1, viewport);
//乘以投影变换的矩阵,该投影矩阵应该和绘制场景时的投影矩阵一致
//GlResize函数里完成了投影变换
double nRange = 3;
float cx = rect.Width();
float cy = rect.Height();
gluPerspective(60, (double)cx / cy, 0.1, 50 * nRange);
//模型视变换
glMatrixMode(GL_MODELVIEW);
RenderScene();
//切换到绘图模式,返回选择缓冲区中的拾取记录数目
hits = glRenderMode(GL_RENDER);
//恢复投影变换矩阵
glMatrixMode(GL_PROJECTION);
glPopMatrix();
//返回模型视矩阵的模式
glMatrixMode(GL_MODELVIEW);
m_selected_names.clear();
if (hits > 0)
{
int current = 0;
for (int i = 0; i < hits; i++)
{
int namecount = SelectBuffer[current];
float zmin = SelectBuffer[current + 1];
float zmax = SelectBuffer[current + 2];
current += 3;
for (int j = 0; j < namecount; j++)
{
m_selected_names.push_back(SelectBuffer[current]);
current++;
}
}
}
}
void CverifierView::SetCutPosition(int cut_position[])
{
srand(time(0));
int random_num = rand() % 100;
cut_position[0] = random_num * 10 + 9;
int left = 1, right = 2, up = 3, down = 4;
int now_num = random_num;
int i = 1;
while (i < 50) {
int choice = rand() % 4 + 1;
if (choice == left) {
if (now_num < 9) {}
else {
cut_position[i] = (now_num - 10) * 10 + 9;
now_num -= 10;
i++;
}
}
else if (choice == up) {
if ((now_num + 1) % 10 == 0) {}
else {
cut_position[i] = (now_num + 1) * 10 + 9;
now_num += 1;
i++;
}
}
else if (choice == down) {
if (now_num % 10 == 0) {}
else
{
cut_position[i] = (now_num - 1) * 10 + 9;
now_num -= 1;
i++;
}
}
else if (choice == right) {
if (now_num > 89) {}
else
{
cut_position[i] = (now_num + 10) * 10 + 9;
now_num += 10;
i++;
}
}
}
}
BOOL CverifierView::judge()
{
int tempx = m_anglex, tempy = m_angley;
while (tempx > 0) {
tempx -= 360;
}
while (tempy > 0) {
tempy -= 360;
}
float distance_anglex = abs(tempx + init_anglex);
float distance_angley = abs(tempy + init_angley);
if ((distance_anglex + distance_angley) < 8 && m_moveX < 15.5 && m_moveX>14.5 && m_moveY > -0.5 && m_moveY < 0.5) {
return true;
}
else return false;
}
void CverifierView::OnDraw(CDC* /*pDC*/)
{
CverifierDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
RenderScene();
SwapBuffers(m_hDC);
}
// CverifierView 打印
void CverifierView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CverifierView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CverifierView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CverifierView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void CverifierView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CverifierView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CverifierView 诊断
#ifdef _DEBUG
void CverifierView::AssertValid() const
{
CView::AssertValid();
}
void CverifierView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CverifierDoc* CverifierView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CverifierDoc)));
return (CverifierDoc*)m_pDocument;
}
#endif //_DEBUG
// CverifierView 消息处理程序
int CverifierView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
GLInit();
return 0;
}
void CverifierView::OnDestroy()
{
CView::OnDestroy();
// TODO: 在此处添加消息处理程序代码
wglMakeCurrent(NULL, NULL);
GlRelease();
}
void CverifierView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
GlResize(cx, cy);
}
BOOL CverifierView::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return true;
}
void CverifierView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_selected_names.size() > 0)
{
if (nFlags & MK_CONTROL)
{
if (!m_moveStart)
{
m_LastX = point.x;
m_LastY = point.y;
m_moveStart = true;
}
else if (nFlags & MK_LBUTTON)
{
float yOffset = point.y - m_LastY;
m_LastY = point.y;
float xOffset = point.x - m_LastX;
m_LastX = point.x;
m_anglex += xOffset / 2.0;
m_angley += yOffset / 2.0;
if (m_anglex < 0)
m_anglex += 360;
if (m_angley < 0)
m_angley += 360;
CRect rect;
GetClientRect(rect);
InvalidateRect(rect);
}
else;
}
if (nFlags & MK_SHIFT)
{
if (!m_moveStart)
{
m_LastX = point.x;
m_LastY = point.y;
m_moveStart = true;
}
else if (nFlags & MK_LBUTTON)
{
float yOffset = point.y - m_LastY;
m_LastY = point.y;
float xOffset = point.x - m_LastX;
m_LastX = point.x;
m_moveX += xOffset / 10.0;
m_moveY += yOffset / 10.0;
CRect rect;
GetClientRect(rect);
InvalidateRect(rect);
}
else;
}
}
CView::OnMouseMove(nFlags, point);
}
void CverifierView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (!(nFlags & MK_CONTROL))
{
ProcessSelection(point.x, point.y);
CRect rect;
GetClientRect(rect);
InvalidateRect(rect);
}
CView::OnLButtonDown(nFlags, point);
}
void CverifierView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CRect rect;
// TODO: 在此添加消息处理程序代码和/或调用默认值
//选中情况下方向键控制角度变换
if (m_selected_names.size() > 0) {
switch (nChar)
{
case VK_LEFT:
{
m_anglex -= 10;
if (m_anglex < 0)
m_anglex += 360;
GetClientRect(rect);
InvalidateRect(rect);
break;
}
case VK_RIGHT:
{
m_anglex += 10;
if (m_anglex < 0)
m_anglex += 360;
GetClientRect(rect);
InvalidateRect(rect);
break;
}
case VK_UP:
{
m_angley += 10;
if (m_angley < 0)
m_angley += 360;
GetClientRect(rect);
InvalidateRect(rect);
break;
}
case VK_DOWN:
{
m_angley -= 10;
if (m_angley < 0)
m_angley += 360;
GetClientRect(rect);
InvalidateRect(rect);
break;
}
default:
break;
}
}
//回退
if (nChar == VK_F2)
{
m_moveX = 0;
m_moveY = 0;
m_anglex = 0;
m_angley = 0;
GetClientRect(rect);
InvalidateRect(rect);
}
//验证
if (nChar == VK_F1) {
if (judge()) {
MessageBox("Pass", "结果", MB_OK);
}
else {
MessageBox("Fail", "结果", MB_OK);
}
}
//重开
if (nChar == VK_F3) {
SetCutPosition(cut_position);
srand(time(0));
init_anglex = 10 + rand() % 7 * 10;
init_angley = 10 + rand() % 7 * 10;
GetClientRect(rect);
InvalidateRect(rect);
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}