Is there any tips of using entity.worldRotation?
When I try to print it, it returned nil. When I try to set a value, nothing happened. At the same time, entity.rotation is ok.
Test code:
function setup()
scene = craftSceneInit(false)
viewer = scene.camera:add(OrbitViewer, vec3(0,10,-20),5, 10, 20)
local k = 1
e1 = scene:entity()
e1.scale = e1.scale * k
local m = craft.model(asset.builtin.Blocky_Characters.Man)
e1:add(craft.renderer,m)
print(e1.worldRotation)
e1.worldrotation= axis2quat(30,1,0,0)
print(e1.rotation)
end
function update(dt)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
drawAxis(scene)
end
function axis2quat(a,x,y,z)
local w = math.cos(math.rad(a)/2)
local x = math.sin(math.rad(a)/2)*x
local y = math.sin(math.rad(a)/2)*y
local z = math.sin(math.rad(a)/2)*z
return quat(w,x,y,z)
end
function craftSceneInit(day)
-- Create a new craft scene
local scene = craft.scene()
-- ???????
if day == true then
sunny = readText(asset.builtin.Environments.Sunny)
else
sunny = readText(asset.builtin.Environments.Night)
end
local env = craft.cubeTexture(json.decode(sunny))
scene.sky.material.envMap = env
scene.sky.eulerAngles = vec3(0,180,0)
-- ??????
scene.sun:get(craft.light).intensity = 0.4
scene.sun.position = vec3(0, -10, 0)
scene.sun.rotation = quat.eulerAngles(45,0,45)
scene.ambientColor = color(88, 107, 222, 255)
-- ??????????????
scene.camera.eulerAngles = vec3(0,0,0)
scene.camera.position = vec3(0,0,0)
return scene
end
function drawAxis(scene,pos,unit)
local l = unit or 1
local pos = pos or vec3(0,0,0)
local o,x,y,z = vec3(0,0,0),vec3(l,0,0),vec3(0,l,0),vec3(0,0,l)
-- ?????
scene.debug:line(o+pos, x+pos, color(255,0,0,255))
scene.debug:line(o+pos, y+pos, color(0,255,0,255))
scene.debug:line(o+pos, z+pos, color(255,255,0,255))
end