Skip to content

Commit 24d12f6

Browse files
committed
Merge branch 'master' of https://github.com/defold/examples
2 parents b299ea9 + 81d4934 commit 24d12f6

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

movement/look_rotation/example/look_rotation.script

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ local function quat_look_rotation(forward, upwards)
1111
return vmath.quat()
1212
end
1313

14+
-- Handle alignment with up direction
15+
if math.abs(vmath.dot(forward, upwards)) > 0.9999999 then
16+
return vmath.quat_from_to(vmath.vector3(0, 0, 1), forward)
17+
end
18+
1419
-- Create a rotation matrix from the forward and upwards vectors
1520
local matrix = vmath.matrix4_look_at(vmath.vector3(0), forward, upwards)
1621

@@ -61,4 +66,4 @@ function on_input(self, action_id, action)
6166
if action_id == hash("mouse_button_left") and action.pressed then
6267
next_target(self)
6368
end
64-
end
69+
end

render/screen_to_world/example/bee.script

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ local function screen_to_world(x, y, z, camera_id)
77
local view = camera.get_view(camera_id)
88
local w, h = window.get_size()
99

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

0 commit comments

Comments
 (0)