Finally!
` Setup
Sync On : Sync Rate 60
Set Display Mode 1440, 900, 32 : Hide Mouse
Backdrop On : Color Backdrop 0 : Set Ambient Light 30 : Set Directional Light 0, 0, 0, 1
Autocam Off : Set Camera Range 1, 0x7fffffff
Disable Escapekey
` Generate a planet
GenPlanet( 1, 1000, 64, 64, 200, 1.0015 )
make object sphere 2, 1000, 32, 32
color object 2, rgb( 0, 0, 128 )
` Texture
create bitmap 1,128,128 : set current bitmap 1
cls rgb(0,128,0)
for d=1 To 10000
ink rgb(0,rnd(255),rnd(50)),0
dot rnd(128),rnd(128)
next d
blur bitmap 1,4
get image 1,0,0,128,128
set current bitmap 0 : delete bitmap 1
Texture Object 1, 1
` Camera
dist# = 2000
` Main Loop
Repeat
` Control Camera
dist# = dist# - mousemovez()
ax# = wrapvalue( ax# + mousemovey() )
ay# = wrapvalue( ay# + mousemovex() )
cx# = sin( ay# ) * cos( ax# ) * dist#
cy# = -sin( ax# ) * dist#
cz# = cos( ay# ) * cos( ax# ) * dist#
position camera cx#, cy#, cz#
rotate camera ax# + 180, ay#, 0
` Update
Sync
` Exit of escapekey
Until Escapekey()
End
` Generate planet
Function GenPlanet( Obj, Size as Float, Rows, Columns, Itr, Height as Float )
` Make sphere
Make Object Sphere Obj, Size, Rows, Columns
` Normal data
Local RAX as Float
Local RAY as Float
Local NX as Float
Local NY as Float
Local NZ as Float
` Vertex data
Local VX as Float
Local VY as Float
Local VZ as Float
Local NVX as Float
Local NVY as Float
Local NVZ as Float
` Lock vertexes for sphere
Lock Vertexdata For Limb 1, 0
` Loop for all itterations
For i = 1 to Itr
` Select a random normal
RAX = Rnd( 360 )
RAY = Rnd( 360 )
NX = Sin( RAY ) * Cos( RAX )
NY = - Sin( RAX )
NZ = Cos( RAY ) * Cos( RAX )
` Loop through object vertexes
For v = 0 to Get Vertexdata Vertex Count() - 1
` Get vertex position
VX = Get Vertexdata Position X( v )
VY = Get Vertexdata Position Y( v )
VZ = Get Vertexdata Position Z( v )
` If inside random normal's hemisphere..
If ( PointInBox( NX * (Size / 2), NY * (Size / 2), NZ * (Size / 2), RAX, RAY, Size, VX, VY, VZ ) )
` Calculate New Position
NVX = VX * Height
NVY = VY * Height
NVZ = VZ * Height
` Reposition vertex
Set Vertexdata Position v, NVX, NVY, NVZ
Endif
` If inside opposite random normal's hemisphere..
If ( PointInBox( -NX * (Size / 2), -NY * (Size / 2), -NZ * (Size / 2), RAX + 180, RAY, Size, VX, VY, VZ ) )
` Calculate New Position
NVX = VX * (1 / Height)
NVY = VY * (1 / Height)
NVZ = VZ * (1 / Height)
` Reposition vertex
Set Vertexdata Position v, NVX, NVY, NVZ
Endif
Next v
Next i
` Unlock vertextdata
Unlock Vertexdata
EndFunction
` Check if inside box
Function PointInBox( PosX as Float, PosY as Float, PosZ as Float, AngX as Float, AngY as Float, Size as Float, PtX as Float, PtY as Float, PtZ as Float )
` In box
Local In as Boolean
` Get Distance and angle between point and center of box
Local Dist as Float
Local PAngX as Float
Local PAngY as Float
Dist = Sqrt( (PtX - PosX) ^ 2 + (PtY - PosY) ^ 2 + (PtZ - PosZ) ^ 2 )
PAngX = Atanfull( PtY - PosY, PtZ - PosZ )
PAngY = Atanfull( PtX - PosX, PtZ - PosZ )
` New assumed positions
Local NX as Float
Local NY as Float
Local NZ as Float
NX = PosX + ( Sin( PAngY - AngY ) * Cos( PAngX - AngX ) * Dist )
NY = PosY - ( Sin( PAngX - AngX ) * Dist )
NZ = PosZ + ( Cos( PAngY - AngY ) * Cos( PAngX - AngX ) * Dist )
` Check if new positions are inside unrotated box
If ( (NX >= PosX - (Size / 2)) && (NX <= PosX + (Size / 2)) )
If ( (NY >= PosY - (Size / 2)) && (NY <= PosY + (Size / 2)) )
If ( (NZ >= PosZ - (Size / 2)) && (NZ <= PosZ + (Size / 2)) )
In = 1
Endif
Endif
Endif
EndFunction In
Mouse to move the camera. Mousewheel to zoom.
[Edit]
Screenie:
"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers