|
segments (optional) - sphere detail; 8 (default) parent (optional) - parent entity of sphere |
|
Creates a sphere mesh/entity and returns its handle. The sphere is centred at 0,0,0 and has a radius of 1. Spheres make instant balls, planets, heads and pickups while you block out a game. The segments value must be in the range 2-100 inclusive, although this is only checked in debug mode. Polygon count grows roughly with the square of the segments value, so a common mistake is costly: leave debug mode off and pass the parent parameter (usually an eight digit entity handle) in the place of the segments value, and Blitz tries to build a sphere with an astronomical number of polygons - your program can hang or crash. Keep debug mode on while developing to catch this. Example segments values: 8: 224 polygons - bare minimum amount of polygons for a sphere 16: 960 polygons - smooth looking sphere at medium-high distances 32: 3968 polygons - smooth sphere at close distances The optional parent parameter allows you to specify a parent entity for the sphere, so that when the parent moves the sphere moves with it. The relationship is one way: applying movement commands to the child will not affect the parent. Specifying a parent will still result in the sphere being created at position 0,0,0 rather than at the parent entity's position. See also: CreateCube, CreateCylinder, CreateCone, CreatePivot, CreateCapsule, CreateTorus. |
; CreateSphere Example
; --------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,1,-5
light=CreateLight()
RotateEntity light,45,45,0
segments=8
; Create the sphere
sphere=CreateSphere(segments)
PositionEntity sphere,0,1,0
EntityColor sphere,255,150,50
spin=0
While Not KeyDown(1)
old=segments
; [ / ] choose fewer or more segments
If KeyHit(26) And segments>2 Then segments=segments-1
If KeyHit(27) And segments<32 Then segments=segments+1
; Rebuild the sphere when the segment count changes
If segments<>old
FreeEntity sphere
sphere=CreateSphere(segments)
PositionEntity sphere,0,1,0
EntityColor sphere,255,150,50
EndIf
spin=spin+1
RotateEntity sphere,0,spin,0
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"[ / ] : segments Arrow keys: move camera Esc: exit"
Text 0,20,"CreateSphere("+segments+")"
Flip
Wend
End