Create a vertex

Blitz3D Forums/Blitz3D Beginners Area/Create a vertex

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Probably not perfect for all segment levels but works with the default of 8 ...

Stevie

Graphics3D 640,480,16,1

light = CreateLight() : RotateEntity light, 30,-45,0
camera = CreateCamera() : PositionEntity camera, 0,0,-3

ss = SEMI_SPHERE() : EntityFX ss, 4

While Not KeyDown(1)

	TurnEntity ss, 1,0,-1
	RenderWorld()
	
	Flip

Wend

End

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

Function SEMI_SPHERE()

	temp = CreateSphere()
	ts = GetSurface( temp, 1 )

	mesh = CreateMesh()
	s = CreateSurface( mesh )
	
	For t = 0 To CountTriangles( ts ) - 1
	
		v0 = TriangleVertex( ts, t , 0 )
		v1 = TriangleVertex( ts, t , 1 )
		v2 = TriangleVertex( ts, t , 2 )
		 
		If VertexY( ts, v0 ) > 0 Or VertexY( ts, v1) > 0 Or VertexY( ts, v2 ) > 0
			nv0 = AddVertex( s, VertexX( ts, v0 ) , VertexY( ts, v0 ) , VertexZ( ts, v0 ) )
			nv1 = AddVertex( s, VertexX( ts, v1 ) , VertexY( ts, v1 ) , VertexZ( ts, v1 ) )
			nv2 = AddVertex( s, VertexX( ts, v2 ) , VertexY( ts, v2 ) , VertexZ( ts, v2 ) )
			VertexNormal s, nv0, VertexNX( ts, v0 ) , VertexNY( ts, v0 ), VertexNZ( ts, v0 )
			VertexNormal s, nv1, VertexNX( ts, v1 ) , VertexNY( ts, v1 ), VertexNZ( ts, v1 )
			VertexNormal s, nv2, VertexNX( ts, v2 ) , VertexNY( ts, v2 ), VertexNZ( ts, v2 )
			AddTriangle ( s, nv0, nv1, nv2 )
		EndIf
		
	Next
	
	FreeEntity temp
	
	Return mesh
	
End Function