Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. Dim _start As Double = 1.5 * Math.PI '1.5
  2. Dim _stop As Double = 4.1 * Math.PI '4.1
  3.  
  4. Dim v3Tmp As Vector3
  5. Dim v2Tmp As Vector2
  6.  
  7. Dim tmpcount As Integer = 0
  8. points2D_ = New List(Of Vector2)
  9. Dim _newName As Integer
  10. _newName = _name + 1
  11.  
  12. 'If renderMode = RenderingMode.Select Then MsgBox("hghgh")
  13.  
  14. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  15. '''''''''' CALCOLO PUNTI PER DISEGNO ROTOLO. ''''''''''
  16. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  17.  
  18. For i As Double = _start To _stop - 1 Step 0.2
  19. 'Diametro Esterno.
  20. v3Tmp.X = ((sadH - 1) * (_interasseH / 100)) + (((_interasseH / 100) - _coil.diametroE) / 2) + (_coil.diametroE / 2) + CDbl(_coil.diametroE / 2 * Math.Cos(i))
  21. v3Tmp.Y = ((_totSaddleV - sadV - 1) * (_interasseV / 100)) + (((_interasseV / 100) - _coil.larghezza) / 2) '+ (Width * y)
  22. v3Tmp.Z = (_coil.diametroE / 2) + (_coil.diametroE / 2 * Math.Sin(i))
  23.  
  24. _out.Add(v3Tmp)
  25. _coil.points3D.Add(v3Tmp)
  26.  
  27. v2Tmp = TreDTo2d(v3Tmp, GlControl1)
  28. _coil.points2D.Add(v2Tmp)
  29.  
  30. 'Diametro Interno.
  31. v3Tmp.X = ((sadH - 1) * (_interasseH / 100)) + (((_interasseH / 100) - _coil.diametroI) / 2) + (_coil.diametroI / 2) + CDbl(_coil.diametroI / 2 * Math.Cos(i))
  32. v3Tmp.Y = ((_totSaddleV - sadV - 1) * (_interasseV / 100)) + (((_interasseV / 100) - _coil.larghezza) / 2) '+ (Width * y)
  33. v3Tmp.Z = (_coil.diametroE / 2) + (_coil.diametroI / 2 * Math.Sin(i))
  34.  
  35. _in.Add(v3Tmp)
  36.  
  37. v2Tmp = TreDTo2d(v3Tmp, GlControl1)
  38. _coil.points2D.Add(v2Tmp)
  39.  
  40. tmpcount += 1
  41. Next
  42.  
  43. v3Tmp.X = ((sadH - 1) * (_interasseH / 100)) + (((_interasseH / 100) - _coil.diametroE) / 2) + (_coil.diametroE / 2) + CDbl(_coil.diametroE / 2 * Math.Cos(_start))
  44. v3Tmp.Y = ((_totSaddleV - sadV - 1) * (_interasseV / 100)) + (((_interasseV / 100) - _coil.larghezza) / 2) '+ (Width * y)
  45. v3Tmp.Z = (_coil.diametroE / 2) + CDbl(_coil.diametroE / 2 * Math.Sin(_start))
  46.  
  47. _out.Add(v3Tmp)
  48. _coil.points3D.Add(v3Tmp)
  49.  
  50. v2Tmp = TreDTo2d(v3Tmp, GlControl1)
  51. _coil.points2D.Add(v2Tmp)
  52.  
  53. points2D_ = _coil.points2D
  54.  
  55. v3Tmp.X = ((sadH - 1) * (_interasseH / 100)) + (((_interasseH / 100) - _coil.diametroI) / 2) + (_coil.diametroI / 2) + CDbl(_coil.diametroI / 2 * Math.Cos(_start))
  56. v3Tmp.Y = ((_totSaddleV - sadV - 1) * (_interasseV / 100)) + (((_interasseV / 100) - _coil.larghezza) / 2) '+ (Width * y)
  57. v3Tmp.Z = (_coil.diametroE / 2) + CDbl(_coil.diametroI / 2 * Math.Sin(_start))
  58.  
  59. _in.Add(v3Tmp)
  60.  
  61. v2Tmp = TreDTo2d(v3Tmp, GlControl1)
  62. _coil.points2D.Add(v2Tmp)
  63.  
  64.  
  65.  
  66. 'Calcolo limiti punti 3D.
  67. Dim _limits3D() As Integer = calcLimits3D(_coil)
  68. _coil.zMin = _limits3D(0)
  69. _coil.zMax = _limits3D(1)
  70.  
  71. _coil.center = calcCenter3D(_coil)
  72.  
  73. ''''''''''''''''''''''''''''''''''''''''
  74. 'Calcolo limiti punti 2D.
  75. Dim _limits() As Integer = calcLimits2D(_coil)
  76.  
  77. _coil.xMin = _limits(0)
  78. _coil.xMax = _limits(1)
  79. _coil.yMin = _limits(2)
  80. _coil.yMax = _limits(3)
  81.  
  82.  
  83. xMin = _limits(0)
  84. xMax = _limits(1)
  85. yMin = _limits(2) - 15
  86. yMax = _limits(3)
  87. ''''''''''''''''''''''''''''''''''''''''
  88.  
  89. 'Dictionary con tutti i rotoli.
  90. coils.Add(_coil.id, _coil)
  91. 'coils__.Add(_coil.id, _coil)
  92.  
  93.  
  94.  
  95. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  96. '''''''''' DISEGNO DEL ROTOLO CON I PUNTI CALCOLATI. ''''''''''
  97. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  98. Dim _color As Double
  99.  
  100. 'If renderMode = RenderingMode.Select Then
  101. ' GL.LoadName(_name)
  102. 'End If
  103. 'GL.PushMatrix()
  104. If renderMode = RenderingMode.Select Then
  105. GL.PushName(_newName) 'GL.LoadName(_newName)
  106.  
  107. End If
  108.  
  109. 'Corona Davanti.
  110. GL.LineWidth(0.5)
  111. GL.Begin(PrimitiveType.QuadStrip)
  112.  
  113. For i As Double = 0 To _out.Count - 1
  114. If _coil.selected Then
  115. GL.Color3(Color.Blue)
  116. Else
  117. If (i < (_out.Count / 4)) Then
  118. _color = (i) / (_out.Count / 4) + 0.2
  119. ElseIf (i >= (_out.Count / 4) And i < (_out.Count / 2)) Then
  120. _color = ((_out.Count / 2) - i) / (_out.Count / 4) + 0.2
  121. ElseIf (i >= (_out.Count / 2) And i < (_out.Count * 3 / 4)) Then
  122. _color = (i - (_out.Count / 2)) / (_out.Count / 4) + 0.2
  123. Else
  124. _color = ((_out.Count / 2) - (i - (_out.Count / 2))) / (_out.Count / 4) + 0.2
  125. End If
  126.  
  127. GL.Color4(0.901 * _color, 0.901 * _color, 0.941 * _color, _color)
  128. End If
  129.  
  130. GL.Vertex3(_out(i).X, _out(i).Y, _out(i).Z)
  131. GL.Vertex3(_in(i).X, _in(i).Y, _in(i).Z)
  132. Next
  133.  
  134. GL.End()
  135. 'GL.PopMatrix()
  136.  
  137.  
  138. 'Corona Dietro.
  139. 'GL.PushMatrix()
  140. GL.LineWidth(0.5)
  141. If renderMode = RenderingMode.Select Then GL.PushName(_newName)
  142. GL.Begin(PrimitiveType.QuadStrip)
  143.  
  144. For i As Double = 0 To _out.Count - 1
  145. If _coil.selected Then
  146. GL.Color3(Color.Blue)
  147. Else
  148.  
  149. If (i < (_out.Count / 4)) Then
  150. _color = (i) / (_out.Count / 4) + 0.4
  151. ElseIf (i >= (_out.Count / 4) And i < (_out.Count / 2)) Then
  152. _color = ((_out.Count / 2) - i) / (_out.Count / 4) + 0.4
  153. ElseIf (i >= (_out.Count / 2) And i < (_out.Count * 3 / 4)) Then
  154. _color = (i - (_out.Count / 2)) / (_out.Count / 4) + 0.4
  155. Else
  156. _color = ((_out.Count / 2) - (i - (_out.Count / 2))) / (_out.Count / 4) + 0.4
  157. End If
  158.  
  159. GL.Color4(0.901 * _color, 0.901 * _color, 0.941 * _color, _color)
  160. End If
  161.  
  162. GL.Vertex3(_out(i).X, _out(i).Y + _coil.larghezza, _out(i).Z)
  163. GL.Vertex3(_in(i).X, _in(i).Y + _coil.larghezza, _in(i).Z)
  164. Next
  165.  
  166. GL.End()
  167. 'GL.PopMatrix()
  168.  
  169.  
  170. 'Superficie Esterna.
  171. GL.LineWidth(0.5)
  172. 'GL.PushMatrix()
  173. If renderMode = RenderingMode.Select Then GL.PushName(_newName)
  174.  
  175. GL.Begin(PrimitiveType.QuadStrip)
  176.  
  177. For i As Double = 0 To _out.Count - 1
  178. If _coil.selected Then
  179. GL.Color3(Color.Blue)
  180. Else
  181. If (i < (_out.Count / 4)) Then
  182. _color = (i) / (_out.Count / 4)
  183. ElseIf (i >= (_out.Count / 4) And i < (_out.Count / 2)) Then
  184. _color = ((_out.Count / 2) - i) / (_out.Count / 4)
  185. ElseIf (i >= (_out.Count / 2) And i < (_out.Count * 3 / 4)) Then
  186. _color = (i - (_out.Count / 2)) / (_out.Count / 4)
  187. Else
  188. _color = ((_out.Count / 2) - (i - (_out.Count / 2))) / (_out.Count / 4)
  189. End If
  190.  
  191. GL.Color4(0.901 * _color, 0.901 * _color, 0.941 * _color, _color)
  192. End If
  193.  
  194. GL.Vertex3(_out(i).X, _out(i).Y + _coil.larghezza, _out(i).Z)
  195. GL.Vertex3(_out(i).X, _out(i).Y, _out(i).Z)
  196. Next
  197.  
  198. GL.End()
  199. 'GL.PopMatrix()
  200.  
  201. 'Superficie interna.
  202. GL.LineWidth(0.5)
  203. 'GL.PushMatrix()
  204. If renderMode = RenderingMode.Select Then GL.PushName(_newName)
  205.  
  206. GL.Begin(PrimitiveType.QuadStrip)
  207.  
  208. For i As Double = 0 To _out.Count - 1
  209. If _coil.selected Then
  210. GL.Color3(Color.Blue)
  211. Else
  212. If (i < (_out.Count / 2)) Then
  213. _color = i / _out.Count
  214. Else
  215. _color = (_out.Count - i) / _out.Count
  216. End If
  217.  
  218.  
  219. GL.Color4(0.901 * _color, 0.901 * _color, 0.941 * _color, _color)
  220. End If
  221.  
  222. GL.Vertex3(_in(i).X, _in(i).Y + _coil.larghezza, _in(i).Z)
  223. GL.Vertex3(_in(i).X, _in(i).Y, _in(i).Z)
  224. Next
  225.  
  226. GL.End()
  227. 'GL.PopMatrix()
  228.  
  229. End Sub
  230.  
  231. Dim viewport(3) As Integer
  232.  
  233. GL.SelectBuffer(512, selectBuf)
  234.  
  235. GL.RenderMode(RenderingMode.Select)
  236.  
  237. GL.GetInteger(GetPName.Viewport, viewport)
  238. GL.PushMatrix()
  239. GL.MatrixMode(MatrixMode.Projection)
  240. GL.LoadIdentity()
  241. PickMatrix(e.X, e.Y, 5, 5, viewport)
  242.  
  243. 'Dim projection As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(0.7853982F, 4.0F / 3.0F, 0.1F, 100.0F) '; // this projection matrix is the same as one in glControlWindow_Paint method.
  244.  
  245. Dim projection As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.04, Me.Width / Me.Height, 100, 10000)
  246.  
  247. GL.MultMatrix(projection)
  248.  
  249. GL.MatrixMode(MatrixMode.Modelview)
  250.  
  251. GL.PushMatrix()
  252.  
  253.  
  254. Try
  255. Dim singleCoil As coil = Nothing
  256. initCoil(singleCoil)
  257. singleCoil.points2D = New List(Of Vector2)
  258. singleCoil.points3D = New List(Of Vector3)
  259.  
  260. _name = 0
  261.  
  262. For i As Integer = 0 To 1 ' _Coils.Length - 1
  263. Dim idCoil As Long = CLng(_Coils(i)(0))
  264.  
  265. If idCoil > 0 Then
  266. singleCoil.id = idCoil
  267.  
  268. singleCoil.fila = CStr(_Coils(i)(1))
  269. singleCoil.box = CInt(_Coils(i)(2))
  270. singleCoil.livello = CInt(_Coils(i)(3))
  271.  
  272. singleCoil.diametroE = CInt(_Coils(i)(4)) / 100
  273. singleCoil.diametroI = 6.1
  274. singleCoil.larghezza = CInt(_Coils(i)(5)) / 100
  275.  
  276. If (singleCoil.id = clickedCoil) Then
  277. singleCoil.selected = True
  278. Else
  279. singleCoil.selected = False
  280. End If
  281.  
  282.  
  283. drawFilledCoil(convertFila(CStr(_Coils(i)(1))), CInt(_Coils(i)(2)), CInt(_Coils(i)(3)), singleCoil, RenderingMode.Select)
  284.  
  285. GL.PopName()
  286. GL.PopMatrix()
  287.  
  288. End If
  289. Next
  290. Catch ex As Exception
  291.  
  292. End Try
  293. 'GL.PopMatrix()
  294. 'GL.Flush()
  295.  
  296. _hits = GL.RenderMode(RenderingMode.Render)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement