First of all. I am using the latest Beta. I used this code here to generate a sphere(for a planet), and always scale the surface 100 meters away. With my distance and radius parameter, i control the distance and parameter. This all works when I am decreasing the distance or increasing the radius, but as if i come closer and go further again it stays the same. I am sure I did everything correctly. Here is the code:
function setup()
s = sphere(600000)
parameter.number("d",601000,800000,800000)
parameter.number("r",500000,600000,500000)
end
function draw()
scl = (d-r)/100
perspective(90)
camera(0,d/scl,0,0,0,0,0,0,1)
scale(r/scl)
s:draw()
end
function sphere(radius)
s = mesh()
vertices = {}
for x = -180, 175, 5 do
for y = -90, 85, 5 do
table.insert(vertices,sphereRotate(x,y)*radius/600000)
table.insert(vertices,sphereRotate(x+5,y)*radius/600000)
table.insert(vertices,sphereRotate(x+5,y+5)*radius/600000)
table.insert(vertices,sphereRotate(x,y)*radius/600000)
table.insert(vertices,sphereRotate(x+5,y+5)*radius/600000)
table.insert(vertices,sphereRotate(x,y+5)*radius/600000)
end
end
s.vertices = vertices
s:setColors(color(0,0,255,255))
return s
end
function rotate3D(vec,angle,x,y,z)
x = x or 0
y = y or 0
z = z or 1
local a,s,c = math.rad(angle),math.sin,math.cos
if x == 1 then
return vec3(vec.x,vec.y*c(a)-vec.z*s(a),vec.y*s(a)+vec.z*c(a))
elseif y == 1 then
return vec3(vec.z*c(a)-vec.x*s(a),vec.y,vec.z*c(a)-vec.x*s(a))
elseif z == 1 then
return vec3(vec.x*c(a)-vec.y*s(a),vec.x*s(a)+vec.y*c(a),vec.z)
end
return vec
end
function sphereRotate(x,y)
return rotate3D(rotate3D(vec3(0,1,0),y,1,0,0),x,0,0,1)
end