Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. local dir_to_npc = npc:position():sub(db.actor:position())
  2. local actor_dir = device().cam_dir
  3. --dir_to_npc.y = 0
  4. --actor_dir.y = 0
  5. --local angle = ((dir_to_npc.x * actor_dir.x) + (dir_to_npc.z * actor_dir.z)) / (math.sqrt(dir_to_npc.x^2 + dir_to_npc.z^2) * math.sqrt(actor_dir.x^2 + actor_dir.z^2))
  6. --angle = (math.acos(angle) * 180) / math.pi
  7.  
  8. local angleX = tools.get_horizontal_angle(dir_to_npc, actor_dir)
  9. local angleY = tools.get_vertical_angle(dir_to_npc, actor_dir)--tools.get_horizontal_angle(dir_to_npc, actor_dir)
  10.  
  11.  
  12.  
  13. local img_name = "hud_indicator"
  14. local hud = get_hud()
  15. local custom_static = hud:GetCustomStatic(img_name)
  16.  
  17. local centre_x = 512
  18. local centre_y = 384
  19. local modif = 50 -- more or less both max X camera angle and Y camera angle, determined through observation
  20. angleX = math.max(-modif, angleX)
  21. angleY = math.max(-modif, angleY)
  22. angleX = math.min(modif, angleX)
  23. angleY = math.min(modif, angleY)
  24. angleX = angleX + modif
  25. angleY = angleY + modif
  26. local x_max = 1024
  27. local y_max = 768
  28. local current_x_position = (x_max/(2*modif) * angleX) - 16 --the indicator is 32x32
  29. current_x_position = math.max(0, current_x_position)
  30. current_x_position = math.min(x_max-32, current_x_position)
  31. local current_y_position = (y_max - (y_max/(2*modif) * angleY)) - 16 --the indicator is 32x32
  32. current_y_position = math.max(0, current_y_position)
  33. current_y_position = math.min(y_max-32, current_y_position)
  34. --current_y_position = y_max - current_y_position
  35.  
  36. --error_log("Height = "..tostring(device().height))
  37. --error_log("Width = "..tostring(device().width))
  38. --error_log("Top = "..tostring(tools.get_vertical_angle(device().cam_top, actor_dir)))
  39. --error_log("Right = "..tostring(tools.get_horizontal_angle(device().cam_right, actor_dir)))
  40.  
  41. --error_log(string.format("%s, %s, %s", tostring(device().cam_top.x), tostring(device().cam_top.y), tostring(device().cam_top.z)))
  42.  
  43. if custom_static == nil then
  44. hud:AddCustomStatic(img_name)
  45. custom_static = hud:GetCustomStatic(img_name)
  46.  
  47. end
  48. if custom_static then
  49. custom_static:wnd():SetWndPos(vector2():set(current_x_position,current_y_position))
  50. end
Add Comment
Please, Sign In to add comment