cubemap.script 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. local ZOOM_SPEED = 0.1
  2. local ROTATION_SPEED = 1
  3. function init(self)
  4. msg.post("@render:", "use_camera_projection")
  5. msg.post(".", "acquire_input_focus")
  6. self.yaw = 0 -- for camera rotation
  7. self.pitch = 0 -- for camera rotation
  8. self.zoom = 5 -- default zoom
  9. self.zoom_offset = 0 -- modification from default zoom
  10. end
  11. function update(self, dt)
  12. local camera_yaw = vmath.quat_rotation_y(math.rad(self.yaw))
  13. local camera_pitch = vmath.quat_rotation_x(math.rad(self.pitch))
  14. local camera_rot = camera_yaw * camera_pitch
  15. local camera_position = vmath.rotate(camera_rot, vmath.vector3(0, 0, self.zoom + self.zoom_offset))
  16. go.set_position(camera_position)
  17. go.set_rotation(camera_rot)
  18. local cameraposv4 = vmath.vector4(camera_position.x, camera_position.y, camera_position.z, 1)
  19. go.set("logo#model", "cameraPosition", cameraposv4)
  20. end
  21. function on_input(self, action_id, action)
  22. if action_id == hash("touch") then
  23. self.yaw = self.yaw - action.dx * ROTATION_SPEED
  24. self.pitch = self.pitch + action.dy * ROTATION_SPEED
  25. elseif action_id == hash("mouse_wheel_up") then
  26. self.zoom_offset = self.zoom_offset - ZOOM_SPEED
  27. elseif action_id == hash("mouse_wheel_down") then
  28. self.zoom_offset = self.zoom_offset + ZOOM_SPEED
  29. end
  30. end