-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
707 lines (644 loc) · 25.3 KB
/
Form1.cs
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
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
using System.Threading;
namespace asgn5v1
{
/// <summary>
/// Summary description for Transformer.
/// </summary>
public class Transformer : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
//private bool GetNewData();
// basic data for Transformer
int numpts = 0;
int numlines = 0;
bool gooddata = false;
bool cont = false;
double x, y, z;
double[,] vertices;
double[,] scrnpts;
double[,] ctrans = new double[4, 4]; //your main transformation matrix
private System.Windows.Forms.ImageList tbimages;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton transleftbtn;
private System.Windows.Forms.ToolBarButton transrightbtn;
private System.Windows.Forms.ToolBarButton transupbtn;
private System.Windows.Forms.ToolBarButton transdownbtn;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton scaleupbtn;
private System.Windows.Forms.ToolBarButton scaledownbtn;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton rotxby1btn;
private System.Windows.Forms.ToolBarButton rotyby1btn;
private System.Windows.Forms.ToolBarButton rotzby1btn;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton rotxbtn;
private System.Windows.Forms.ToolBarButton rotybtn;
private System.Windows.Forms.ToolBarButton rotzbtn;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton shearrightbtn;
private System.Windows.Forms.ToolBarButton shearleftbtn;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton resetbtn;
private System.Windows.Forms.ToolBarButton exitbtn;
int[,] lines;
public Transformer()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
Text = "COMP 4560: Assignment 5 (201230) (Jeffrey Woo)";
ResizeRedraw = true;
BackColor = Color.Black;
MenuItem miNewDat = new MenuItem("New &Data...",
new EventHandler(MenuNewDataOnClick));
MenuItem miExit = new MenuItem("E&xit",
new EventHandler(MenuFileExitOnClick));
MenuItem miDash = new MenuItem("-");
MenuItem miFile = new MenuItem("&File",
new MenuItem[] { miNewDat, miDash, miExit });
MenuItem miAbout = new MenuItem("&About",
new EventHandler(MenuAboutOnClick));
Menu = new MainMenu(new MenuItem[] { miFile, miAbout });
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Transformer));
this.tbimages = new System.Windows.Forms.ImageList(this.components);
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.transleftbtn = new System.Windows.Forms.ToolBarButton();
this.transrightbtn = new System.Windows.Forms.ToolBarButton();
this.transupbtn = new System.Windows.Forms.ToolBarButton();
this.transdownbtn = new System.Windows.Forms.ToolBarButton();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.scaleupbtn = new System.Windows.Forms.ToolBarButton();
this.scaledownbtn = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.rotxby1btn = new System.Windows.Forms.ToolBarButton();
this.rotyby1btn = new System.Windows.Forms.ToolBarButton();
this.rotzby1btn = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.rotxbtn = new System.Windows.Forms.ToolBarButton();
this.rotybtn = new System.Windows.Forms.ToolBarButton();
this.rotzbtn = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.shearrightbtn = new System.Windows.Forms.ToolBarButton();
this.shearleftbtn = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.resetbtn = new System.Windows.Forms.ToolBarButton();
this.exitbtn = new System.Windows.Forms.ToolBarButton();
this.SuspendLayout();
//
// tbimages
//
this.tbimages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("tbimages.ImageStream")));
this.tbimages.TransparentColor = System.Drawing.Color.Transparent;
this.tbimages.Images.SetKeyName(0, "");
this.tbimages.Images.SetKeyName(1, "");
this.tbimages.Images.SetKeyName(2, "");
this.tbimages.Images.SetKeyName(3, "");
this.tbimages.Images.SetKeyName(4, "");
this.tbimages.Images.SetKeyName(5, "");
this.tbimages.Images.SetKeyName(6, "");
this.tbimages.Images.SetKeyName(7, "");
this.tbimages.Images.SetKeyName(8, "");
this.tbimages.Images.SetKeyName(9, "");
this.tbimages.Images.SetKeyName(10, "");
this.tbimages.Images.SetKeyName(11, "");
this.tbimages.Images.SetKeyName(12, "");
this.tbimages.Images.SetKeyName(13, "");
this.tbimages.Images.SetKeyName(14, "");
this.tbimages.Images.SetKeyName(15, "");
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.transleftbtn,
this.transrightbtn,
this.transupbtn,
this.transdownbtn,
this.toolBarButton1,
this.scaleupbtn,
this.scaledownbtn,
this.toolBarButton2,
this.rotxby1btn,
this.rotyby1btn,
this.rotzby1btn,
this.toolBarButton3,
this.rotxbtn,
this.rotybtn,
this.rotzbtn,
this.toolBarButton4,
this.shearrightbtn,
this.shearleftbtn,
this.toolBarButton5,
this.resetbtn,
this.exitbtn});
this.toolBar1.Dock = System.Windows.Forms.DockStyle.Right;
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.tbimages;
this.toolBar1.Location = new System.Drawing.Point(484, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(24, 306);
this.toolBar1.TabIndex = 0;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// transleftbtn
//
this.transleftbtn.ImageIndex = 1;
this.transleftbtn.Name = "transleftbtn";
this.transleftbtn.ToolTipText = "translate left";
//
// transrightbtn
//
this.transrightbtn.ImageIndex = 0;
this.transrightbtn.Name = "transrightbtn";
this.transrightbtn.ToolTipText = "translate right";
//
// transupbtn
//
this.transupbtn.ImageIndex = 2;
this.transupbtn.Name = "transupbtn";
this.transupbtn.ToolTipText = "translate up";
//
// transdownbtn
//
this.transdownbtn.ImageIndex = 3;
this.transdownbtn.Name = "transdownbtn";
this.transdownbtn.ToolTipText = "translate down";
//
// toolBarButton1
//
this.toolBarButton1.Name = "toolBarButton1";
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// scaleupbtn
//
this.scaleupbtn.ImageIndex = 4;
this.scaleupbtn.Name = "scaleupbtn";
this.scaleupbtn.ToolTipText = "scale up";
//
// scaledownbtn
//
this.scaledownbtn.ImageIndex = 5;
this.scaledownbtn.Name = "scaledownbtn";
this.scaledownbtn.ToolTipText = "scale down";
//
// toolBarButton2
//
this.toolBarButton2.Name = "toolBarButton2";
this.toolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// rotxby1btn
//
this.rotxby1btn.ImageIndex = 6;
this.rotxby1btn.Name = "rotxby1btn";
this.rotxby1btn.ToolTipText = "rotate about x by 1";
//
// rotyby1btn
//
this.rotyby1btn.ImageIndex = 7;
this.rotyby1btn.Name = "rotyby1btn";
this.rotyby1btn.ToolTipText = "rotate about y by 1";
//
// rotzby1btn
//
this.rotzby1btn.ImageIndex = 8;
this.rotzby1btn.Name = "rotzby1btn";
this.rotzby1btn.ToolTipText = "rotate about z by 1";
//
// toolBarButton3
//
this.toolBarButton3.Name = "toolBarButton3";
this.toolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// rotxbtn
//
this.rotxbtn.ImageIndex = 9;
this.rotxbtn.Name = "rotxbtn";
this.rotxbtn.ToolTipText = "rotate about x continuously";
//
// rotybtn
//
this.rotybtn.ImageIndex = 10;
this.rotybtn.Name = "rotybtn";
this.rotybtn.ToolTipText = "rotate about y continuously";
//
// rotzbtn
//
this.rotzbtn.ImageIndex = 11;
this.rotzbtn.Name = "rotzbtn";
this.rotzbtn.ToolTipText = "rotate about z continuously";
//
// toolBarButton4
//
this.toolBarButton4.Name = "toolBarButton4";
this.toolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// shearrightbtn
//
this.shearrightbtn.ImageIndex = 12;
this.shearrightbtn.Name = "shearrightbtn";
this.shearrightbtn.ToolTipText = "shear right";
//
// shearleftbtn
//
this.shearleftbtn.ImageIndex = 13;
this.shearleftbtn.Name = "shearleftbtn";
this.shearleftbtn.ToolTipText = "shear left";
//
// toolBarButton5
//
this.toolBarButton5.Name = "toolBarButton5";
this.toolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// resetbtn
//
this.resetbtn.ImageIndex = 14;
this.resetbtn.Name = "resetbtn";
this.resetbtn.ToolTipText = "restore the initial image";
//
// exitbtn
//
this.exitbtn.ImageIndex = 15;
this.exitbtn.Name = "exitbtn";
this.exitbtn.ToolTipText = "exit the program";
//
// Transformer
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(508, 306);
this.Controls.Add(this.toolBar1);
this.Name = "Transformer";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Transformer_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Transformer());
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
Pen pen = new Pen(Color.White, 3);
double temp;
int k;
if (gooddata)
{
//create the screen coordinates:
// scrnpts = vertices*ctrans
for (int i = 0; i < numpts; i++)
{
for (int j = 0; j < 4; j++)
{
temp = 0.0d;
for (k = 0; k < 4; k++)
temp += vertices[i, k] * ctrans[k, j];
scrnpts[i, j] = temp;
}
}
//now draw the lines
for (int i = 0; i < numlines; i++)
{
grfx.DrawLine(pen, (int)scrnpts[lines[i, 0], 0], (int)scrnpts[lines[i, 0], 1],
(int)scrnpts[lines[i, 1], 0], (int)scrnpts[lines[i, 1], 1]);
}
} // end of gooddata block
} // end of OnPaint
void MenuNewDataOnClick(object obj, EventArgs ea)
{
//MessageBox.Show("New Data item clicked.");
gooddata = GetNewData();
RestoreInitialImage();
}
void MenuFileExitOnClick(object obj, EventArgs ea)
{
Close();
}
void MenuAboutOnClick(object obj, EventArgs ea)
{
AboutDialogBox dlg = new AboutDialogBox();
dlg.ShowDialog();
}
void RestoreInitialImage()
{
Invalidate();
} // end of RestoreInitialImage
bool GetNewData()
{
string strinputfile, text;
ArrayList coorddata = new ArrayList();
ArrayList linesdata = new ArrayList();
OpenFileDialog opendlg = new OpenFileDialog();
opendlg.Title = "Choose File with Coordinates of Vertices";
if (opendlg.ShowDialog() == DialogResult.OK)
{
strinputfile = opendlg.FileName;
FileInfo coordfile = new FileInfo(strinputfile);
StreamReader reader = coordfile.OpenText();
do
{
text = reader.ReadLine();
if (text != null) coorddata.Add(text);
} while (text != null);
reader.Close();
DecodeCoords(coorddata);
}
else
{
MessageBox.Show("***Failed to Open Coordinates File***");
return false;
}
opendlg.Title = "Choose File with Data Specifying Lines";
if (opendlg.ShowDialog() == DialogResult.OK)
{
strinputfile = opendlg.FileName;
FileInfo linesfile = new FileInfo(strinputfile);
StreamReader reader = linesfile.OpenText();
do
{
text = reader.ReadLine();
if (text != null) linesdata.Add(text);
} while (text != null);
reader.Close();
DecodeLines(linesdata);
}
else
{
MessageBox.Show("***Failed to Open Line Data File***");
return false;
}
scrnpts = new double[numpts, 4];
setIdentity(ctrans, 4, 4); //initialize transformation matrix to identity
double[,] origin = new double[,] { { 10, 0, 0, 0 }, { 0, -10, 0, 0 }, { 0, 0, 10, 0 }, { -100 + ClientSize.Width / 2, -100 + ClientSize.Height / 2, 0, 1 } };
transform(origin);
return true;
} // end of GetNewData
void DecodeCoords(ArrayList coorddata)
{
//this may allocate slightly more rows that necessary
vertices = new double[coorddata.Count, 4];
numpts = 0;
string[] text = null;
for (int i = 0; i < coorddata.Count; i++)
{
text = coorddata[i].ToString().Split(' ', ',');
vertices[numpts, 0] = double.Parse(text[0]);
if (vertices[numpts, 0] < 0.0d) break;
vertices[numpts, 1] = double.Parse(text[1]);
vertices[numpts, 2] = double.Parse(text[2]);
vertices[numpts, 3] = 1.0d;
numpts++;
}
}// end of DecodeCoords
void DecodeLines(ArrayList linesdata)
{
//this may allocate slightly more rows that necessary
lines = new int[linesdata.Count, 2];
numlines = 0;
string[] text = null;
for (int i = 0; i < linesdata.Count; i++)
{
text = linesdata[i].ToString().Split(' ', ',');
lines[numlines, 0] = int.Parse(text[0]);
if (lines[numlines, 0] < 0) break;
lines[numlines, 1] = int.Parse(text[1]);
numlines++;
}
} // end of DecodeLines
void setIdentity(double[,] A, int nrow, int ncol)
{
for (int i = 0; i < nrow; i++)
{
for (int j = 0; j < ncol; j++) A[i, j] = 0.0d;
A[i, i] = 1.0d;
}
}// end of setIdentity
private void Transformer_Load(object sender, System.EventArgs e)
{
//ctrans = new double[,] {{1,0,0,0},{0,-1,0,0},{0,0,1,0},{ClientSize.Width/2, ClientSize.Height/2,0,1}};
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
cont = false;
if (e.Button == transleftbtn)
{
double[,] left = new double[,] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { -50, 0, 0, 1 } };
transform(left);
Refresh();
}
if (e.Button == transrightbtn)
{
double[,] right = new double[,] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 50, 0, 0, 1 } };
transform(right);
Refresh();
}
if (e.Button == transupbtn)
{
double[,] up = new double[,] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, -25, 0, 1 } };
transform(up);
Refresh();
}
if (e.Button == transdownbtn)
{
double[,] down = new double[,] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 25, 0, 1 } };
transform(down);
Refresh();
}
if (e.Button == scaleupbtn)
{
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] { { 1.1, 0, 0, 0 }, { 0, 1.1, 0, 0 }, { 0, 0, 1.1, 0 }, { -.1 * x, -.1 * y, -.1 * z, 1 } };
transform(scaleup);
Refresh();
}
if (e.Button == scaledownbtn)
{
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] { { .9, 0, 0, 0 }, { 0, .9, 0, 0 }, { 0, 0, .9, 0 }, { .1 * x, .1 * y, .1 * z, 1 } };
transform(scaleup);
Refresh();
}
if (e.Button == rotxby1btn)
{
double cos = Math.Cos(0.05);
double sin = Math.Sin(0.05);
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] { { 1, 0, 0, 0 },
{ 0, cos, sin, 0 },
{ 0, -sin, cos, 0 },
{ 0, ((-y * cos) + (z * sin)) + y, ((-y * sin) + (-z * cos)) + z, 1 } };
transform(scaleup);
Refresh();
}
if (e.Button == rotyby1btn)
{
double cos = Math.Cos(0.05);
double sin = Math.Sin(0.05);
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] { { cos, 0, -sin, 0 },
{ 0, 1, 0, 0 },
{ sin, 0, cos, 0 },
{ -x * cos + -z * sin + x, 0, ((x * sin) + (-z * cos)) + z, 1 } };
transform(scaleup);
Refresh();
}
if (e.Button == rotzby1btn)
{
double cos = Math.Cos(0.05);
double sin = Math.Sin(0.05);
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] {
{ cos, sin, 0, 0 },
{ -sin, cos, 0, 0 },
{ 0, 0, 1, 0 },
{ -x * cos + y * sin + x, -x * sin - y* cos +y, 0, 1 } };
transform(scaleup);
Refresh();
}
if (e.Button == rotxbtn)
{
cont = true;
while (cont)
{
double cos = Math.Cos(0.05);
double sin = Math.Sin(0.05);
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] { { 1, 0, 0, 0 },
{ 0, cos, sin, 0 },
{ 0, -sin, cos, 0 },
{ 0, ((-y * cos) + (z * sin)) + y, ((-y * sin) + (-z * cos)) + z, 1 } };
transform(scaleup);
cont = true;
Invalidate();
}
}
if (e.Button == rotybtn)
{
cont = true;
while (cont)
{
double cos = Math.Cos(0.05);
double sin = Math.Sin(0.05);
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] { { cos, 0, -sin, 0 },
{ 0, 1, 0, 0 },
{ sin, 0, cos, 0 },
{ -x * cos + -z * sin + x, 0, ((x * sin) + (-z * cos)) + z, 1 } };
transform(scaleup);
cont = true;
Refresh();
}
}
if (e.Button == rotzbtn)
{
cont = true;
while (cont)
{
double cos = Math.Cos(0.05);
double sin = Math.Sin(0.05);
x = scrnpts[0, 0];
y = scrnpts[0, 1];
z = scrnpts[0, 2];
double[,] scaleup = new double[,] {
{ cos, sin, 0, 0 },
{ -sin, cos, 0, 0 },
{ 0, 0, 1, 0 },
{ -x * cos + y * sin + x, -x * sin - y* cos +y, 0, 1 } };
transform(scaleup);
cont = true;
Refresh();
}
}
if (e.Button == shearleftbtn)
{
Refresh();
}
if (e.Button == shearrightbtn)
{
Refresh();
}
if (e.Button == resetbtn)
{
RestoreInitialImage();
}
if (e.Button == exitbtn)
{
Close();
}
}
private void transform(double[,] matrixTrans)
{
double temp;
double[,] temp2 = new double[4, 4];
cont = false;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
temp = 0.0d;
for (int k = 0; k < 4; k++)
temp += ctrans[i, k] * matrixTrans[k, j];
temp2[i, j] = temp;
}
}
ctrans = temp2;
}
}
}