October 28, 2020, 11:05:34 PM

Author Topic: [bb] - Line Helpers - by Jeremy Alessi [ 1+ years ago ]  (Read 1380 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] - Line Helpers - by Jeremy Alessi [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : - Line Helpers -
Author : Jeremy Alessi
Posted : 1+ years ago

Description : These functions can help you in numerous ways and I didn't see them here.  I used to them to interpolate a point at the edge of the screen for an off-screen object.  This way a player character would be pointing at something off screen but the player wouldn't get lost as they'd see a relative symbol at the edge of the screen.  I used it for a 3D implementation in a strange way, but they are general functions that apply across the board.

Code :
Code: BlitzBasic
  1. ;====== RETURNX ==========================================================
  2. ; == Use this to return an x# for any given y# and two other
  3. ; == points on a coordinate plane
  4.  
  5. Function ReturnedX#(y#, X1#, Y1#, X2#, Y2#)
  6.                
  7.         Return ( ( y# - YIntercept( X1#, Y1#, X2#, Y2# ) ) / Slope#( X1#, Y1#, X2#, Y2# ) )
  8.        
  9. End Function
  10.  
  11. ;=========================================================================
  12.  
  13. ;====== RETURNY ==========================================================
  14. ; == Use this to return a y# for any given x# and two other
  15. ; == points on a coordinate plane
  16.  
  17. Function ReturnedY#(x#, X1#, Y1#, X2#, Y2#)
  18.        
  19.         Return ( Slope#( X1#, Y1#, X2#, Y2# ) * x# + YIntercept( X1#, Y1#, X2#, Y2# ) )
  20.        
  21. End Function
  22.  
  23. ;=========================================================================
  24.        
  25. ;====== SLOPE ============================================================
  26.  
  27. Function Slope#(X1#, Y1#, X2#, Y2#)
  28.        
  29.         m# = ( ( Y2# - Y1# ) / ( X2# - X1# ) )
  30.  
  31.         If m#=0
  32.                 Return .001 ;avoid infinity
  33.         Else
  34.                 Return m#
  35.         EndIf
  36.        
  37. End Function
  38.  
  39. ;=========================================================================
  40.  
  41. ;====== YINTERCEPT =======================================================
  42.  
  43. Function YIntercept(X1#, Y1#, X2#, Y2#)
  44.  
  45.         Return ( (-Slope#( X1#, Y1#, X2#, Y2# ) * X1#) + Y1#)
  46.        
  47. End Function
  48.  
  49. ;=========================================================================


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal