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 pathTrans.cls
More file actions
203 lines (173 loc) · 5.46 KB
/
Trans.cls
File metadata and controls
203 lines (173 loc) · 5.46 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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Transformed3d"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private NumCurvePts As Integer
Private CurvePoints() As Point3D
Private NumTrans As Integer
Private trans() As Transformation
Private solid As Solid3d ' The display solid.
Public Property Get HideSurfaces() As Boolean
If Not (solid Is Nothing) Then HideSurfaces = solid.HideSurfaces
End Property
Public Property Let HideSurfaces(ByVal new_value As Boolean)
If Not (solid Is Nothing) Then solid.HideSurfaces = new_value
End Property
' Create the display solid by applying the
' series of transformations in array M().
Public Sub Transform(Optional cap_ends As Variant)
Dim face As Face3d
Dim i As Integer
Dim j As Integer
Dim x0 As Single
Dim y0 As Single
Dim z0 As Single
Dim x1 As Single
Dim y1 As Single
Dim z1 As Single
Dim x2 As Single
Dim y2 As Single
Dim z2 As Single
Dim x3 As Single
Dim y3 As Single
Dim z3 As Single
If IsMissing(cap_ends) Then cap_ends = True
Set solid = New Solid3d
' Add the base curve to solid assuming the
' curve is stored oriented towards the
' transformations.
If cap_ends Then
Set face = New Face3d
solid.Faces.Add face
For i = NumCurvePts - 1 To 1 Step -1
face.AddPoints _
CurvePoints(i).coord(1), _
CurvePoints(i).coord(2), _
CurvePoints(i).coord(3)
Next i
End If
' Start with the transformed coordinates
' the same as the original coordinates.
For i = 1 To NumCurvePts
CurvePoints(i).trans(1) = CurvePoints(i).coord(1)
CurvePoints(i).trans(2) = CurvePoints(i).coord(2)
CurvePoints(i).trans(3) = CurvePoints(i).coord(3)
Next i
' Create the transformed copies of the curve.
For i = 1 To NumTrans
x0 = CurvePoints(1).trans(1)
y0 = CurvePoints(1).trans(2)
z0 = CurvePoints(1).trans(3)
m3ApplyFull _
CurvePoints(1).coord, trans(i).M, _
CurvePoints(1).trans
x1 = CurvePoints(1).trans(1)
y1 = CurvePoints(1).trans(2)
z1 = CurvePoints(1).trans(3)
For j = 2 To NumCurvePts
x2 = CurvePoints(j).trans(1)
y2 = CurvePoints(j).trans(2)
z2 = CurvePoints(j).trans(3)
m3ApplyFull _
CurvePoints(j).coord, trans(i).M, _
CurvePoints(j).trans
x3 = CurvePoints(j).trans(1)
y3 = CurvePoints(j).trans(2)
z3 = CurvePoints(j).trans(3)
solid.AddFace _
x0, y0, z0, _
x2, y2, z2, _
x1, y1, z1
solid.AddFace _
x2, y2, z2, _
x3, y3, z3, _
x1, y1, z1
x0 = x2
y0 = y2
z0 = z2
x1 = x3
y1 = y3
z1 = z3
Next j
Next i
' Add the final curve to solid assuming
' the curve is stored oriented towards the
' transformations.
If cap_ends Then
Set face = New Face3d
solid.Faces.Add face
For i = 2 To NumCurvePts
face.AddPoints _
CurvePoints(i).trans(1), _
CurvePoints(i).trans(2), _
CurvePoints(i).trans(3)
Next i
End If
End Sub
' Clip the display solid.
Public Sub ClipEye(ByVal r As Single)
If Not solid Is Nothing Then solid.ClipEye r
End Sub
' Add a point to the curve.
Public Sub AddCurvePoint(X As Single, Y As Single, z As Single)
NumCurvePts = NumCurvePts + 1
ReDim Preserve CurvePoints(1 To NumCurvePts)
CurvePoints(NumCurvePts).coord(1) = X
CurvePoints(NumCurvePts).coord(2) = Y
CurvePoints(NumCurvePts).coord(3) = z
CurvePoints(NumCurvePts).coord(4) = 1
End Sub
' Set a transformation.
Public Sub SetTransformation(M() As Single)
NumTrans = NumTrans + 1
ReDim Preserve trans(1 To NumTrans)
m3MatCopy trans(NumTrans).M, M
End Sub
' Apply a transformation matrix which may not
' contain 0, 0, 0, 1 in the last column to the
' object.
Public Sub ApplyFull(M() As Single)
Dim i As Integer
' Transform the curve.
For i = 1 To NumCurvePts
m3ApplyFull CurvePoints(i).coord, M, _
CurvePoints(i).trans
Next i
' Transform the display solid if it exists.
If Not solid Is Nothing Then solid.ApplyFull M
End Sub
' Apply a transformation matrix to the object.
Public Sub Apply(M() As Single)
Dim i As Integer
' Transform the curve.
For i = 1 To NumCurvePts
m3Apply CurvePoints(i).coord, M, _
CurvePoints(i).trans
Next i
' Transform the display solid if it exists.
If Not solid Is Nothing Then solid.Apply M
End Sub
' Draw the extrusion on a Form, Printer, or
' PictureBox.
Public Sub Draw(ByVal pic As PictureBox, Optional r As Variant)
If Not solid Is Nothing Then _
solid.Draw pic, r
End Sub
' Perform backface removal on the display solid.
Public Sub Cull(ByVal X As Single, ByVal Y As Single, ByVal z As Single)
If Not solid Is Nothing Then solid.Cull X, Y, z
End Sub
' Set or clear the Culled property for the solid.
Property Let Culled(value As Boolean)
If Not solid Is Nothing Then solid.Culled = value
End Property