Here's a little update, this time you use the up and down keys to control the lathe speed, and the lathe actually cuts into the mesh now, so you can make more complex models like this:
`Lathe tech demo by Andrew Vanbeck 8-Jul-09
set display mode desktop width(),desktop height(),32
global blocktype blockwidth# blocklength#
global lathe_x# lathe_z# lathe_y# lathe_feedback#
global lang# langspd#
cls
set camera range 0.01,100.0
print "Enter settings for block, or press return for defaults"
input "Press 1 for a round block, or 2 for a square block:",blocktype
if blocktype<>2 then blocktype=1
input "Enter Width/Diameter of block:",blockwidth#
if blockwidth#=0 then blockwidth#=1.0
input "Enter Length of block:",blocklength#
if blocklength#=0 then blocklength#=2.0
sync on
sync rate 50
autocam off
load image "woodgrain.png",1,1
`Load relevant block object
if blocktype=1 then load object "round_block.x",1 else load object "square_block.x",1
`Now scale to desired size - original sizes are 2x2x2 units
scale object 1,blockwidth#*50.0,blockwidth#*50.0,blocklength#*50.0
rotate object 1,0,90,0 : fix object pivot 1
make mesh from object 1,1
delete object 1
make object 1,1,1
set object smoothing 1,80
set normalization on
`Now make the lathe blade object
make object cone 2,0.2 : scale object 2,50,100,50 : rotate object 2,90,0,0 : set object cull 2,0
`And a dummy object, to avoid scary math!
make object cube 3,0.1 : hide object 3
lathe_x#=0.0
lathe_z#=blockwidth#*2.0
zoom#=blockwidth#*-4.0
langspd#=1.0
`Main loop
do
text 0,0,"LEFT-CLICK to move lathe blade, RIGHT-CLICK to view model, MOUSE WHEEL to zoom"
text 0,20,"UP and DOWN cursor keys to adjust lathe speed."
inc zoom#,mousemovez()/500.0
inc langspd#,(downkey()-upkey())/10.0
if langspd#<-14.0 then langspd#=-14.0
if langspd#>14.0 then langspd#=14.0
lang#=wrapvalue(lang#+langspd#)
rotate object 1,lang#,0,0
position object 2,lathe_x#,0,0.0-lathe_z#-0.1
position camera lathe_x#,0,0
rotate camera 90,0,0
lastmb=mb
mb=mouseclick()
if mb<>0 and lastmb=0 then void=mousemovex()+mousemovey() `Quosh mouse moves if it's the first click
if mb=1
inc lathe_x#,((mousemovex())*0.001)*lathe_feedback#
inc lathe_z#,((mousemovey())*0.001)*lathe_feedback#
if lathe_z#<0.0 then lathe_z#=0.0
lathe(1)
else
if mb=2 then rotate camera mousey(),mousex(),0
endif
if shiftkey()=1
`Auto-SCREW!
inc lathe_x#,0.001
lathe(1)
if lathe_x#>(blocklength#/2.0)
lathe_x#=0.0-(blocklength#/2.0)
lang#=0
endif
endif
move camera zoom#
sync
loop
function lathe(obj)
lathe_feedback#=1.0
lx#=lathe_x#
`Use limb 0 on objects created from a mesh
lock vertexdata for limb obj,0
verts=GET VERTEXDATA VERTEX COUNT()-1
wid#=(blocklength#/50.0)/2.0 `Width of blade, so it catches one row at a time
for v=0 to verts
x#=get vertexdata position x(v)
y#=get vertexdata position y(v)
z#=get vertexdata position z(v)
`Vertex is in line with blade?
if x#>(lx#-wid#) and x#<(lx#+wid#)
`Work out the distance from centre
d#=dist#(0,0,z#,y#)
`Work out X angle
xang#=wrapvalue(atanfull(z#,y#)+lang#+90.0)
if d#>lathe_z# and xang#<30.0
`Work out new ZY position
lathe_feedback#=lathe_feedback#/1.5
mul#=(lathe_z#/d#)
if mul#<0 then mul#=0
z#=z#*mul#
y#=y#*mul#
set vertexdata position v,x#,y#,z#
endif
endif
`UV coord based on ZY position of vertex
set vertexdata uv v,0.5+((z#/blockwidth#)/2.1),0.5+((y#/blockwidth#)/2.1)
next v
unlock vertexdata
endfunction
function dist#(xa#,za#,xb#,zb#)
x#=xa#-xb#
z#=za#-zb#
dist#=sqrt(abs(x#*x#)+abs(z#*z#))
endfunction dist#
function tdist#(xa#,ya#,za#,xb#,yb#,zb#)
x#=xa#-xb#
y#=ya#-yb#
z#=za#-zb#
tdist#=sqrt(abs(x#*x#)+abs(y#*y#)+abs(z#*z#))
endfunction tdist#
Edit, forgot to say, press SHIFT to move the lathe along automatically. If you set the lathe to full speed it should make a clean line, but at low speed you can cut screw ridges and make spikes, as the lathe goes in either direction.