-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVertices and Triangles.vb
240 lines (201 loc) · 6.58 KB
/
Vertices and Triangles.vb
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
Public Structure Vertex_Coloured
Public Position As VEC3
Public Colour As Color
Public Normal As VEC3
Public Sub New(ByVal _position As VEC3,
ByVal _colour As Color,
ByVal _normal As VEC3)
Position = _position
Colour = _colour
Normal = _normal
End Sub
Public Sub New(ByVal X As Double, ByVal Y As Double, ByVal Z As Double,
ByVal R As Byte, ByVal G As Byte, ByVal B As Byte)
Position = New VEC3(X, Y, Z)
Colour = Color.FromArgb(R, G, B)
End Sub
Public Sub SetColour(ByVal C As Color)
Colour = C
End Sub
Public Property X() As Double
Get
Return Position.X
End Get
Set(ByVal value As Double)
Position.X = value
End Set
End Property
Public Property Y() As Double
Get
Return Position.Y
End Get
Set(ByVal value As Double)
Position.Y = value
End Set
End Property
Public Property Z() As Double
Get
Return Position.Z
End Get
Set(ByVal value As Double)
Position.Z = value
End Set
End Property
Public ReadOnly Property R() As Double
Get
Return Colour.R
End Get
End Property
Public ReadOnly Property G() As Double
Get
Return Colour.G
End Get
End Property
Public ReadOnly Property B() As Double
Get
Return Colour.B
End Get
End Property
Shared Function LERP(ByVal v1 As Vertex_Coloured,
ByVal v2 As Vertex_Coloured,
ByVal t As Double) As Vertex_Coloured
Return New Vertex_Coloured((v1.Position + (v2.Position - v1.Position) * t), Add_Cr(v1.Colour, Mult_Cr((Sub_Cr(v2.Colour, v1.Colour)), t)), v1.Normal)
End Function
Shared Function Add_Cr(ByVal C1 As Color,
ByVal C2 As VEC3) As Color
Return Color.FromArgb(C1.R + C2.X, C1.G + C2.Y, C1.B + C2.Z)
End Function
Shared Function Sub_Cr(ByVal C1 As Color,
ByVal C2 As Color) As VEC3
Return New VEC3(CDbl(C1.R) - CDbl(C2.R), CDbl(C1.G) - CDbl(C2.G), CDbl(C1.B) - CDbl(C2.B))
End Function
Shared Function Mult_Cr(ByVal C1 As VEC3,
ByVal C2 As VEC3) As VEC3
Return New VEC3(C1.X * C2.X, C1.Y * C2.Y, C1.Z * C2.Z)
End Function
Shared Function Mult_Cr(ByVal C1 As VEC3,
ByVal t As Double) As VEC3
Return New VEC3(C1.X * t, C1.Y * t, C1.Z * t)
End Function
End Structure
Public Structure Vertex_Textured
Public Position As VEC3
Public TextureC As PointF
Public Normal As VEC3
Public Light_Level As Double
Public Sub Set_Light_Level(ByVal value As Double)
Light_Level = Math.Max(0, Math.Min(1, value))
End Sub
Public Sub New(ByVal _position As VEC3, ByVal _textureC As PointF, ByVal _normal As VEC3, ByVal _Light_Level As Double)
Position = _position
TextureC = _textureC
Normal = _normal
Light_Level = _Light_Level
End Sub
Public Sub New(ByVal _position As VEC3, ByVal _textureC As PointF, ByVal _normal As VEC3)
Position = _position
TextureC = _textureC
Normal = _normal
End Sub
Public Sub New(ByVal X As Double, ByVal Y As Double, ByVal Z As Double,
ByVal U As Double, ByVal V As Double)
Position = New VEC3(X, Y, Z)
TextureC = New PointF(U, V)
End Sub
Public Property X() As Double
Get
Return Position.X
End Get
Set(ByVal value As Double)
Position.X = value
End Set
End Property
Public Property Y() As Double
Get
Return Position.Y
End Get
Set(ByVal value As Double)
Position.Y = value
End Set
End Property
Public Property Z() As Double
Get
Return Position.Z
End Get
Set(ByVal value As Double)
Position.Z = value
End Set
End Property
Public ReadOnly Property U() As Single
Get
Return TextureC.X
End Get
End Property
Public ReadOnly Property V() As Single
Get
Return TextureC.Y
End Get
End Property
Shared Function LERP(ByVal v1 As Vertex_Textured,
ByVal v2 As Vertex_Textured,
ByVal t As Double) As Vertex_Textured
Return New Vertex_Textured((v1.Position + (v2.Position - v1.Position) * t),
Add_PF(v1.TextureC, Mult_PF((Sub_PF(v2.TextureC, v1.TextureC)), t)),
v1.Normal,
v1.Light_Level + (v2.Light_Level - v1.Light_Level) * t)
End Function
Shared Function Add_PF(ByVal PF1 As PointF,
ByVal PF2 As PointF) As PointF
Return New PointF(PF1.X + PF2.X, PF1.Y + PF2.Y)
End Function
Shared Function Sub_PF(ByVal PF1 As PointF,
ByVal PF2 As PointF) As PointF
Return New PointF(PF1.X - PF2.X, PF1.Y - PF2.Y)
End Function
Shared Function Mult_PF(ByVal PF1 As PointF,
ByVal t As Double) As PointF
Return New PointF(PF1.X * t, PF1.Y * t)
End Function
End Structure
Public Structure Triangle_Coloured
Public V1 As Vertex_Coloured
Public V2 As Vertex_Coloured
Public V3 As Vertex_Coloured
Public Normal As VEC3
Public Sub New(ByVal _V1 As Vertex_Coloured,
ByVal _V2 As Vertex_Coloured,
ByVal _V3 As Vertex_Coloured)
V1 = _V1
V2 = _V2
V3 = _V3
End Sub
End Structure
Public Structure Triangle_Textured
Public V1 As Vertex_Textured
Public V2 As Vertex_Textured
Public V3 As Vertex_Textured
Public TX As Texture
Public Normal As VEC3
Public Sub New(ByVal _V1 As Vertex_Textured,
ByVal _V2 As Vertex_Textured,
ByVal _V3 As Vertex_Textured)
V1 = _V1
V2 = _V2
V3 = _V3
End Sub
End Structure
Public Structure Triangle
Public V1 As Integer
Public V2 As Integer
Public V3 As Integer
Public Type As Model.Triangle_Type
Public Sub New(ByVal _V1 As Integer,
ByVal _V2 As Integer,
ByVal _V3 As Integer,
ByVal TType As Model.Triangle_Type)
V1 = _V1
V2 = _V2
V3 = _V3
Type = TType
End Sub
End Structure