Ooops
November 30, 2020, 02:12:52 AM

Author Topic: [bb] PickedVertex() by KimoTech [ 1+ years ago ]  (Read 744 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] PickedVertex() by KimoTech [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : PickedVertex()
Author : KimoTech
Posted : 1+ years ago

Description : Returns the nearest picked vertex.

Code :
Code: BlitzBasic
  1. ; I havent tested it much yet, so probertly some bugs :)
  2.  
  3. Function PickedVertex()
  4. surf=PickedSurface()
  5. tri=PickedTriangle()
  6. v1=TriangleVertex(surf,tri,1)
  7. v2=TriangleVertex(surf,tri,2)
  8. v3=TriangleVertex(surf,tri,3)
  9.  
  10. Dist1X#=Abs(VertexX#(surf,v1)-PickedX#())
  11. Dist1Y#=Abs(VertexY#(surf,v1)-PickedY#())
  12. Dist1Z#=Abs(VertexZ#(surf,v1)-PickedZ#())
  13. Dist1#=Dist1X#+Dist1Y#+Dist1Z#
  14.  
  15. Dist2X#=Abs(VertexX#(surf,v2)-PickedX#())
  16. Dist2Y#=Abs(VertexY#(surf,v2)-PickedY#())
  17. Dist2Z#=Abs(VertexZ#(surf,v2)-PickedZ#())
  18. Dist2#=Dist2X#+Dist2Y#+Dist2Z#
  19.  
  20. Dist3X#=Abs(VertexX#(surf,v3)-PickedX#())
  21. Dist3Y#=Abs(VertexY#(surf,v3)-PickedY#())
  22. Dist3Z#=Abs(VertexZ#(surf,v3)-PickedZ#())
  23. Dist3#=Dist3X#+Dist3Y#+Dist3Z#
  24.  
  25. If Dist1#<Dist2# And Dist1#<Dist3# Then Return v1
  26. If Dist2#<Dist1# And Dist2#<Dist3# Then Return v2
  27. If Dist3#<Dist2# And Dist3#<Dist1# Then Return v3
  28. Return v1
  29.  
  30. End Function


Comments :


big10p(Posted 1+ years ago)

 <div class="quote"> I havent tested it much yet, so probertly some bugs </div>Indeed there are. :)Also not tested, but you may have better luck with this:
Code: [Select]
Function PickedVertex()

mesh = PickedEntity()
surf = PickedSurface()
tri = PickedTriangle()

px# = PickedX()
py# = PickedY()
pz# = PickedZ()

v0 = TriangleVertex(surf,tri,0)
v1 = TriangleVertex(surf,tri,1)
v2 = TriangleVertex(surf,tri,2)

TFormPoint VertexX(surf,v0),VertexY(surf,v0),VertexZ(surf,v0),mesh,0
dx# = TFormedX - px
dy# = TFormedY - py
dz# = TFormedZ - pz
v0d# = dx*dx + dy*dy + dz*dz

TFormPoint VertexX(surf,v1),VertexY(surf,v1),VertexZ(surf,v1),mesh,0
dx# = TFormedX - px
dy# = TFormedY - py
dz# = TFormedZ - pz
v1d# = dx*dx + dy*dy + dz*dz

TFormPoint VertexX(surf,v2),VertexY(surf,v2),VertexZ(surf,v2),mesh,0
dx# = TFormedX - px
dy# = TFormedY - py
dz# = TFormedZ - pz
v2d# = dx*dx + dy*dy + dz*dz

If (v0d < v1d) And (v0d < v2d) Then Return v0
If (v1d < v0d) And (v1d < v2d) Then Return v1

Return v2

End Function



KimoTech(Posted 1+ years ago)

 thanks! but thats only my first code post.. :) just for try. Heh. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal