Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. ;//////////////////////////////////////////////////////////////////////////////
  2. ;//
  3. ;//////////////////////////////////////////////////////////////////////////////
  4. Procedure.f min(a.f,b.f)
  5. If a<b
  6. ProcedureReturn a
  7. EndIf
  8. ProcedureReturn b
  9. EndProcedure
  10.  
  11. ;//////////////////////////////////////////////////////////////////////////////
  12. ;//
  13. ;//////////////////////////////////////////////////////////////////////////////
  14. Procedure.f max(a.f,b.f)
  15. If a>b
  16. ProcedureReturn a
  17. EndIf
  18. ProcedureReturn b
  19. EndProcedure
  20.  
  21. ;//////////////////////////////////////////////////////////////////////////////
  22. ;//
  23. ;//////////////////////////////////////////////////////////////////////////////
  24. Structure sVector2f
  25. x.f
  26. y.f
  27. EndStructure
  28. ;//////////////////////////////////////////////////////////////////////////////
  29. ;//
  30. ;//////////////////////////////////////////////////////////////////////////////
  31. ProcedureDLL.i createVector2f(x.f, y.f)
  32. *v.sVector2f = AllocateMemory(SizeOf(sVector2f))
  33. If *v
  34. *v\x = x
  35. *v\y = y
  36. ProcedureReturn *v
  37. EndIf
  38. EndProcedure
  39.  
  40. ;//////////////////////////////////////////////////////////////////////////////
  41. ;//
  42. ;//////////////////////////////////////////////////////////////////////////////
  43. ProcedureDLL deleteVector2f(*v.sVector2f)
  44. If *v
  45. *v\x = #Null
  46. *v\y = #Null
  47. FreeMemory(*v)
  48. EndIf
  49. EndProcedure
  50.  
  51. ;//////////////////////////////////////////////////////////////////////////////
  52. ;//
  53. ;//////////////////////////////////////////////////////////////////////////////
  54. ProcedureDLL addVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f)
  55. *result\x = *a\x + *b\x
  56. *result\y = *a\y + *b\y
  57. EndProcedure
  58.  
  59. ;//////////////////////////////////////////////////////////////////////////////
  60. ;//
  61. ;//////////////////////////////////////////////////////////////////////////////
  62. ProcedureDLL subVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f)
  63. *result\x = *a\x - *b\x
  64. *result\y = *a\y - *b\y
  65. EndProcedure
  66.  
  67. ;//////////////////////////////////////////////////////////////////////////////
  68. ;//
  69. ;//////////////////////////////////////////////////////////////////////////////
  70. ProcedureDLL mulVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f)
  71. *result\x = *a\x * *b\x
  72. *result\y = *a\y * *b\y
  73. EndProcedure
  74.  
  75. ;//////////////////////////////////////////////////////////////////////////////
  76. ;//
  77. ;//////////////////////////////////////////////////////////////////////////////
  78. ProcedureDLL divVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f)
  79. If *b\x <> 0
  80. *result\x = *a\x / *b\x
  81. EndIf
  82.  
  83. If *b\y <> 0
  84. *result\y = *a\y / *b\y
  85. EndIf
  86. EndProcedure
  87.  
  88. ;//////////////////////////////////////////////////////////////////////////////
  89. ;//
  90. ;//////////////////////////////////////////////////////////////////////////////
  91. ProcedureDLL scaleVector2f(*a.sVector2f, value.f)
  92. *a\x * value
  93. *a\y * value
  94. EndProcedure
  95.  
  96. ;//////////////////////////////////////////////////////////////////////////////
  97. ;//
  98. ;//////////////////////////////////////////////////////////////////////////////
  99. ProcedureDLL.f squareLengthVector2f(*v.sVector2f)
  100. ProcedureReturn (*v\x * *v\x) + (*v\y * *v\y)
  101. EndProcedure
  102.  
  103. ;//////////////////////////////////////////////////////////////////////////////
  104. ;//
  105. ;//////////////////////////////////////////////////////////////////////////////
  106. ProcedureDLL.f lengthVector2f(*v.sVector2f)
  107. ProcedureReturn Sqr((*v\x * *v\x) + (*v\y * *v\y))
  108. EndProcedure
  109.  
  110. ;//////////////////////////////////////////////////////////////////////////////
  111. ;//
  112. ;//////////////////////////////////////////////////////////////////////////////
  113. ProcedureDLL.f dotProductVector2f(*a.sVector2f, *b.sVector2f)
  114. ProcedureReturn (*a\x * *b\x) + (*a\y * *b\y)
  115. EndProcedure
  116.  
  117. ;//////////////////////////////////////////////////////////////////////////////
  118. ;//
  119. ;//////////////////////////////////////////////////////////////////////////////
  120. ProcedureDLL normalizeVector2f(*v.sVector2f)
  121. l.f = Sqr((*v\x * *v\x) + (*v\y * *v\y))
  122. If l > 0
  123. *v\x / l
  124. *v\y / l
  125. EndIf
  126. EndProcedure
  127.  
  128. ;//////////////////////////////////////////////////////////////////////////////
  129. ;//
  130. ;//////////////////////////////////////////////////////////////////////////////
  131. ProcedureDLL middlePointVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f)
  132. *result\x = (*a\x + *b\x) * 0.5
  133. *result\y = (*a\y + *b\y) * 0.5
  134. EndProcedure
  135.  
  136. ;//////////////////////////////////////////////////////////////////////////////
  137. ;//
  138. ;//////////////////////////////////////////////////////////////////////////////
  139. ProcedureDLL lerpVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f, val.f)
  140. *result\x = *a\x + (*b\x - *a\x) * val
  141. *result\y = *a\y + (*b\y - *a\y) * val
  142. EndProcedure
  143.  
  144. ;//////////////////////////////////////////////////////////////////////////////
  145. ;//
  146. ;//////////////////////////////////////////////////////////////////////////////
  147. ProcedureDLL.f crossProductVector2f(*a.sVector2f, *b.sVector2f)
  148. ProcedureReturn *a\x * *b\y - *a\y * *b\x
  149. EndProcedure
  150.  
  151. ;//////////////////////////////////////////////////////////////////////////////
  152. ;//
  153. ;//////////////////////////////////////////////////////////////////////////////
  154. ProcedureDLL randomDeviantVector2f(*v.sVector2f, angle.f)
  155. angle = angle * Random(angle) * (#PI*2)
  156. cosa.f = Cos(angle)
  157. sina.f = Cos(angle)
  158. *v\x = cosa * *v\x - sina - *v\y
  159. *v\y = sina * *v\x + cosa * *v\y
  160. EndProcedure
  161.  
  162. ;//////////////////////////////////////////////////////////////////////////////
  163. ;//
  164. ;//////////////////////////////////////////////////////////////////////////////
  165. ProcedureDLL perpendicularVector2f(*v.sVector2f)
  166. Protected x.f = *v\x
  167. Protected y.f = *v\y
  168. *v\x = -y
  169. *v\y = x
  170. EndProcedure
  171.  
  172. ;//////////////////////////////////////////////////////////////////////////////
  173. ;//
  174. ;//////////////////////////////////////////////////////////////////////////////
  175. ProcedureDLL reflectVector2f(*v.sVector2f, *normal.sVector2f)
  176. Protected dot.f = (*v\x * *normal\x) + (*v\y * *normal\y)
  177. *v\x = *v\x - ( 2 * dot * *normal\x )
  178. *v\y = *v\y - ( 2 * dot * *normal\y )
  179. EndProcedure
  180.  
  181. ;//////////////////////////////////////////////////////////////////////////////
  182. ;//
  183. ;//////////////////////////////////////////////////////////////////////////////
  184. Procedure.b isCloseVector2f(*A.sVector2f , *B.sVector2f)
  185. tolerance.f = 0.01
  186. If (Abs(*A\x - *B\x) < tolerance) And (Abs(*A\y - *B\y) < tolerance)
  187. ProcedureReturn #True
  188. Else
  189. ProcedureReturn #False
  190. EndIf
  191. EndProcedure
  192.  
  193. ;//////////////////////////////////////////////////////////////////////////////
  194. ;//
  195. ;//////////////////////////////////////////////////////////////////////////////
  196. ProcedureDLL.i intersectVector2f(*p1.sVector2f,*p2.sVector2f,*p3.sVector2f,*p4.sVector2f)
  197.  
  198. Protected.f x1 = *p1\x, x2 = *p2\x, x3 = *p3\x, x4 = *p4\x;
  199. Protected.f y1 = *p1\y, y2 = *p2\y, y3 = *p3\y, y4 = *p4\y;
  200.  
  201. Protected.d d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
  202.  
  203. If d = 0
  204. ProcedureReturn #Null
  205. EndIf
  206.  
  207. Protected.f pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4)
  208. Protected.f x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d
  209. Protected.f y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d
  210.  
  211. If ( x < min(x1, x2) Or x > max(x1, x2) Or x < min(x3, x4) Or x > max(x3, x4) )
  212. ProcedureReturn #Null
  213. EndIf
  214.  
  215. If ( y < min(y1, y2) Or y > max(y1, y2) Or y < min(y3, y4) Or y > max(y3, y4) )
  216. ProcedureReturn #Null
  217. EndIf
  218.  
  219. ProcedureReturn createVector2f(x,y)
  220. EndProcedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement