|
spline - spline handle x# - x coordinate of the point y# - y coordinate of the point z# - z coordinate of the point roll# (optional) - banking of the cross-section at this point, in degrees; 0 (default) scale# (optional) - size of the cross-section at this point, greater than 0; 1 (default) corner (optional) - True makes a sharp, mitred corner at this point; False (default) |
|
Adds a point to the end of a spline and returns its index. The path runs through the points in the order you add them. The first point is index 0, and each call returns the index of the point it added. Call it as a statement when you do not need the index. roll# banks the cross-section of meshes made along the path, in the same sense as RotateEntity's roll for an entity facing along the path. It is blended smoothly between points, so a road banks into a bend and out again. scale# widens or narrows the cross-section, also blended between points: taper a branch towards its tip, or widen a road at a junction. corner True turns the path sharply at the point instead of curving through it. Meshes made along it are mitred there, so a square duct, a skirting board or a kerb keeps its thickness and has crisp edges round the corner. A corner that turns by more than 120 degrees would need a long spike, so its joint is cut flat instead. The coordinates and roll must be finite numbers and the scale greater than 0; anything else stops the program with a runtime error. A new point changes what you build from the spline next; meshes already made keep their shape. See also: CreateSpline, SplineUpright, CreateRibbon, PositionOnSpline, SplineDetail. |
; AddSplinePoint Example
; ----------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,4,-7
RotateEntity camera,30,0,0
light=CreateLight()
RotateEntity light,45,45,0
; A little car that drives along the road, leaning with it
car=CreateBox(0.4,0.2,0.6)
EntityColor car,230,60,50
; Roll in 15 degree steps, scale in quarters
roll_steps=-2
scale_steps=6
corner=False
rebuild=True
distance#=0
While Not KeyDown(1)
; [ / ] bank the middle point, - / + widen it, C makes it a sharp corner
If KeyHit(26) And roll_steps>-4 Then
roll_steps=roll_steps-1
rebuild=True
EndIf
If KeyHit(27) And roll_steps<4 Then
roll_steps=roll_steps+1
rebuild=True
EndIf
If KeyHit(12) And scale_steps>2 Then
scale_steps=scale_steps-1
rebuild=True
EndIf
If KeyHit(13) And scale_steps<8 Then
scale_steps=scale_steps+1
rebuild=True
EndIf
If KeyHit(46) Then
corner=Not corner
rebuild=True
EndIf
If rebuild Then
If route Then
FreeEntity road
FreeSpline route
EndIf
roll#=roll_steps*15
scale#=scale_steps*0.25
; A road through five points; only the middle one is banked and widened
route=CreateSpline()
AddSplinePoint route,-4,0,-1
AddSplinePoint route,-2,0,1
middle=AddSplinePoint(route,0,0.5,2.5,roll,scale,corner)
AddSplinePoint route,2,0,1
AddSplinePoint route,4,0,-1
road=CreateRibbon(route,1.2,0.15)
EntityColor road,110,110,120
rebuild=False
EndIf
; Drive along the road and start again at the end
distance=distance+0.03
If distance>SplineLength(route) Then distance=0
PositionOnSpline car,route,distance
MoveEntity car,0,0.1,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,"Arrow keys: move camera [ / ] : roll - / + : scale C: corner Esc: exit"
Text 0,20,"middle=AddSplinePoint(route,0,0.5,2.5,"+roll+","+scale+","+corner+")"
Text 0,40,"It returned point index "+middle+"; roll banks the road and scale widens it"
Flip
Wend
End