GeoSphere

Blitz3D Forums/Blitz3D Programming/GeoSphere

xmlspy(Posted 2004) [#1]
Can someone create me a GeoSphere? or a Geosphere function? thanks.


Stevie G(Posted 2004) [#2]
Like this ....

Graphics3D 800,600

Dim Geo ( 3 )
Global Camera=CreateCamera()
Global Light=CreateLight()

WireFrame True

Demo()

End

;======================================
;======================================
;======================================

Function Demo()

	PositionEntity Camera,0,0,-5
	RotateEntity Light, 30, -60,0

	For l= 0 To 3
		Geo( l ) = GEOcreate ( 0, l+1 )
		r = 100+84*(l=1)+42*(l=3)
		g = 100+84*(l=2)+42*(l=3)
		b = 100+84*(l=0)
		EntityColor Geo( l ), r, g, b
		;EntityFX Geo( l ), 4
		UpdateNormals Geo( l )
		EntityShininess Geo( l ) , 1
		PositionEntity Geo( l ), 2.0 * Cos( l * 90 +45 ) , 2.0 * Sin( l * 90 +45 ) , 0
		If l = 3
			For p = 0 To 50
				Extrude ( Geo ( 3 ), Rnd( 0,1 ) )
			Next
		EndIf
		
	Next

	While Not KeyDown(1)
	
		For l= 0 To 3
			TurnEntity Geo( l ), .2 , -.125, .1
		Next
			
		RenderWorld()
		Flip

	Wend
	
End Function

;======================================
;======================================
;======================================

Function GEOcreate( Parent , Detail )

	Mesh = CreateMesh( Parent )
	S = CreateSurface( Mesh )
	a#=2.0/(1.0+Sqr(5.0))					
	b#=1.0/Sqr((3.0+Sqr(5.0)) / (1.0+Sqr(5.0)))
	v01=AddVertex(S,  0,  a,  b)
	v02=AddVertex(S,  0,  a, -b)
	v03=AddVertex(S,  0, -a,  b)
	v04=AddVertex(S,  0, -a, -b)
	v05=AddVertex(S,  a,  b,  0)
	v06=AddVertex(S,  a, -b,  0)
	v07=AddVertex(S, -a,  b,  0)
	v08=AddVertex(S, -a, -b,  0)
	v09=AddVertex(S,  b,  0,  a)
	v10=AddVertex(S,  b,  0, -a)
	v11=AddVertex(S, -b,  0,  a)
	v12=AddVertex(S, -b,  0, -a)
	GEOsub( S, v02,v05,v07,Detail )
	GEOsub( S, v01,v07,v05,Detail )
	GEOsub( S, v01,v03,v11,Detail )
	GEOsub( S, v01,v09,v03,Detail )
	GEOsub( S, v02,v04,v10,Detail )
	GEOsub( S, v02,v12,v04,Detail )
	GEOsub( S, v03,v06,v08,Detail )
	GEOsub( S, v04,v08,v06,Detail )
	GEOsub( S, v07,v11,v12,Detail )
	GEOsub( S, v08,v12,v11,Detail )
	GEOsub( S, v05,v10,v09,Detail )
	GEOsub( S, v06,v09,v10,Detail )
	GEOsub( S, v01,v11,v07,Detail )
	GEOsub( S, v01,v05,v09,Detail )
	GEOsub( S, v02,v07,v12,Detail )
	GEOsub( S, v02,v10,v05,Detail )
	GEOsub( S, v04,v12,v08,Detail )
	GEOsub( S, v04,v06,v10,Detail )
	GEOsub( S, v03,v08,v11,Detail )
	GEOsub( S, v03,v09,v06,Detail )

	Return mesh

End Function

;======================================
;======================================
;======================================

Function GEOsub( S, v1 , v2 , v3 , Detail )
	
	If Detail > 0 
		nx#=(VertexX(S,v1)+VertexX(S,v2))/2
		ny#=(VertexY(S,v1)+VertexY(S,v2))/2
		nz#=(VertexZ(S,v1)+VertexZ(S,v2))/2
		l#=Sqr(nx*nx+ny*ny+nz*nz)
		n1=AddVertex(S,nx/l,ny/l,nz/l)
		nx#=(VertexX(S,v2)+VertexX(S,v3))/2
		ny#=(VertexY(S,v2)+VertexY(S,v3))/2
		nz#=(VertexZ(S,v2)+VertexZ(S,v3))/2
		l#=Sqr(nx*nx+ny*ny+nz*nz)
		n2=AddVertex(S,nx/l,ny/l,nz/l)
		nx#=(VertexX(S,v3)+VertexX(S,v1))/2
		ny#=(VertexY(S,v3)+VertexY(S,v1))/2
		nz#=(VertexZ(S,v3)+VertexZ(S,v1))/2
		l#=Sqr(nx*nx+ny*ny+nz*nz)
		n3=AddVertex(S,nx/l,ny/l,nz/l)
		GEOsub( S, v1,n3,n1,Detail-1)
		GEOsub( S, v2,n1,n2,Detail-1)
		GEOsub( S, v3,n2,n3,Detail-1)
		GEOsub( S, n3,n2,n1,Detail-1)
	Else
		AddTriangle(S,v1,v2,v3)
	End If

End Function

;======================================
;======================================
;======================================

Function Extrude ( Mesh, Radius# )

	pivot = CreatePivot( Mesh )
	PositionEntity pivot,0,-1,0
	RotateEntity pivot, Rand( -90, 90 ), Rand(-180,180),0
	
	temp = CreatePivot()
	
	S = GetSurface( Mesh, 1 )
	CV = CountVertices ( S ) - 1
	For V = 0 To CV
		Vx# = VertexX( S, V )
		Vy# = VertexY( S, V )
		Vz# = VertexZ( S, V )
		PositionEntity temp, Vx, Vy, Vz
		Distance# = EntityDistance ( temp, pivot ) 
		If Distance < Radius
			E# = Cos( Distance / Radius * 90) * .005 
			Nx# = Vx - VertexNX ( S, V ) * E
			Ny# = Vy - VertexNY ( S, V ) * E
			Nz# = Vz - VertexNZ ( S, V ) * E
			VertexCoords S, V, Nx, Ny, Nz
			VertexColor S, V, 128,128,128
		EndIf
	Next  

	FreeEntity pivot
	FreeEntity temp	

End Function






xmlspy(Posted 2004) [#3]
Exactly like that, awesome!


Stevie G(Posted 2004) [#4]
No worries mate ;)


puki(Posted 2004) [#5]
Oh yes - that is really, really good. This what I am training myself for.

Edit:
However, I'd rather you could see the opposite rear surface throught the front of the mesh.


Damien Sturdy(Posted 2004) [#6]
what tghe heck is that? lol.. il go play now.


xmlspy(Posted 2004) [#7]
How do you texture a geosphere correctly? Spheres are no problem.