This repository was archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRotate.frm
More file actions
433 lines (396 loc) · 11.7 KB
/
Rotate.frm
File metadata and controls
433 lines (396 loc) · 11.7 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
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
VERSION 5.00
Begin VB.Form frmRotate
Appearance = 0 'Flat
BackColor = &H00C0C0C0&
Caption = "Rotate"
ClientHeight = 5415
ClientLeft = 300
ClientTop = 735
ClientWidth = 9015
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
KeyPreview = -1 'True
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 5415
ScaleWidth = 9015
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 7
Left = 6840
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 7
Top = 2760
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 6
Left = 4560
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 6
Top = 2760
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 5
Left = 2280
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 5
Top = 2760
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 4
Left = 0
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 4
Top = 2760
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 3
Left = 6840
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 3
Top = 0
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 2
Left = 4560
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 2
Top = 0
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 1
Left = 2280
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 1
Top = 0
Width = 2175
End
Begin VB.PictureBox Pict
AutoRedraw = -1 'True
Height = 2175
Index = 0
Left = 0
ScaleHeight = -8
ScaleLeft = -4
ScaleMode = 0 'User
ScaleTop = 4
ScaleWidth = 8
TabIndex = 0
Top = 0
Width = 2175
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Reverse translation"
Height = 255
Index = 7
Left = 6840
TabIndex = 15
Top = 5040
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Reverse 1st rotation"
Height = 255
Index = 6
Left = 4560
TabIndex = 14
Top = 5040
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Reverse 2nd rotation"
Height = 255
Index = 5
Left = 2280
TabIndex = 13
Top = 5040
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Rotate around line"
Height = 255
Index = 4
Left = 0
TabIndex = 12
Top = 5040
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Rotate into Y axis"
Height = 255
Index = 3
Left = 6840
TabIndex = 11
Top = 2280
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Rotate into Y-Z plane"
Height = 255
Index = 2
Left = 4560
TabIndex = 10
Top = 2280
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Translate to origin"
Height = 255
Index = 1
Left = 2280
TabIndex = 9
Top = 2280
Width = 2175
WordWrap = -1 'True
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Original picture"
Height = 255
Index = 0
Left = 0
TabIndex = 8
Top = 2280
Width = 2175
WordWrap = -1 'True
End
End
Attribute VB_Name = "frmRotate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' The line around which to rotate.
Private Const Px = 0
Private Const Py = 3
Private Const Pz = 0
Private Const Vx = 1
Private Const Vy = 1
Private Const Vz = 1
' Location of viewing eye.
Private EyeR As Single
Private EyeTheta As Single
Private EyePhi As Single
' Location of focus point.
Private Const FocusX = 0#
Private Const FocusY = 0#
Private Const FocusZ = 0#
Private Projector(1 To 4, 1 To 4) As Single
' Matrices used for the rotation.
Private trans(1 To 4, 1 To 4) As Single
Private Rot1(1 To 4, 1 To 4) As Single
Private Rot2(1 To 4, 1 To 4) As Single
Private Rot3(1 To 4, 1 To 4) As Single
Private Rot2_Inv(1 To 4, 1 To 4) As Single
Private Rot1_Inv(1 To 4, 1 To 4) As Single
Private Trans_Inv(1 To 4, 1 To 4) As Single
Private M(0 To 7) As Transformation
' Create the matrices used when rotating through
' angle theta around a line passing through
' (p1, p2, p3) in direction <d1, d2, d3>. Theta
' is measured counterclockwise as you look down
' the line opposite the line's direction.
Private Sub CreateMatrices(ByVal p1 As Single, ByVal p2 As Single, ByVal p3 As Single, ByVal d1 As Single, ByVal d2 As Single, ByVal d3 As Single, ByVal theta As Single)
Dim D As Single
Dim L As Single
' Translate the line to the origin.
m3Translate trans, -p1, -p2, -p3
m3Translate Trans_Inv, p1, p2, p3
' Rotate around Z-axis until the line is in
' the Y-Z plane.
m3Identity Rot1
D = Sqr(d1 * d1 + d2 * d2)
Rot1(1, 1) = d2 / D
Rot1(1, 2) = d1 / D
Rot1(2, 1) = -Rot1(1, 2)
Rot1(2, 2) = Rot1(1, 1)
m3Identity Rot1_Inv
Rot1_Inv(1, 1) = Rot1(1, 1)
Rot1_Inv(1, 2) = -Rot1(1, 2)
Rot1_Inv(2, 1) = -Rot1(2, 1)
Rot1_Inv(2, 2) = Rot1(2, 2)
' Rotate around the X-axis until the line
' lies along the Y axis.
m3Identity Rot2
L = Sqr(d1 * d1 + d2 * d2 + d3 * d3)
Rot2(2, 2) = D / L
Rot2(2, 3) = -d3 / L
Rot2(3, 2) = -Rot2(2, 3)
Rot2(3, 3) = Rot2(2, 2)
m3Identity Rot2_Inv
Rot2_Inv(2, 2) = Rot2(2, 2)
Rot2_Inv(2, 3) = -Rot2(2, 3)
Rot2_Inv(3, 2) = -Rot2(3, 2)
Rot2_Inv(3, 3) = Rot2(3, 3)
' Rotate around the Y axis.
m3YRotate Rot3, theta
' Put the matrices in the M array.
m3Identity M(0).M
m3MatCopy M(1).M, trans
m3MatCopy M(2).M, Rot1
m3MatCopy M(3).M, Rot2
m3MatCopy M(4).M, Rot3
m3MatCopy M(5).M, Rot2_Inv
m3MatCopy M(6).M, Rot1_Inv
m3MatCopy M(7).M, Trans_Inv
End Sub
' Let the user change the location of the eye.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Const Dtheta = PI / 20
Select Case KeyCode
Case vbKeyLeft
EyeTheta = EyeTheta - Dtheta
Case vbKeyRight
EyeTheta = EyeTheta + Dtheta
Case vbKeyUp
EyePhi = EyePhi - Dtheta
Case vbKeyDown
EyePhi = EyePhi + Dtheta
Case Else
Exit Sub
End Select
' Redraw the pictures.
DrawTheData
End Sub
' Rotate the points in the cube and draw the cube.
Private Sub DrawData(ByVal pic As Object)
Dim i As Integer
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single
Dim oldwidth As Integer
' Compute the projection matrix.
m3PProject Projector, m3Parallel, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
' Transform the points.
TransformAllData Projector
' Draw the points.
pic.Cls
oldwidth = pic.DrawWidth
For i = 1 To NumSegments
x1 = Segments(i).fr_tr(1)
y1 = Segments(i).fr_tr(2)
x2 = Segments(i).to_tr(1)
y2 = Segments(i).to_tr(2)
' Draw the plane's normal in bold.
If i = 4 Then pic.DrawWidth = 3
pic.Line (x1, y1)-(x2, y2)
If i = 4 Then pic.DrawWidth = oldwidth
Next i
pic.Refresh
End Sub
Private Sub Form_Load()
' Initialize the eye position.
EyeR = 3
EyeTheta = PI * 0.4
EyePhi = PI * 0.1
' Create the rotation matrices.
CreateMatrices Px, Py, Pz, Vx, Vy, Vz, PI * 0.1
' Create, project, and draw the data.
DrawTheData
End Sub
' Draw all the pictures.
Private Sub DrawTheData()
Dim i As Integer
' Start with fresh data.
CreateData
For i = 0 To 7
' Apply the next transformation.
TransformData M(i).M, 4, NumSegments
SetPoints 4, NumSegments
' Display the data.
DrawData Pict(i)
Next i
End Sub
Private Sub CreateData()
' Start with no data.
NumSegments = 0
' Create the axes.
MakeSegment 0, 0, 0, 5, 0, 0 ' X axis.
MakeSegment 0, 0, 0, 0, 5, 0 ' Y axis.
MakeSegment 0, 0, 0, 0, 0, 5 ' Z axis.
' Create the line's direction vector.
MakeSegment Px, Py, Pz, Px + Vx, Py + Vy, Pz + Vz
' Create the object to reflect.
MakeSegment 1, 1, 1, 1, 1, 3
MakeSegment 1, 1, 3, 3, 1, 3
MakeSegment 3, 1, 3, 3, 1, 1
MakeSegment 3, 1, 1, 1, 1, 1
MakeSegment 1, 3, 1, 1, 3, 3
MakeSegment 1, 3, 3, 3, 3, 3
MakeSegment 3, 3, 3, 3, 3, 1
MakeSegment 3, 3, 1, 1, 3, 1
MakeSegment 1, 1, 1, 1, 3, 1
MakeSegment 1, 1, 3, 1, 3, 3
MakeSegment 3, 1, 3, 3, 3, 3
MakeSegment 3, 1, 1, 3, 3, 1
End Sub