Code archives/3D Graphics - Maths/Calc terrain height - Ideal for terrain tool
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
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. | |||||
;GetHeight#( center x of mountain, center z of mountain, vertex/terrain-seg x to calc, vertex/terrain-seg z to calc, mountain radius ) Function GetHeight#(cx#,cz#,px#,pz#,r#) If PointDistance#(cx#,0,cz#,px#,0,pz#)<r# Then Return -Cos#(( PointDistance#(cx#,0,cz#,px#,0,pz#) / r#)*180)-1 End Function Function PointDistance#(X1#,Y1#,Z1#,X2#,Y2#,Z2#) dx# = X1 - X2:dy# = Y1 - Y2:dz# = Z1 - Z2 Return Sqr(dx*dx + dy*dy + dz*dz) End Function ;Example: Graphics 800,600 Repeat Cls For z=0 To 600 Plot z,GetHeight(200,0,z,0,300)*MouseZ()+400 Next Flip Until KeyHit(1) End |
Comments
None.
Code Archives Forum