|
radius# (optional) - distance from the centre to the middle of the tube; 0.75 (default) tube_radius# (optional) - radius of the tube itself, less than radius#; 0.25 (default) segments (optional) - segments round the ring for a full turn, from 3 to 256; 24 (default) sides (optional) - segments round the tube, from 3 to 128; 12 (default) arc# (optional) - how much of the ring to build, in degrees, more than 0 and up to 360; 360 (default) parent (optional) - parent entity for the new mesh; 0 for none (default) |
|
Creates a ring-shaped torus lying flat, or a capped bend, and returns its handle. The torus lies flat round the Y axis, centred on the origin. radius# reaches the middle of the tube, so the outside edge is radius#+tube_radius# from the centre, and the defaults are 2 units across like the other primitives. Use it for swim rings, tyres, hoops, quoits, rope coils and doughnuts. An arc# under 360 builds only part of the ring and caps both ends: a 90 degree pipe elbow, a half-ring arch or a handle. Angles run from +X towards +Z. Segment counts are for a full turn, and a partial arc uses its share. Surface 1 is the ring itself, and a partial arc adds its end caps as surface 2. U runs round the ring and V round the tube. The torus is a closed solid, so it works with the CSG commands. Automatic EntityPhysics makes a static torus a triangle mesh. A moving one becomes a ring of capsules round the middle of the tube: a close approximation that rolls, keeps its hole open and can be thrown over a post, as in the example. PositionMesh, RotateMesh, ScaleMesh and FitMesh keep this, so a shape you have turned or resized with them keeps its collider. Editing its vertex positions or triangles, AddMesh or FlipMesh makes it an ordinary mesh again, and an explicit EntityPhysics shape, EntityBox, EntityRadius, EntityCapsule or EntityConvex always wins. Arguments are checked in release builds too: a radius that is not a positive number, a tube_radius that is not less than radius, segments outside 3 to 256, sides outside 3 to 128, or an arc that is not more than 0 and up to 360 degrees stops the program with a runtime error naming the argument. See also: CreateTube, CreatePipe, CreateSphere, EntityPhysics, MeshUnion. |
; CreateTorus Example
; -------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; Automatic entity physics runs on the Box3D collision backend
SetCollisionBackend 1
Const SCENERY=1
Const PROPS=2
camera=CreateCamera()
PositionEntity camera,0,3,-7
RotateEntity camera,20,0,0
light=CreateLight()
RotateEntity light,45,-25,0
; A ring-toss stall: a floor and a post to throw rings over
ground=CreateCube()
ScaleEntity ground,4,0.5,4
PositionEntity ground,0,-0.5,0
EntityColor ground,70,110,70
EntityType ground,SCENERY
EntityPhysics ground,0
post=CreateCylinder(16)
ScaleEntity post,0.1,1,0.1
PositionEntity post,0,1,0
EntityColor post,230,230,230
EntityType post,SCENERY
EntityPhysics post,0
; A partial torus makes a capped bend: here a 90 degree pipe elbow
elbow=CreateTorus(0.6,0.15,24,12,90)
PositionEntity elbow,-2.5,0.15,0
EntityColor elbow,160,170,180
Physics PROPS,SCENERY
Physics PROPS,PROPS
SeedRnd MilliSecs()
Dim rings(15)
count=0
; Ring radius in 10 cm steps
radius_steps=5
; The first three drop by themselves, a moment apart
auto_drops=3
next_drop=MilliSecs()
timer=CreateTimer(60)
While Not KeyDown(1)
; [ / ] change the size of the next ring
If KeyHit(26) And radius_steps>3 Then radius_steps=radius_steps-1
If KeyHit(27) And radius_steps<8 Then radius_steps=radius_steps+1
radius#=radius_steps/10.0
; Space throws a ring at the post
If (KeyHit(57) Or (auto_drops>0 And MilliSecs()>next_drop)) And count<15 Then
auto_drops=auto_drops-1
next_drop=MilliSecs()+700
; A swim-ring shape lying flat; radius reaches the middle of the tube
ring=CreateTorus(radius,0.08)
EntityColor ring,Rand(150,255),Rand(60,200),Rand(40,120)
PositionEntity ring,Rnd(-0.3,0.3),4,Rnd(-0.3,0.3)
RotateEntity ring,Rnd(-20,20),Rnd(360),Rnd(-20,20)
EntityType ring,PROPS
; Automatic physics builds a ring of capsules, so the hole stays open
EntityPhysics ring
rings(count)=ring
count=count+1
EndIf
; R collects the rings
If KeyHit(19) Then
For index=0 To count-1
FreeEntity rings(index)
Next
count=0
EndIf
; 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
UpdateWorld
RenderWorld
Text 0,0,"Arrow keys: move camera [ / ] : ring size Space: throw R: collect Esc: exit"
Text 0,20,"ring=CreateTorus("+radius+",0.08) rings: "+count+" of 15"
Text 0,40,"Left: elbow=CreateTorus(0.6,0.15,24,12,90), a capped quarter bend"
Flip
WaitTimer timer
Wend
End