Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Who know how to use entity.worldRotation in craft? It returns nil

edited April 28 in Questions Posts: 113

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

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,364

    @binaryblues it looks like a bug in Craft that is missing the binding to expose worldRotation. I have fixed it and it will be available in Codea version 3.2.2

  • Posts: 113

    @Simeon thank you for the rapid response! It will be very helpful for me! :)

Sign In or Register to comment.