./vdo_triangle_select.lua

  1.  
  2. local SIN_60 = 0.866 
  3. local CENTER_TO_CORNER = 0.58 
  4.  
  5. --Math Functions for Triangle Select 
  6. local function cap(val, min_val, max_val) 
  7. 	if val < min_val then 
  8. 		return min_val 
  9. 	elseif val > max_val then 
  10. 		return max_val 
  11. 	end 
  12. 	 
  13. 	return val 
  14. end 
  15.  
  16. -- calculate the magnitude of a line 
  17. local function magnitude(startx,starty,endx,endy) 
  18.  
  19. 	local x = endx - startx 
  20. 	local y = endy - starty 
  21.  
  22.     return sqrt( x * x + y * y ) 
  23. end 
  24.  
  25. -- Inherited from Vdo_base_object 
  26. Vdo_triangle_select = Vdo_base_object:new_base() 
  27.  
  28. local TRIANGLE_NW_X = 32 
  29. local TRIANGLE_NW_Y = 32 
  30. local TRIANGLE_SIDE = 235 
  31.  
  32. local Min_x = 0 
  33. local Min_y = 0 
  34. local Max_x = TRIANGLE_SIDE 
  35.  
  36. -- height of triangle 
  37. local Max_y = TRIANGLE_SIDE * SIN_60 
  38.  
  39. local Fat_txt 
  40. local Skinny_txt 
  41. local Strength_txt 
  42.  
  43. local Cursor 
  44.  
  45.  
  46. local function update_percent_fields(fat, skinny, strength) 
  47. 	-- update % displays	 
  48. 	local body 
  49. 	local insert_values = { [0] = fat } 
  50. 	body = vint_insert_values_in_string("STORE_FAT", insert_values) 
  51. 	Fat_txt:set_text(body) 
  52. 	 
  53. 	insert_values = { [0] = skinny } 
  54. 	body = vint_insert_values_in_string("STORE_SKINNY", insert_values) 
  55. 	Skinny_txt:set_text(body) 
  56. 	 
  57. 	insert_values = { [0] = strength } 
  58. 	body = vint_insert_values_in_string("STORE_STRENGTH", insert_values) 
  59. 	Strength_txt:set_text(body)	 
  60. end 
  61.  
  62. function Vdo_triangle_select:init() 
  63.  
  64. 	self.btn_select = Vdo_button_toggle:new("btn_select", self.handle, self.doc_handle) 
  65. 	self.btn_highlight = Vdo_button_highlight:new("btn_highlight", self.handle, self.doc_handle) 
  66. 	 
  67. 	self.btn_highlight:show_button(CTRL_MENU_BUTTON_A) 
  68. 	 
  69. 	self.btn_select:set_label("STORE_SELECT_BUILD") 
  70. 	 
  71. 	self.tri_color_grp = Vdo_base_object:new("tri_color_grp", self.handle, self.doc_handle) 
  72. 	self.tri_color_grp:set_visible(false) 
  73. 	 
  74. 	self.btn_select:set_highlight(true) 
  75. 	self.btn_highlight:set_highlight(true) 
  76.  
  77. 	self.pulse_anim = Vdo_anim_object:new("stick_pulse_anim", self.handle, self.doc_handle) 
  78. 	self.pulse_anim:unpause() 
  79. 	 
  80. 	-- Temp: bitmap doesn't line up with triangle edges 
  81. 	-- TRIANGLE_NW_X, TRIANGLE_NW_Y = triangle_h:get_anchor() 
  82. 	 
  83. 	--Get Cursor Handle 
  84. 	Cursor = Vdo_base_object:new("cursor", self.handle, self.doc_handle) 
  85. 	 
  86. 	local triangle_bmp = Vdo_base_object:new("triangle_base", self.handle, self.doc_handle) 
  87. 	triangle_bmp:set_image("ui_menu_pcr_tri") 
  88. 	 
  89. 	--Modify Stick Graphic depending on system 
  90. 	local cursor_bmp = Vdo_base_object:new("stick_bitmap",  Cursor.handle, Cursor.doc_handle) 
  91. 	local cursor_txt = Vdo_base_object:new("stick_text",  Cursor.handle, Cursor.doc_handle) 
  92. 	self.glow_bmp = Vdo_base_object:new("glow",  Cursor.handle, Cursor.doc_handle) 
  93. 	 
  94. 	local platform = game_get_platform() 
  95. 	if platform == "PS3" then  
  96. 		cursor_bmp:set_image("ui_hud_combo_thumb_ps3")  
  97. 		cursor_txt:set_text("L") 
  98. 	elseif platform == "PS4" then	-- HVS_JRP[PRINCE] 3/18/2014 
  99. 		cursor_bmp:set_image("ui_hud_combo_thumb_ps4") 
  100. 		cursor_txt:set_text("L") 
  101. 	elseif (platform == "PC") then  
  102. 		cursor_bmp:set_image("ui_pc_body_select_circle")  
  103. 		cursor_txt:set_visible(false) 
  104. 	elseif platform == "XBOX3" then	-- HVS_JRP[PRINCE] 3/18/2014 
  105. 		cursor_bmp:set_image("ui_hud_radial_stick_thumb_xbox3") -- HVS_DMK 
  106. 		cursor_txt:set_text("LS") 
  107. 	else 
  108. 		cursor_bmp:set_image("ui_hud_combo_thumb") 
  109. 		cursor_txt:set_text("LS") 
  110. 	end 
  111. 	 
  112. 	--Uncomment these for more accurate cursor 
  113. 	--cursor_bmp:set_visible(false) 
  114. 	--cursor_txt:set_visible(false) 
  115. 	--self.glow_bmp:set_visible(false) 
  116. 	 
  117. 	-- start in the middle of the triangle - need to update based on current settings 
  118. 	Cursor:set_anchor(TRIANGLE_NW_X + Max_x / 2, TRIANGLE_NW_Y + TRIANGLE_SIDE * CENTER_TO_CORNER) 
  119. 	 
  120. 	Fat_txt = Vdo_base_object:new("fat_txt", self.handle, self.doc_handle) 
  121. 	Skinny_txt = Vdo_base_object:new("skinny_txt", self.handle, self.doc_handle) 
  122. 	Strength_txt = Vdo_base_object:new("strength_txt", self.handle, self.doc_handle) 
  123. 	 
  124. 	update_percent_fields(0, 0, 0) 
  125. end 
  126.  
  127. function	Vdo_triangle_select:init_morphs(str, skin, fat, x, y) 
  128.  
  129. 	-- leave cursor in middle for never initialized position 
  130. 	if x >= 0 and y >= 0 then 
  131. 		Cursor:set_anchor(x,y) 
  132. 	else 
  133. 		Cursor:set_anchor(TRIANGLE_NW_X + Max_x / 2, TRIANGLE_NW_Y + TRIANGLE_SIDE * CENTER_TO_CORNER) 
  134. 	end 
  135.  
  136. 	-- update % displays	 
  137. 	update_percent_fields(floor(fat * 100 + 0.5), floor(skin * 100 + 0.5), floor(str * 100 + 0.5))	 
  138. end 
  139.  
  140. -- Move the left stick by the given magnitudes 
  141. function Vdo_triangle_select:move_left_stick(mag_x, mag_y) 
  142.  
  143. 	local cursor_x, cursor_y = Cursor:get_anchor() 
  144. 	 
  145. 	local new_x = cursor_x + mag_x 
  146. 	local new_y = cursor_y - mag_y	 
  147. 	 
  148. 	-- convert from screen position  
  149. 	local rel_x = new_x - TRIANGLE_NW_X 
  150. 	local rel_y = new_y - TRIANGLE_NW_Y 
  151. 	 
  152. 	local ax = 0 
  153. 	local ay = Max_y 
  154. 	local bx = (Max_x / 2) 
  155. 	local by = 0 
  156. 	local cx = Max_x 
  157. 	local cy = ay 
  158. 	 
  159. 	-- Check the location of the mouse cursor against each side of the triangle 
  160. 	-- If the point is "inside," it is to the right or on the line 
  161. 	local point_inside_left = false 
  162. 	local point_inside_right = false 
  163. 	local point_inside_bottom = false 
  164. 	if which_side_of_2d_line(rel_x, rel_y, ax, ay, bx, by) >= 0 then 
  165. 		point_inside_left = true 
  166. 	end 
  167. 	 
  168. 	if which_side_of_2d_line(rel_x, rel_y, bx, by, cx, cy) >= 0 then 
  169. 		point_inside_right = true 
  170. 	end 
  171. 	 
  172. 	if which_side_of_2d_line(rel_x, rel_y, cx, cy, ax, ay) >= 0 then 
  173. 		point_inside_bottom = true 
  174. 	end 
  175. 	 
  176. 	local new_x, new_y 
  177. 	--local rel_x, rel_y 
  178. 	if point_inside_left and point_inside_right and point_inside_bottom then 
  179. 		-- If the point is inside the triangle, then done 
  180. 	else 
  181. 		-- If the point is not on the inside of the triangle, find the closest point on the 
  182. 		-- line that the point is not on the inside of. 
  183. 		 
  184. 		if not point_inside_left then 
  185. 			rel_x, rel_y= closest_point_on_line_segment(rel_x, rel_y, ax, ay, bx, by) 
  186. 		end 
  187. 		 
  188. 		if not point_inside_right then 
  189. 			rel_x, rel_y = closest_point_on_line_segment(rel_x, rel_y, bx, by, cx, cy) 
  190. 		end 
  191. 		 
  192. 		if not point_inside_bottom then 
  193. 			rel_x, rel_y = closest_point_on_line_segment(rel_x, rel_y, cx, cy, ax, ay) 
  194. 		end 
  195. 	end	 
  196. 	 
  197. 	-- convert from screen coord (top is lower y value) to Cartesian for my sanity 
  198. 	rel_y = Max_y - rel_y 
  199. 	 
  200. 	-- Get percentages for display, and to update the morph. 
  201. 	 
  202. 	local center_x = 117.5 
  203. 	local center_y = 67.84 
  204. 	 
  205. 	local d_left_corner = magnitude(0, 0, rel_x, rel_y) 
  206. 	local d_right_corner = magnitude(rel_x, rel_y, Max_x, 0) 
  207. 	local d_top_corner = magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  208. 	 
  209. 	local d_bottom = d_left_corner + d_right_corner 
  210. 	local d_left = d_left_corner + d_top_corner 
  211. 	local d_right = d_right_corner + d_top_corner 
  212. 	 
  213. 	local closest 
  214. 	if d_bottom < d_left then 
  215. 		if d_bottom < d_right then 
  216. 			-- closest to bottom 
  217. 			closest = 1 
  218. 		else 
  219. 			-- closest to right 
  220. 			closest = 0 
  221. 		end 
  222. 	else 
  223. 		if d_left < d_right then 
  224. 			-- closest to left 
  225. 			closest = 2 
  226. 		else 
  227. 			-- closest to right 
  228. 			closest = 0 
  229. 		end 
  230. 	end 
  231. 	 
  232. 	local d_center = magnitude(center_x, center_y, rel_x, rel_y) 
  233. 	local d_min = magnitude(center_x, center_y, 0, 0) * 2 
  234. 	local d_max = Max_x * 2					--magnitude(0, 0, Max_x, 0); 
  235. 	 
  236. 	local fat_percent = d_min 
  237. 	local skinny_percent = d_min 
  238. 	local muscle_percent = d_min 
  239.  
  240. 	-- left side (fat) 
  241. 	if closest ~= 2 then 
  242. 		if d_right < d_bottom then 
  243. 			-- right section 
  244. 			if d_right_corner > d_top_corner then 
  245. 				fat_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  246. 			else 
  247. 				fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  248. 			end 
  249. 		else 
  250. 			-- bottom section 
  251. 			if d_right_corner > d_left_corner then 
  252. 				fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  253. 			else 
  254. 				fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  255. 			end 
  256. 		end 
  257. 	end 
  258. 	fat_percent = (fat_percent - d_min) / (d_max - d_min) 
  259. 	 
  260. 	-- right side (skinny) 
  261. 	if closest ~= 0 then 
  262. 		if d_left < d_bottom then 
  263. 			-- left section 
  264. 			if d_left_corner > d_top_corner then 
  265. 				skinny_percent = magnitude(Max_x, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  266. 			else 
  267. 				skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  268. 			end 
  269. 		else 
  270. 			-- bottom section 
  271. 			if d_left_corner > d_right_corner then 
  272. 				skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  273. 			else 
  274. 				skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  275. 			end 
  276. 		end 
  277. 	end 
  278. 	skinny_percent = (skinny_percent - d_min) / (d_max - d_min) 
  279.  
  280. 	-- bottom side (strength) 
  281. 	if closest ~= 1 then 
  282. 		if d_left < d_right then 
  283. 			-- left section 
  284. 			if d_top_corner > d_left_corner then 
  285. 				muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x, 0) 
  286. 			else 
  287. 				muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  288. 			end 
  289. 		else 
  290. 			-- right section 
  291. 			if d_top_corner > d_right_corner then 
  292. 				muscle_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  293. 			else 
  294. 				muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  295. 			end 
  296. 		end 
  297. 	end 
  298. 	muscle_percent = (muscle_percent - d_min) / (d_max - d_min) 
  299. 	 
  300. 	-- update % displays	 
  301. 	update_percent_fields(floor(fat_percent * 100 + 0.5), floor(skinny_percent * 100 + 0.5), floor(muscle_percent * 100 + 0.5))		 
  302. 	 
  303. 	-- convert back to screen coord 
  304. 	rel_y = Max_y - rel_y 
  305. 	 
  306. 	-- convert back to screen position 
  307. 	new_x = rel_x + TRIANGLE_NW_X 
  308. 	new_y = rel_y + TRIANGLE_NW_Y 
  309.  
  310. 	Cursor:set_anchor(new_x, new_y) 
  311. 	 
  312. 	if new_x ~= self.old_x or new_y ~= self.old_y then 
  313. 		game_UI_audio_play("UI_Cell_Nav") 
  314. 	end 
  315. 	self.old_x = new_x 
  316. 	self.old_y = new_y 
  317. 	 
  318. 	return muscle_percent, skinny_percent, fat_percent, new_x, new_y 
  319. end 
  320.  
  321. function Vdo_triangle_select:set_highlight_color(new_color) 
  322. 	self.btn_highlight:set_highlight_color(new_color) 
  323. 	Fat_txt:set_color(new_color.R, new_color.G, new_color.B) 
  324. 	Skinny_txt:set_color(new_color.R, new_color.G, new_color.B) 
  325. 	Strength_txt:set_color(new_color.R, new_color.G, new_color.B)	 
  326. 	self.glow_bmp:set_color(new_color.R, new_color.G, new_color.B)	 
  327. 	self.tri_color_grp:set_color(new_color.R, new_color.G, new_color.B)	 
  328. 	self.tri_color_grp:set_visible(true) 
  329. end 
  330.  
  331.  
  332. -- ===================================== 
  333. --       Mouse Specific Functions 
  334. -- ===================================== 
  335.  
  336. function Vdo_triangle_select:update_mouse(mouse_x, mouse_y)	 
  337. 	if (mouse_x ~= nil) and (mouse_y ~= nil) then 
  338. 		local triangle_base = Vdo_base_object:new("triangle_base", self.handle, self.doc_handle) 
  339. 		local tri_x, tri_y = vint_get_global_anchor(triangle_base.handle, self.doc_handle) 
  340. 		local tri_width, tri_height = triangle_base:get_actual_size() 
  341. 		 
  342. 		-- Calculate the points of the innermost triangle (A, B, C) in screen space 
  343. 		-- A is the bottom left point, B is the top point, C is the bottom right point 
  344. 		local ax = tri_x + TRIANGLE_NW_X 
  345. 		local ay = tri_y + TRIANGLE_NW_Y + Max_y + 4 
  346. 		local bx = tri_x + (tri_width / 2) 
  347. 		local by = tri_y + TRIANGLE_NW_Y + 4 
  348. 		local cx = tri_x + tri_width - TRIANGLE_NW_X 
  349. 		local cy = ay 
  350. 		 
  351. 		-- Adjust the mouse_x and mouse_y position based on the resolution/etc 
  352. 		local screen_w, screen_h = vint_get_screen_size() 
  353. 		local anchor_x, anchor_y 
  354. 		local relative_x, relative_y 
  355. 		if vint_is_std_res() then 
  356. 			local doc_width = screen_h * 4 / 3 
  357. 			local offset = (doc_width - screen_w) / 2 
  358. 			mouse_x = ((mouse_x + offset) * 640 / doc_width) 
  359. 			mouse_y = mouse_y * 480 / screen_h 
  360. 			 
  361. 			mouse_x = tri_x + (mouse_x - tri_x) * 1.5 
  362. 			mouse_y = tri_y + (mouse_y - tri_y) * 1.5 
  363. 		else  
  364. 			local doc_width = screen_h * 16 / 9 
  365. 			local offset = (doc_width - screen_w) / 2 
  366. 			mouse_x = ((mouse_x + offset) * 1280 / doc_width) 
  367. 			mouse_y = mouse_y * 720 / screen_h 
  368. 		end 
  369. 		 
  370. 		-- Check the location of the mouse cursor against each side of the triangle 
  371. 		-- If the point is "inside," it is to the right or on the line 
  372. 		local point_inside_left = false 
  373. 		local point_inside_right = false 
  374. 		local point_inside_bottom = false 
  375. 		if which_side_of_2d_line(mouse_x, mouse_y, ax, ay, bx, by) >= 0 then 
  376. 			point_inside_left = true 
  377. 		end 
  378. 		 
  379. 		if which_side_of_2d_line(mouse_x, mouse_y, bx, by, cx, cy) >= 0 then 
  380. 			point_inside_right = true 
  381. 		end 
  382. 		 
  383. 		if which_side_of_2d_line(mouse_x, mouse_y, cx, cy, ax, ay) >= 0 then 
  384. 			point_inside_bottom = true 
  385. 		end 
  386. 		 
  387. 		local new_x, new_y 
  388. 		local rel_x, rel_y 
  389. 		if point_inside_left and point_inside_right and point_inside_bottom then 
  390. 			-- If the point is inside the triangle, calculate the position of the mouse in the triangle space 
  391. 			new_x = mouse_x - tri_x 
  392. 			new_y = mouse_y - tri_y - 4 
  393. 			 
  394. 		else 
  395. 			-- If the point is not on the inside of the triangle, find the closest point on the 
  396. 			-- line that the point is not on the inside of. 
  397. 			 
  398. 			if not point_inside_left then 
  399. 				new_x, new_y = closest_point_on_line_segment(mouse_x, mouse_y, ax, ay, bx, by) 
  400. 			end 
  401. 			 
  402. 			if not point_inside_right then 
  403. 				new_x, new_y = closest_point_on_line_segment(mouse_x, mouse_y, bx, by, cx, cy) 
  404. 			end 
  405. 			 
  406. 			if not point_inside_bottom then 
  407. 				new_x, new_y = closest_point_on_line_segment(mouse_x, mouse_y, cx, cy, ax, ay) 
  408. 			end 
  409. 			 
  410. 			-- Calculate the position of the point in the triangle space 
  411. 			new_x = new_x - tri_x 
  412. 			new_y = new_y - tri_y - 4 
  413. 		end 
  414. 		 
  415. 		rel_x = new_x - TRIANGLE_NW_X 
  416. 		rel_y = Max_y - (new_y - TRIANGLE_NW_Y) 
  417.  
  418. 		Cursor:set_anchor(new_x, new_y) 
  419. 		 
  420. 		-- Cap just in case. 
  421. 		rel_x = cap(rel_x, 0, Max_x) 
  422. 		rel_y = cap(rel_y, 0, Max_y) 
  423. 	 
  424. 		local center_x = 117.5 
  425. 		local center_y = 67.84 
  426. 		 
  427. 		local d_left_corner = magnitude(0, 0, rel_x, rel_y) 
  428. 		local d_right_corner = magnitude(rel_x, rel_y, Max_x, 0) 
  429. 		local d_top_corner = magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  430. 		 
  431. 		local d_bottom = d_left_corner + d_right_corner 
  432. 		local d_left = d_left_corner + d_top_corner 
  433. 		local d_right = d_right_corner + d_top_corner 
  434. 		 
  435. 		local closest 
  436. 		if d_bottom < d_left then 
  437. 			if d_bottom < d_right then 
  438. 				-- closest to bottom 
  439. 				closest = 1 
  440. 			else 
  441. 				-- closest to right 
  442. 				closest = 0 
  443. 			end 
  444. 		else 
  445. 			if d_left < d_right then 
  446. 				-- closest to left 
  447. 				closest = 2 
  448. 			else 
  449. 				-- closest to right 
  450. 				closest = 0 
  451. 			end 
  452. 		end 
  453. 		 
  454. 		local d_center = magnitude(center_x, center_y, rel_x, rel_y) 
  455. 		local d_min = magnitude(center_x, center_y, 0, 0) * 2 
  456. 		local d_max = Max_x * 2					--magnitude(0, 0, Max_x, 0); 
  457. 		 
  458. 		local fat_percent = d_min 
  459. 		local skinny_percent = d_min 
  460. 		local muscle_percent = d_min 
  461.  
  462. 		-- left side (fat) 
  463. 		if closest ~= 2 then 
  464. 			if d_right < d_bottom then 
  465. 				-- right section 
  466. 				if d_right_corner > d_top_corner then 
  467. 					fat_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  468. 				else 
  469. 					fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  470. 				end 
  471. 			else 
  472. 				-- bottom section 
  473. 				if d_right_corner > d_left_corner then 
  474. 					fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  475. 				else 
  476. 					fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  477. 				end 
  478. 			end 
  479. 		end 
  480. 		fat_percent = (fat_percent - d_min) / (d_max - d_min) 
  481. 		 
  482. 		-- right side (skinny) 
  483. 		if closest ~= 0 then 
  484. 			if d_left < d_bottom then 
  485. 				-- left section 
  486. 				if d_left_corner > d_top_corner then 
  487. 					skinny_percent = magnitude(Max_x, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  488. 				else 
  489. 					skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  490. 				end 
  491. 			else 
  492. 				-- bottom section 
  493. 				if d_left_corner > d_right_corner then 
  494. 					skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  495. 				else 
  496. 					skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  497. 				end 
  498. 			end 
  499. 		end 
  500. 		skinny_percent = (skinny_percent - d_min) / (d_max - d_min) 
  501.  
  502. 		-- bottom side (strength) 
  503. 		if closest ~= 1 then 
  504. 			if d_left < d_right then 
  505. 				-- left section 
  506. 				if d_top_corner > d_left_corner then 
  507. 					muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x, 0) 
  508. 				else 
  509. 					muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  510. 				end 
  511. 			else 
  512. 				-- right section 
  513. 				if d_top_corner > d_right_corner then 
  514. 					muscle_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  515. 				else 
  516. 					muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  517. 				end 
  518. 			end 
  519. 		end 
  520. 		muscle_percent = (muscle_percent - d_min) / (d_max - d_min) 
  521. 	 
  522. 		-- update % displays	 
  523. 		update_percent_fields(floor(fat_percent * 100 + 0.5), floor(skinny_percent * 100 + 0.5), floor(muscle_percent * 100 + 0.5))		 
  524. 	 
  525. 		return muscle_percent, skinny_percent, fat_percent, new_x, new_y 
  526. 	end 
  527. end