November 25, 2020, 08:25:50 AM

Author Topic: [bb] Calc terrain height - Ideal for terrain tool by KimoTech [ 1+ years ago ]  (Read 748 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Calc terrain height - Ideal for terrain tool
Author : KimoTech
Posted : 1+ years ago

Description : Uses Cos#() to calc the vertex/terrain height for ex. a mountain. Ideal if u want to make a terrain tool for modifying the terrain with smooth mountains.

Code :
Code: BlitzBasic
  1. ;GetHeight#( center x of mountain, center z of mountain, vertex/terrain-seg x to calc, vertex/terrain-seg z to calc, mountain radius )
  2.  
  3. Function GetHeight#(cx#,cz#,px#,pz#,r#)
  4. If PointDistance#(cx#,0,cz#,px#,0,pz#)<r# Then Return -Cos#(( PointDistance#(cx#,0,cz#,px#,0,pz#) / r#)*180)-1
  5. End Function
  6.  
  7. Function PointDistance#(X1#,Y1#,Z1#,X2#,Y2#,Z2#)
  8. dx# = X1 - X2:dy# = Y1 - Y2:dz# = Z1 - Z2
  9. Return Sqr(dx*dx + dy*dy + dz*dz)
  10. End Function
  11.  
  12.  
  13. ;Example:
  14.  
  15. Graphics 800,600
  16.  
  17. Repeat
  18. Cls
  19. For z=0 To 600
  20. Plot z,GetHeight(200,0,z,0,300)*MouseZ()+400
  21. Next
  22.  
  23. Flip
  24. Until KeyHit(1)
  25. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal