Преглед на файлове

Merge branch 'master' of https://github.com/defold/examples

Björn Ritzl преди 2 месеца
родител
ревизия
24d12f6893
променени са 2 файла, в които са добавени 9 реда и са изтрити 11 реда
  1. 6 1
      movement/look_rotation/example/look_rotation.script
  2. 3 10
      render/screen_to_world/example/bee.script

+ 6 - 1
movement/look_rotation/example/look_rotation.script

@@ -11,6 +11,11 @@ local function quat_look_rotation(forward, upwards)
 		return vmath.quat()
 	end
 
+	-- Handle alignment with up direction
+	if math.abs(vmath.dot(forward, upwards)) > 0.9999999 then
+		return vmath.quat_from_to(vmath.vector3(0, 0, 1), forward)
+	end
+
 	-- Create a rotation matrix from the forward and upwards vectors
 	local matrix = vmath.matrix4_look_at(vmath.vector3(0), forward, upwards)
 
@@ -61,4 +66,4 @@ function on_input(self, action_id, action)
 	if action_id == hash("mouse_button_left") and action.pressed then
 		next_target(self)
 	end
-end
+end

+ 3 - 10
render/screen_to_world/example/bee.script

@@ -7,13 +7,6 @@ local function screen_to_world(x, y, z, camera_id)
 	local view = camera.get_view(camera_id)
 	local w, h = window.get_size()
 
-	-- The window.get_size() function will return the scaled window size,
-	-- ie taking into account display scaling (Retina screens on macOS for
-	-- instance). We need to adjust for display scaling in our calculation.
-	local scale = window.get_display_scale()
-	w = w / scale
-	h = h / scale
-
 	-- https://defold.com/manuals/camera/#converting-mouse-to-world-coordinates
 	local inv = vmath.inv(projection * view)
 	x = (2 * x / w) - 1
@@ -33,8 +26,8 @@ end
 function on_input(self, action_id, action)
 	if action_id == hash("touch") and action.pressed then
 		-- convert mouse/touch screen position to world position
-		local worldx, worldy = screen_to_world(action.x, action.y, 0, "#camera")
+		local worldx, worldy = screen_to_world(action.screen_x, action.screen_y, 0, "#camera")
 		local world = vmath.vector3(worldx, worldy, 0)
-		go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, world, go.EASING_LINEAR, 0.5, 0, moved_to_position) -- <8>
+		go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, world, go.EASING_LINEAR, 0.5, 0)
 	end
-end
+end