January 26, 2021, 06:22:47 AM

Author Topic: [bb] Vector Graphics Functions by SSS [ 1+ years ago ]  (Read 395 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Vector Graphics Functions by SSS [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Vector Graphics Functions
Author : SSS
Posted : 1+ years ago

Description : hi all, in my spare time i made some vector geometry methods, and i thought after i made them that some people might find them usefull, i havnt added alot of features like color blending or collision but if people thought that they would like this then i would implement them :D

Please note, this was an exercise i set for myself in writing a linked list... but then i thought that it might be usefull, in the example, click the mouse in relation to the SQUARE in the center to append a vector in that direction + that magnetude


Code :
Code: BlitzBasic
  1. here is the function set
  2.  
  3.  
  4. Type Vector2
  5. Field x,y
  6. End Type
  7. Type Vector3
  8. Field x,y,z
  9. End Type
  10.  
  11. Type VectorGeomObject
  12. Field start.VectorGeomSet
  13. Field size
  14. Field position.Vector2
  15. End Type
  16.  
  17. Type VectorGeomSet
  18. Field movement.Vector2
  19. Field StartColor.Vector3
  20. Field EndColor.Vector3
  21. Field NextSet.VectorGeomSet
  22. End Type
  23.  
  24.  
  25. Function Vec2.Vector2(x,y)
  26.         v.Vector2 = New Vector2
  27.         vx = x
  28.         vy = y
  29.         Return v
  30. End Function
  31.  
  32. Function Vec3.Vector3(x,y,z)
  33.         v.Vector3 = New Vector3
  34.         vx = x
  35.         vy = y
  36.         vz = z
  37.         Return v
  38. End Function
  39.  
  40. Function CreateVector(x = 0, y = 0)
  41.         v.VectorGeomObject = New VectorGeomObject
  42.         vsize = 0
  43.         vposition.Vector2 = New Vector2
  44.         vpositionx = x
  45.         vpositiony = y
  46.         Return Handle(v)
  47. End Function
  48.  
  49. Function PositionVector(hVector,x,y)
  50.         v.VectorGeomObject = Object.VectorGeomObject(hVector)
  51.         vpositionx = x
  52.         vpositiony = y
  53. End Function
  54.  
  55. Function AppendVector(hVector,vector.Vector2,startcolor.Vector3,endcolor.Vector3)
  56.         v.VectorGeomObject = Object.VectorGeomObject(hVector)
  57.         If vsize = 0
  58.                 vstart.VectorGeomSet = New VectorGeomSet
  59.                 vecset.VectorGeomSet = vstart
  60.                 vecsetmovement.Vector2 = vector
  61.                 vecsetStartColor = startcolor
  62.                 vecsetEndColor = endcolor
  63.                 vecsetNextSet.VectorGeomSet = New VectorGeomSet
  64.                 vsize = vsize +1
  65.         Else
  66.                 vecset.VectorGeomSet = vstart
  67.                 For i = 1 To vsize-1
  68.                         vecset = vecsetNextSet
  69.                 Next
  70.                 vecsetNextSet.VectorGeomSet = New VectorGeomSet
  71.                 vecset = vecsetNextSet
  72.                 vecsetmovement.Vector2 = vector
  73.                 vecsetStartColor = startcolor
  74.                 vecsetEndColor = endcolor
  75.                 vsize = vsize+1
  76.         EndIf
  77. End Function
  78.  
  79. Function GetNumVectors(hVector)
  80.         v.VectorGeomObject = Object.VectorGeomObject(hVector)
  81.         Return vsize
  82. End Function
  83.  
  84. Function EditVector(hVector,Index,vector.Vector2,startcolor.Vector3,endcolor.Vector3)
  85.         v.VectorGeomObject = Object.VectorGeomObject(hVector)
  86.         If Index > vsize Then Return
  87.         vecset.VectorGeomSet = vstart
  88.         For i = 1 To Index-1
  89.                 vecset = vecsetNextSet
  90.         Next
  91.         vecsetmovement = vector
  92.         vecsetStartColor = startcolor
  93.         vecsetEndColor = endcolor
  94. End Function
  95.  
  96. Function VectorStartColor(hVector,Index,startcolor.Vector3)
  97.         v.VectorGeomObject = Object.VectorGeomObject(hVector)
  98.         If Index > vsize Then Return
  99.         vecset.VectorGeomSet = vstart
  100.         For i = 1 To Index-1
  101.                 vecset = vecsetNextSet
  102.         Next
  103.         vecsetStartColor = startcolor
  104. End Function
  105.  
  106. Function VectorMovement(hVector,Index,vector.Vector2)
  107.         v.VectorGeomObject = Object.VectorGeomObject(hVector)
  108.         If Index > vsize Then Return
  109.         vecset.VectorGeomSet = vstart
  110.         For i = 1 To Index-1
  111.                 vecset = vecsetNextSet
  112.         Next
  113.         vecsetmovement = vector
  114. End Function
  115.  
  116. Function DrawVectors()
  117.         Local x = 0
  118.         Local y = 0
  119.         For v.VectorGeomObject = Each VectorGeomObject
  120.                 vecset.VectorGeomSet = vstart
  121.                 x = vpositionx
  122.                 y = vpositiony
  123.                 For i = 1 To vsize
  124.                         Color vecsetStartColorx,vecsetStartColory,vecsetStartColorz
  125.                         Line x,y,vecsetmovementx+x,vecsetmovementy+y
  126.                         x = x + vecsetmovementx
  127.                         y = y + vecsetmovementy
  128.                         vecset = vecsetNextSet
  129.                 Next
  130.         Next
  131. End Function
  132.  
  133. and here is an example
  134.  
  135. Graphics 640,480,32,2
  136. SetBuffer BackBuffer()
  137. xz = CreateVector(320,240)
  138.  
  139.  
  140. While Not KeyDown(1)
  141. Cls
  142. ;x = x + 3
  143. ;If x > 630 Then x = -10
  144. Rect 310,230,20,20
  145. If MouseDown(1)
  146. AppendVector(xz,Vec2(MouseX()-320,MouseY()-240),Vec3(Rand(255),Rand(255),Rand(255)),Vec3(0,0,0))
  147. Delay 100
  148. EndIf
  149. DrawVectors()
  150. Flip
  151. Wend


Comments :


iamdaman13(Posted 1+ years ago)

 Sorry, posted in wrong topic.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal