--Rotate wheels on a vehicle

function wheelInit(body)
	wheels = {}
	local shapes = GetBodyShapes(body)
	for i=1,#shapes do
		local st = GetShapeLocalTransform(shapes[i])
		local xs,ys,zs = GetShapeSize(shapes[i])
		if xs <= 10 and ys <= 10 and zs <= 10 and st.pos[2] < 0.2 and math.max(zs, ys) > 0 then
			local wheel = {}
			wheel.shape = shapes[i]
			wheel.center = VecAdd(st.pos, TransformToParentVec(st, Vec(xs*0.05, ys*0.05, zs*0.05)))
			wheel.radius = math.max(zs, ys)*0.05
			wheel.angle = 0
			wheel.localTransform = TransformToLocalTransform(Transform(wheel.center), st)
			wheels[#wheels+1] = wheel
		end
	end	
end


function wheelUpdate(speed)
	for i=1,#wheels do
		local w = wheels[i]
		w.angle = w.angle - speed/w.radius
		local t = Transform(w.center, QuatEuler(w.angle, 0, 0))
		local lt = TransformToParentTransform(t, w.localTransform)
		SetShapeLocalTransform(w.shape, lt)
	end
end

