-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNNView.cpp
766 lines (573 loc) · 16.1 KB
/
NNView.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
// NNView.cpp : implementation of the CNNView class
//
#include "stdafx.h"
#include "NN.h"
#include "NNDoc.h"
#include "NNView.h"
#include "ViewParamDlg.h"
#include "NeuralNet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNNView
IMPLEMENT_DYNCREATE(CNNView, CView)
BEGIN_MESSAGE_MAP(CNNView, CView)
//{{AFX_MSG_MAP(CNNView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_BUTTON_VIEW_PARAM, OnButtonViewParam)
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_RBUTTONDBLCLK()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNNView construction/destruction
CNNView::CNNView()
{
// TODO: add construction code here
//JAC insert
m_MaxX=1.0;
m_MinX=-1.0;
m_MaxY=1.0;
m_MinY=-1.0;
m_MaxZ=1.0;
m_MinZ=-1.0;
//RotX=0.0;
//RotY=0.0;
m_RotX=0.0;
m_RotY=0.0;
m_MouseRotSensativity=10.0;
m_MouseTransSensativity=0.01;
m_MouseZoomSensativity=0.01;
m_PointSize=0.1;
m_NeuronSize=0.1;
m_NormalSize=0.1;
m_DrawAxes=false;
m_DrawNeurons=true;
m_DrawPoints=true;
m_DrawEdges=true;
m_DrawFaces=true;
m_LightingTwoSides=false;
m_RotAngle=0.0;
m_TransX=0.0;
m_TransY=0.0;
m_Zoom=1.0;
// init rotation matrix
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
m_ViewMat[i*4+j]= (i==j)? 1.0:0.0;
}
CNNView::~CNNView()
{
//when trying to close the view make sure that no thread is running
//mark that training continously is not needed anymore.
CNNDoc* pDoc = GetDocument();
pDoc->WaitUntilThreadTerminates ();
}
BOOL CNNView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CNNView drawing
void CNNView::OnDraw(CDC* pDC)
{
CNNDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPalette* ppalOld = pDC->SelectPalette(&m_Pal, 0);
pDC->RealizePalette();
// Make the HGLRC current.
BOOL bResult = wglMakeCurrent (pDC->m_hDC, m_hrc);
#ifdef MY_DEBUG
if (!bResult) {
TRACE("wglMakeCurrent Failed %x\r\n", GetLastError() ) ;
}
#endif
// Draw.
DrawScene(pDoc) ;
glFinish(); // wait untill al GL commands have been processed
// Swap buffers.
SwapBuffers(pDC->m_hDC) ;
// Select old palette.
if (ppalOld) pDC->SelectPalette(ppalOld, 0);
wglMakeCurrent(NULL, NULL) ;
}
/////////////////////////////////////////////////////////////////////////////
// CNNView printing
BOOL CNNView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CNNView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CNNView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CNNView diagnostics
#ifdef _DEBUG
void CNNView::AssertValid() const
{
CView::AssertValid();
}
void CNNView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CNNDoc* CNNView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNNDoc)));
return (CNNDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNNView message handlers
int CNNView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDC dc(this) ;
#ifdef MY_DEBUG
TRACE("window created") ;
#endif
//
// Fill in the pixel format descriptor.
//
PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)) ;
#ifdef MY_DEBUG
TRACE("mem set") ;
#endif
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1 ;
pfd.dwFlags = PFD_DOUBLEBUFFER |
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW ;
pfd.iPixelType = PFD_TYPE_RGBA ;
pfd.cColorBits = 24 ;
pfd.cDepthBits = 32 ;
pfd.iLayerType = PFD_MAIN_PLANE ;
#ifdef MY_DEBUG
TRACE("pfd set") ;
#endif
int nPixelFormat = ChoosePixelFormat(dc.m_hDC, &pfd);
if (nPixelFormat == 0)
{
#ifdef MY_DEBUG
TRACE("ChoosePixelFormat Failed %d\r\n",GetLastError()) ;
#endif
return -1;
}
#ifdef MY_DEBUG
TRACE("Pixel Format %d\r\n",nPixelFormat) ;
#endif
BOOL bResult = SetPixelFormat (dc.m_hDC, nPixelFormat, &pfd);
if (!bResult)
{
#ifdef MY_DEBUG
TRACE("SetPixelFormat Failed %d\r\n",GetLastError()) ;
#endif
return -1 ;
}
// // Create a rendering context. //
m_hrc = wglCreateContext(dc.m_hDC);
if (!m_hrc) {
#ifdef MY_DEBUG
TRACE("wglCreateContext Failed %x\r\n", GetLastError()) ;
#endif
return -1;
}
// TODO: Add your specialized creation code here
return 0;
}
void CNNView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CClientDC dc(this) ;
BOOL bResult = wglMakeCurrent (dc.m_hDC, m_hrc);
if (!bResult)
{
#ifdef MY_DEBUG
TRACE("wglMakeCurrent Failed %x\r\n", GetLastError() ) ;
#endif
return ;
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
ReshapeFunc(cx, cy);
wglMakeCurrent(NULL, NULL);
}
void CNNView::ReshapeFunc(int Wx, int Wy)
{
GLdouble gldAspect = (GLdouble) Wx/ (GLdouble) Wy;
glViewport(0, 0 ,Wx, Wy);
//double MaxSize = m_MaxX-m_MinX;
//double MeanX=(m_MaxX+m_MinX)/2;
//double MeanY=(m_MaxY+m_MinY)/2;
double MaxSizeX=m_MaxX-m_MinX;
double MaxSizeY=m_MaxY-m_MinY;
double MaxSizeZ=m_MaxZ-m_MinZ;
double MaxSize=max(MaxSizeX,MaxSizeY);
MaxSize=max(MaxSize,MaxSizeZ);
double ar;
if (Wy==0) //it is possible in the initial creation of the window...
ar=1.0;
else
ar=(double)Wx/Wy;
if (ar>1.0){
glOrtho(-MaxSize*ar, MaxSize*ar,-MaxSize, MaxSize,-2*MaxSize, 2*MaxSize);
}
else{
glOrtho(-MaxSize, MaxSize,-MaxSize/ar, MaxSize/ar,-2*MaxSize, 2*MaxSize);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
BOOL CNNView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return true;
//return CView::OnEraseBkgnd(pDC);
}
void CNNView::DrawScene(CNNDoc* pDoc)
{
float DefaultAmbientColor[4]={0.0f,0.0f,0.0f,1.0f};
float Light1AmbientColor[4]={0.1f,0.1f,0.1f,1.0f};
float Light1DiffuseColor[4]={0.5f,0.5f,0.5f,1.0f};
float Light1SpecularColor[4]={1.0f,1.0f,1.0f,1.0f};
float Light1Position[4]={1.0f,1.0f,1.0f,0.0f};
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable (GL_BLEND);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_NORMALIZE);
//glEnable (GL_COLOR_MATERIAL);
glDisable (GL_LIGHT0);
glEnable (GL_LIGHT1);
glShadeModel(GL_SMOOTH);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, m_LightingTwoSides ? 1:0);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER ,0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT ,DefaultAmbientColor);
glLightfv(GL_LIGHT1,GL_AMBIENT,Light1AmbientColor);
glLightfv(GL_LIGHT1,GL_DIFFUSE,Light1DiffuseColor);
glLightfv(GL_LIGHT1,GL_SPECULAR,Light1SpecularColor);
glLightfv(GL_LIGHT1,GL_POSITION,Light1Position);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
GenRotMatrix();
glMultMatrixd(m_ViewMat);
glTranslated(-(m_MaxX+m_MinX)/2,-(m_MaxY+m_MinY)/2,-(m_MaxZ+m_MinZ)/2);
// axes are red
glColor3f(1.0,0.0,0.0);
double ArrowSize;
glInitNames();
// glPushName(0);
glDisable(GL_LIGHTING);
ArrowSize=m_MaxX-m_MinX;
ArrowSize=min(ArrowSize,m_MaxY-m_MinY);
ArrowSize=min(ArrowSize,m_MaxZ-m_MinZ);
if(m_DrawAxes){
glBegin(GL_LINES);
glVertex3d((m_MaxX+m_MinX)/2,(m_MaxY+m_MinY)/2,(m_MaxZ+m_MinZ)/2);
glVertex3d((m_MaxX+m_MinX)/2+ArrowSize/4,(m_MaxY+m_MinY)/2,(m_MaxZ+m_MinZ)/2);
glVertex3d((m_MaxX+m_MinX)/2,(m_MaxY+m_MinY)/2,(m_MaxZ+m_MinZ)/2);
glVertex3d((m_MaxX+m_MinX)/2,(m_MaxY+m_MinY)/2+ArrowSize/4,(m_MaxZ+m_MinZ)/2);
glVertex3d((m_MaxX+m_MinX)/2,(m_MaxY+m_MinY)/2,(m_MaxZ+m_MinZ)/2);
glVertex3d((m_MaxX+m_MinX)/2,(m_MaxY+m_MinY)/2,(m_MaxZ+m_MinZ)/2+ArrowSize/4);
glEnd();
}
// points
if (m_DrawPoints){
pDoc->m_PtLst.Draw();
}
// Neurons
if (m_DrawNeurons){
pDoc->m_NNet.Draw();
}
// Edges
if (m_DrawEdges){
pDoc->m_NNet.Edges.Draw();
}
glEnable(GL_LIGHTING);
//faces
if (m_DrawFaces){
pDoc->m_NNet.Faces.Draw();
}
glDisable(GL_LIGHTING);
#ifdef MY_DEBUG
MyGLErrorMessage("drawing scene");
#endif
glPopMatrix();
// glPopName();
glDisable (GL_BLEND);
glDisable (GL_LIGHT1);
glDisable (GL_DEPTH_TEST);
glDisable (GL_NORMALIZE);
//glDisable (GL_COLOR_MATERIAL);
#ifdef MY_DEBUG
TRACE ("view : finished Drawing picture\n");
#endif
}
void CNNView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
CNNDoc *pDoc;
pDoc=GetDocument();
//
// Build a display lists
//
if (lHint==1){ // this occours when we first set the bounding box of the point list
RECT MyRect;
GetClientRect( &MyRect ); //get the area of the current window
m_MinX=pDoc->m_PtLst.MinVals.Pos[0];
m_MinY=pDoc->m_PtLst.MinVals.Pos[1];
m_MinZ=pDoc->m_PtLst.MinVals.Pos[2];
m_MaxX=pDoc->m_PtLst.MaxVals.Pos[0];
m_MaxY=pDoc->m_PtLst.MaxVals.Pos[1];
m_MaxZ=pDoc->m_PtLst.MaxVals.Pos[2];
double ArrowSize;
ArrowSize=m_MaxX-m_MinX;
ArrowSize=max(ArrowSize,m_MaxY-m_MinY);
ArrowSize=max(ArrowSize,m_MaxZ-m_MinZ);
ArrowSize /= 4;
m_PointSize=(double)ArrowSize/100;
m_NeuronSize=(double)ArrowSize/50;
m_NormalSize=(double)ArrowSize/5;
CClientDC dc(this) ;
BOOL bResult = wglMakeCurrent(dc.m_hDC, m_hrc);
#ifdef MY_DEBUG
if (!bResult)
{
TRACE("wglMakeCurrent Failed %x\r\n", GetLastError() ) ;
}
#endif
glMatrixMode(GL_PROJECTION);
MyGLErrorMessage("reshape problem7");
glLoadIdentity();
MyGLErrorMessage("reshape problem6");
ReshapeFunc(MyRect.right , MyRect.bottom);
// also, we can now initialize the lists...
// release the dc
wglMakeCurrent(NULL, NULL) ;
}
//
// Attach the window dc to OpenGL.
//
CClientDC dc(this) ;
BOOL bResult = wglMakeCurrent(dc.m_hDC, m_hrc);
#ifdef MY_DEBUG
if (!bResult)
{
TRACE("wglMakeCurrent Failed %x\r\n", GetLastError() ) ;
}
#endif
pDoc->m_UpdatingListsNow.Lock(); //*** locking
if (lHint==1){ // this occours when we first set the bounding box of the point list
pDoc->m_PtLst.InitDispList();
pDoc->m_NNet.InitDispList();
pDoc->m_NNet.Edges.InitDispList();
pDoc->m_NNet.Faces.InitDispList();
}
#ifdef MY_DEBUG
TRACE("view - locking in update view\n");
#endif
if(pDoc->m_PtLst.RecalcForDisplay)
pDoc->m_PtLst.DrawList(m_PointSize,pDoc->m_NGChunkSize,pDoc->m_CurrentIteration);
pDoc->m_NNet.DrawList(m_NeuronSize,m_NormalSize);
pDoc->m_NNet.Edges.DrawList(0);
pDoc->m_NNet.Faces.DrawList();
glFinish(); //wait untill all gl commands have been processed.
pDoc->m_UpdatingListsNow.Unlock(); // *** unlocking list
#ifdef MY_DEBUG
TRACE("view - unlocking in update view\n");
#endif
// release the dc
wglMakeCurrent(NULL, NULL) ;
Invalidate(FALSE) ;
#ifdef MY_DEBUG
TRACE ("View - finshed updating the window\n");
#endif
UpdateWindow() ;
}
void CNNView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
m_MouseMoveStart=point;
CView::OnLButtonDown(nFlags, point);
}
void CNNView::OnLButtonUp(UINT nFlags, CPoint point)
{
if (nFlags && MK_SHIFT) { //picking
#define BUFSIZE 512
CClientDC dc(this) ;
BOOL bResult = wglMakeCurrent(dc.m_hDC, m_hrc);
#ifdef MY_DEBUG
if (!bResult)
{
TRACE("wglMakeCurrent Failed %x\r\n", GetLastError() ) ;
}
#endif
GLuint SelectBuf[BUFSIZE];
GLint Hits;
glSelectBuffer (BUFSIZE, SelectBuf);
glRenderMode (GL_SELECT);
GLint ViewPort[4];
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glGetIntegerv (GL_VIEWPORT, ViewPort);
gluPickMatrix(point.x, ViewPort[3] - point.y , 1.0 , 1.0 , ViewPort);
ReshapeFunc(ViewPort[2],ViewPort[3]);
CNNDoc* pDoc = GetDocument();
DrawScene(pDoc);
Hits = glRenderMode (GL_RENDER);
// release the dc
glMatrixMode(GL_PROJECTION);
glPopMatrix();
wglMakeCurrent(NULL, NULL) ;
GLint i;
GLuint names, ptr, j=0;
#ifdef MY_DEBUG
TRACE ("hits = %d\n", Hits);
#endif
ptr = 0;
for ( i = 0; i < Hits; i++) { /* for each hit */
names = SelectBuf[ptr];
TRACE (" number of names for hit %d = %d\n",i+1,names);
ptr+=3;
TRACE (" names are: ");
for (j = 0; j < names; j++){ /* for each name */
TRACE ("%X ", SelectBuf[ptr]);
ptr++;
}
TRACE ("\n");
}
}
else{
m_RotX = point.x-m_MouseMoveStart.x;
m_RotY = point.y-m_MouseMoveStart.y;
m_RotAngle = sqrt(m_RotX*m_RotX+m_RotY*m_RotY) / m_MouseRotSensativity;
Invalidate(FALSE) ; // maybe true???
UpdateWindow() ;
}
//GetDocument()->UpdateAllViews(NULL);
CView::OnLButtonUp(nFlags, point);
}
void CNNView::OnButtonViewParam()
{
// TODO: Add your command handler code here
CViewParamDlg ViewDlg;
ViewDlg.m_NeuronSize=m_NeuronSize;
ViewDlg.m_NormalSize=m_NormalSize;
ViewDlg.m_PointSize=m_PointSize;
ViewDlg.m_DrawAxes=m_DrawAxes;
ViewDlg.m_DrawPoints=m_DrawPoints;
ViewDlg.m_DrawNeurons=m_DrawNeurons;
ViewDlg.m_DrawEdges=m_DrawEdges;
ViewDlg.m_DrawFaces=m_DrawFaces;
ViewDlg.m_LightingTwoSides=m_LightingTwoSides;
if (ViewDlg.DoModal()==IDOK){
m_NeuronSize=ViewDlg.m_NeuronSize;
m_NormalSize=ViewDlg.m_NormalSize;
if (m_PointSize!=ViewDlg.m_PointSize){
// update point list parameters and force update of display
m_PointSize=ViewDlg.m_PointSize;
CNNDoc *pDoc=GetDocument();
pDoc->m_PtLst.RecalcForDisplay=true;
}
m_DrawAxes=ViewDlg.m_DrawAxes;
m_DrawPoints=ViewDlg.m_DrawPoints;
m_DrawNeurons=ViewDlg.m_DrawNeurons;
m_DrawEdges=ViewDlg.m_DrawEdges;
m_DrawFaces=ViewDlg.m_DrawFaces;
m_LightingTwoSides=ViewDlg.m_LightingTwoSides;
}
GetDocument()->UpdateAllViews(NULL);
}
void CNNView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MouseMoveStart=point;
CView::OnRButtonDown(nFlags, point);
}
void CNNView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (nFlags && MK_SHIFT) {
double Scx=point.x-m_MouseMoveStart.x;
double Scy=point.y-m_MouseMoveStart.y;
if (Scy < 0.0)
m_Zoom = 1.0 / (1.0 + sqrt(Scx*Scx+Scy*Scy) * (m_MouseZoomSensativity));
else
m_Zoom = 1.0 + sqrt(Scx*Scx+Scy*Scy) * (m_MouseZoomSensativity);
// this happens when mouse has not been moved
//if (m_Zoom==0.0) m_Zoom=1.0;
}
else{
m_TransX = (point.x-m_MouseMoveStart.x) * m_MouseTransSensativity *(m_MaxX-m_MinX);
m_TransY = (point.y-m_MouseMoveStart.y) * m_MouseTransSensativity *(m_MaxY-m_MinY);
}
Invalidate(FALSE) ; // maybe true???
UpdateWindow() ;
//GetDocument()->UpdateAllViews(NULL);
CView::OnRButtonUp(nFlags, point);
}
GLdouble *CNNView::GenRotMatrix()
{
// JAC insert - use opengl's commands to create a new modeling matrix
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(m_TransX,-m_TransY,0.0);
if (m_RotAngle!=0.0) glRotated(m_RotAngle,m_RotY,m_RotX,0.0);
glScaled(m_Zoom,m_Zoom,m_Zoom);
glMultMatrixd(m_ViewMat);
glGetDoublev(GL_MODELVIEW_MATRIX,m_ViewMat);
glPopMatrix();
m_RotAngle=0.0;
m_Zoom=1.0;
m_TransX=0.0;
m_TransY=0.0;
MyGLErrorMessage("roatation");
return m_ViewMat;
}
void CNNView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// retinitialize
m_RotAngle=0.0;
m_TransX=0.0;
m_TransY=0.0;
m_Zoom=1.0;
// init rotation matrix
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
m_ViewMat[i*4+j]= (i==j)? 1.0:0.0;
Invalidate(FALSE) ; // maybe true???
UpdateWindow() ;
CView::OnRButtonDblClk(nFlags, point);
}